休息Web服务不返回任何结果

时间:2014-02-21 20:25:58

标签: java web-services rest jcr modeshape

我有一个webservice,可以在modeshape内容库中搜索文本。 界面看起来像这样:

 @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;
}

我通过以下代码访问网络服务:

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);
        }

    }

问题是当我对我的本地modeshape存储库进行webservice调用时,结果按预期返回。但是当我在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 org.modeshape.jcr.query.optimize.RewritePseudoColumns@580ba9a4
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

并终止。

是否与modeshape配置或webservice有关? 只是为了让你知道,在某种程度上,模式形状可能有一百万条记录。导致问题的超时也是如此。如果是这样,那么我如何配置我的网络服务,以便它可以活5分钟?

任何帮助将不胜感激。 关于相同代码在不同服务器中的行为方式如何,这真的令人困惑。

1 个答案:

答案 0 :(得分:0)

没什么。错误说了一切。显然,uuid不应该用作将参数传递给SQL2查询的变量名。把它变成了uid,它就像一个魅力。