transactional http end point and neo4j-rest-binding with cypher queries

498 views
Skip to first unread message

civic9

unread,
Oct 26, 2013, 4:41:34 PM10/26/13
to ne...@googlegroups.com
Hi,

I am using:
neo4j 2.0.0-M06

I am trying to check whether neo4j-rest-binding supports transactional http end point.
neo4j-rest-binding works for me only without transactions.

Sample code:
RestAPI graphDb = new RestAPIFacade("http://localhost:7474/db/data");
QueryEngine engine=new RestCypherQueryEngine(graphDb); 

// this works fine
engine.query("CREATE (person1 { personId: 1, started: 1361708546 })", Collections.EMPTY_MAP);  

// this gives me an exception
Transaction tx = graphDb.beginTx();
engine.query("CREATE (person1 { personId: 1, started: 1361708546 })", Collections.EMPTY_MAP);  
tx.success();
tx.close();

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.batch.RecordingRestRequest.toMap(RecordingRestRequest.java:135)
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 Test.neo4jRestFacade(Test.java:284)
at Test.main(Test.java:48)
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

Am I doing something wrong or neo4j-rest-binding is not ready to use with transactions?
I have also tried executeBatch with cypher queries (without transactions) but it gives me similar exception about empty JSON.


Michael Hunger

unread,
Oct 27, 2013, 12:00:26 AM10/27/13
to ne...@googlegroups.com
It does not use the transactional endpoint yet. 

It would not work across the board anyway as the transactional endpoint _only_ supports cypher. 
So all the other method of RestAPI wouldn't be executed transactionally at all.
I probably add a version some day that maps all graphdb operations to cypher statements, then it could work but would still be a leaky abstraction.

Thanks for pointing out the bug, haven't seen that yet. Please raise a github issue so that it is tracked.

You can look into the neo4j-jdbc driver if you need support for the transactional endpoint.


Which is now available as version 2.0.0-M06 from the same maven repository.

Looking forward to feedback on that.

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michael Hunger

unread,
Oct 27, 2013, 12:40:55 AM10/27/13
to ne...@googlegroups.com

civic9

unread,
Oct 27, 2013, 5:17:49 PM10/27/13
to ne...@googlegroups.com
W dniu niedziela, 27 października 2013 05:00:26 UTC+1 użytkownik Michael Hunger napisał:
Fixed in master.

Thanks,  at least it is working now in batch mode with cypher queries.
Transactional http endpoint support in rest client would be nice even for cypher queries only.
I know that it is probably not so hard to make calls to transactional http endpoint using only general rest 
client like jersey but I was looking for something ready and simple to use.
I am just testing different possibilities to use neo4j in server mode from java.

You can look into the neo4j-jdbc driver if you need support for the transactional endpoint.

Neo4J-JDBC seems to be working fine, but when parsing results it gives on stderr messages like:
Unexpected token END_ARRAY
errors-next-token = FIELD_NAME
null

using that example:

I don't know whether it is important or not. Results at least in simple tests look fine.
Anyway,you should consider using one of the logging APIs instead of System.err.print.


Ranjith

unread,
Nov 12, 2013, 3:17:12 PM11/12/13
to ne...@googlegroups.com

Alex Frieden

unread,
Nov 12, 2013, 3:18:43 PM11/12/13
to ne...@googlegroups.com
try changing Collections.EMPTY_MAP to null


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Alexander Frieden

Ranjith Anantharaman

unread,
Nov 12, 2013, 3:26:48 PM11/12/13
to neo4j
Hi ,

(I am writing this again since I couldn view my previous message ,something went wrong while posting I guess). 

I am getting the same exception Exception in thread "main" java.lang.RuntimeException: Error reading as JSON '' ...
,,,,,,,,
,,Caused by: java.io.EOFException: No content to map to Object due to end of input
...

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

System.out.println();

Jar used is : neo4j-rest-graphdb-2.0.0-M06.jar 

Changing Collections.EMPTY_MAP to null as you suggested gives same exception. There is no Transactional statements involved in the code I guess. Can you identify what might be causing this ? Thanks . 


--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/NjnX_pftCfA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages