【问题标题】:Neo4j Rest Calls Using Java( not in embedded mode)使用 Java 的 Neo4j 休息调用(非嵌入式模式)
【发布时间】:2013-05-07 16:32:01
【问题描述】:

我实际上是在 Neo4j 中使用社区插件,并尝试通过 java 发出 POST 请求来查询 Neo4j 服务器。

我总是收到 java.io.IOException:服务器返回 HTTP 响应代码:400 虽然对相同 url 的类似调用通过 javascript 工作,但业务逻辑建议通过 java 进行调用。

这是我的代码 sn-p:

String baseURL="ip_of_server";
    StringBuilder builder = new StringBuilder();
    try {
        URL url = new URL(baseURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST"); 
        connection.setRequestProperty("Content-Type", "application/json");
        OutputStream os=connection.getOutputStream();
         OutputStreamWriter writer = new OutputStreamWriter(os,Charset.forName("UTF-8"));


         System.out.println(url);
         Map<String, Object> params = new HashMap<String, Object>();
         params.put("query", "start x = node(3) return x");
         HashMap<String,String> test3= new HashMap<String,String>();
         params.put("params", test3);
         ObjectMapper temp = new ObjectMapper();

         String testString= temp.writeValueAsString(params);
         writer.write(testString);
         writer.close();
         os.close();


        String line = null;
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));
        while ((line = reader.readLine()) != null) {
            builder.append(line);

        }
        System.out.println("Response from server for request : " + url.toString() + " is " );
        System.out.println(builder.toString());



    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

有什么建议吗?

【问题讨论】:

  • 我的这个问题可能会提供一些提示 - stackoverflow.com/questions/15260994/…
  • 我还没有在 neo4j db 中设置密码。在我看来,在 POST 中发送查询是个问题。难道是因为多个“=”???
  • 我可以进行这样的查询,但现在我不能在查询中包含 node_auto_index(name="xxx") :**curl -v -H "Content-Type: application/json" -d "{\"query\":\"start x=node(3) return x.name\"}" "url"**

标签: java rest post neo4j cypher


【解决方案1】:

它需要一个解析器,因为'='等通过编码转换为其他字符,因此neo4j会抛出错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多