【发布时间】:2013-11-13 07:46:16
【问题描述】:
我正在尝试使用 neo4j-rest-graphdb-2.0.0-M06.jar 通过 java 通过 REST API 执行 Cypher Query强>。来自http://m2.neo4j.org/content/repositories/releases/org/neo4j/neo4j-rest-graphdb/2.0.0-M06/neo4j-rest-graphdb-2.0.0-M06.jar。
我使用的java代码是:
RestAPI graphdb1 = new RestAPIFacade(dbpath);
QueryEngine engine1 = new RestCypherQueryEngine(graphdb1);
String cypherQuery= "match (X)-[:rel1]-(Y) where X:LABEL_X and Y:LABEL_Y return X.id,X.name";
engine1.query(cypherQuery, Collections.EMPTY_MAP);
我得到一个例外:
Exception in thread "main" java.lang.RuntimeException: **Error reading as JSON** ''
at org.neo4j.rest.graphdb.util.JsonHelper.readJson(JsonHelper.java:57)
at org.neo4j.rest.graphdb.util.JsonHelper.jsonToSingleValue(JsonHelper.java:62)
at org.neo4j.rest.graphdb.RequestResult.toEntity(RequestResult.java:114)
at org.neo4j.rest.graphdb.RequestResult.toMap(RequestResult.java:120)
at org.neo4j.rest.graphdb.ExecutingRestRequest.toMap(ExecutingRestRequest.java:212)
at org.neo4j.rest.graphdb.ExecutingRestAPI.query(ExecutingRestAPI.java:544)
at org.neo4j.rest.graphdb.ExecutingRestAPI.query(ExecutingRestAPI.java:564)
at org.neo4j.rest.graphdb.RestAPIFacade.query(RestAPIFacade.java:234)
at org.neo4j.rest.graphdb.query.RestCypherQueryEngine.query(RestCypherQueryEngine.java:50)
at com.unmetric.graph.test.GraphConnectTest.testRestApi(GraphConnectTest.java:39)
at com.unmetric.graph.test.GraphConnectTest.main(GraphConnectTest.java:26)
**Caused by: java.io.EOFException: No content to map to Object due to end of input**
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at org.neo4j.rest.graphdb.util.JsonHelper.readJson(JsonHelper.java:55)
... 10 more
【问题讨论】:
-
如果在浏览器中执行查询会发生什么?
-
在 neo4j 网络管理界面中?是的,我得到了结果。我在 org.neo4j.rest.graphdb 的 ExecutingRestApi.class 中看到了代码: public Map, ?> query(String statement, Map
params) { params = (params==null) ? Collections. emptyMap() : 参数; final RequestResult requestResult = getRestRequest().post("cypher", MapUtil.map("query", statement, "params", params));返回 getRestRequest().toMap(requestResult);这是导致问题的原因吗,方法签名应该是 CypherResult 吗? -
不是说响应的实体流是空的还是已经被消费了?但这不应该发生,如果你得到一个响应,它应该包含一些实体,不是吗?服务器日志中有任何内容吗?