2014-02-21 74 views
0

我有一個web服務,它搜索modeshape內容存儲庫中的文本片段。 接口看起來是這樣的:其他web服務不返回任何結果

@POST 
    @Path("globalSearch") 
    @Consumes(MediaType.TEXT_PLAIN) 
    @Produces(MediaType.TEXT_XML) 
    public String globalSearch(String search) { 
     XMLConverterService xmlOb = new XMLConverterService(); 
     Map<String,String> param = xmlOb.fetchMapFromXml(search); 
     StringBuffer xmlString = new StringBuffer(); 
     xmlString.append("<xml>"); 
     int count = 0; 
     List<Map<String, String>> result = (new DataInterfaceService()) 
       .fetchGlobalSearch(param); 
     if(result!=null){ 
     for (Map<String, String> map : result) { 
      count++; 
      xmlString.append("<result" + count + ">") 
        .append(xmlOb.fetchXmlFromMap(map)) 
        .append("</result" + count + ">"); 
     } 
     xmlString.append("</xml>"); 
     return xmlString.toString(); 
     } 
     return null; 
    } 

的fetchGlobalSearch()函數看起來是這樣的:

public List<Map<String, String>> fetchGlobalSearch(Map<String, String> param) { 
    logger.log(Level.INFO, "entering fetchGlobalSearch"); 
    String keyWord = param.get("keyword"); 
    String type = param.get("type"); 
    List<Map<String, String>> listOfMaps = null; 
    Map<String, String> retValue = null; 
    String qry = ""; 
    if (type.equalsIgnoreCase("GRA")) { 
     qry = "SELECT [med:UNIQUE_ID],[med:GRPNAME],[med:CSR],[med:UW],[med:GROUP_STATE],[med:STR_DATE] " 
       + "FROM [med:notes] where contains([med:XML_STORE], $uuid)"; 
    } else { 
     qry = "SELECT [fur:UNIQUE_ID],[fur:MM],[fur:FROMUW],[fur:INSURED],[fur:POLICY_NUM],[fur:UWCSRDATE],[fur:FURCOMPDATE],[fur:FUR_DATE],[fur:CSRCOMPDATE] " 
       + "FROM [fur:notesfur] where contains([fur:XML_STORE], $uuid)"; 
    } 
    try { 
     Query qr = qrym.createQuery(qry, Query.JCR_SQL2); 

     Value uid = session.getValueFactory().createValue(keyWord); 
     qr.bindValue("uuid", uid); 

     QueryResult resultSet = qr.execute(); 
     String[] columns = resultSet.getColumnNames(); 

     RowIterator rowiter = resultSet.getRows(); 

     while (rowiter.hasNext()) { 
      if (listOfMaps == null) 
       listOfMaps = new ArrayList<Map<String, String>>(); 
      retValue = new HashMap<String, String>(); 
      Row row = rowiter.nextRow(); 
      for (String column : columns) { 
       if (row.getValue(column) != null) { 
        retValue.put(column, row.getValue(column).toString()); 
       } 
      } 
      listOfMaps.add(retValue); 
     } 

    } catch (RepositoryException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    logger.log(Level.INFO, "exiting fetchGlobalSearch"); 
    return listOfMaps; 
} 

我用下面這段代碼訪問web服務:

private static void callGlobalSearch(){ 
     try { 
      String param = ""; 
      param = fetchGlobalParams(); 
      System.out.println("param : " + param); 
      // Create a socket connection to the host 
      URL url = new URL(
        "http://localhost:8080/xxttrr/rest/globalSearch"); 
      HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
      // make url connection 
      conn.setDoOutput(true); 
      conn.setDoInput(true); 
      conn.setUseCaches(false); 
      conn.setAllowUserInteraction(true); 
      conn.setRequestMethod("POST"); 
      conn.setRequestProperty("Content-Type", 
        "text/plain; charset=utf-8"); 
      conn.setRequestProperty("Content-Length", Integer.toString(param.getBytes().length)); 
      DataOutputStream printout = new DataOutputStream (conn.getOutputStream()); 
      printout.writeBytes(param); 
      printout.flush(); 
      printout.close(); 
      BufferedReader in = new BufferedReader(new java.io.InputStreamReader(conn.getInputStream())); 
      String line;    
      while ((line = in.readLine()) != null) { 
       System.out.println(line); 
      } 
      in.close(); 
      conn.disconnect(); 
     } catch (Exception e) { 
      System.out.println("Error: " + e); 
     } 

    } 

的問題是當我對本地的modehape存儲庫進行web服務調用時,結果按預期返回。但是當我在DEV服務器上部署的代碼它形成以下日誌:

14:32:47,033 INFO [DataInterfaceService] (http-/0.0.0.0:8380-1) entering fetchGlobalSearch 
14:32:47,035 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule [email protected] 
14:32:47,036 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule ReplaceViews 
14:32:47,036 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule CopyCriteria 
14:32:47,037 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule RightOuterToLeftOuterJoins 
14:32:47,037 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule AddAccessNodes 
14:32:47,037 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule PushSelectCriteria 
14:32:47,037 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule PushProjects 
14:32:47,037 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule AddOrderingColumnsToSources 
14:32:47,038 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule RewriteAsRangeCriteria 
14:32:47,038 DEBUG [org.modeshape.jcr.query.optimize.RuleBasedOptimizer] (http-/0.0.0.0:8380-1) Running query optimizer rule RewritePathAndNameCriteria 
14:32:47,039 DEBUG [org.modeshape.jcr.query.lucene.LuceneQueryEngine] (http-/0.0.0.0:8380-1) Executing the lucene query: +(::wks:System ::wks:Default) +:ft:ddd:XML_STORE:"uuid" +jcr:mixinTypes:ddd:notes 
14:32:47,051 INFO [DataInterfaceService] (http-/0.0.0.0:8380-1) exiting fetchGlobalSearch 

和終止。

這是與模式配置或web服務有關嗎? 只是爲了讓你知道,在一個點上,modehape中可能會有一百萬條記錄。導致問題的超時也是如此。如果是這樣,那麼我怎樣才能配置我的web服務,使其能夠活5分鐘?

任何幫助,將不勝感激。 對於同一代碼在不同服務器中的行爲方式,真的很讓人困惑。

+0

一些最重要的部分缺失 - 其餘服務的內容在哪裏?此外,您不希望服務試圖返回「數百萬」行數據。您需要以某種方式對結果進行分頁,以使服務更加可用。 – mikemil

+0

嗨Mikemil, web服務不返回百萬條記錄。它只是在一百萬條記錄中搜索。一次web服務應該返回最多20條記錄。我在我的主帖中粘貼了界面的代碼。希望它能幫助你找出問題所在。 – TusharPanda

回答

0

這沒什麼。錯誤說了這一切。顯然uuid不應該被用作將參數傳遞給SQL2查詢的變量名稱。改變它使用,它像一個魅力。