1
votes

I am trying to execute a Cypher Query over REST API through java using the neo4j-rest-graphdb-2.0.0-M06.jar . from http://m2.neo4j.org/content/repositories/releases/org/neo4j/neo4j-rest-graphdb/2.0.0-M06/neo4j-rest-graphdb-2.0.0-M06.jar .

The java code I use is :

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

I get an exception :

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
1
What happens if you execute the query in the browser?Michael Hunger
In the neo4j web admin interface ? Yes I get results. I saw the code in ExecutingRestApi.class in org.neo4j.rest.graphdb : public Map<?, ?> query(String statement, Map<String, Object> params) { params = (params==null) ? Collections.<String,Object>emptyMap() : params; final RequestResult requestResult = getRestRequest().post("cypher", MapUtil.map("query", statement, "params", params)); return getRestRequest().toMap(requestResult); } Is this the causing the problem, should the method signature be CypherResult instead ?Ranjith
Doesn't that mean that the response's entity stream is empty or has already been consumed? But that shouldn't happen, if you get a response at all, it should contain some entity, no? Anything in the server logs?jjaderberg

1 Answers

2
votes

I met exactly the same problem. After 3 hours debugging, finally found the problem:

RestAPI graphdb1 = new RestAPIFacade(dbpath);

You not only need to provide dbpath but also your user name and password (default user name and password both are neo4j)

RestAPI graphdb1 = new RestAPIFacade(dbpath, "neo4j", "neo4j");