简体   繁体   中英

Parameters not found in cypher query executed via rest in javascript

Good morning, I have a Neo4j Database with Maven Dependencies build via a Java programm. Now I want to create a Webinterface to access the data. When executing a cypher POST via jQuery.ajax I get a bad request error. In details:

var query2 = '{"query":"start n = node(*) where n.groupId! = {groupId} and n.artifactId! = {artifactId} return n.version","params":{"groupId":"junit","artifactId":"junit"}}';

When I send this via rest to the server I get a 400 Bad Request error:

{ "message" : "Expected a parameter named groupId", "exception" : "BadInputException", "stacktrace" : [ "org.neo4j.server.rest.repr.RepresentationExceptionHandlingIterable.exceptionOnHasNext(RepresentationExceptionHandlingIterable.java:51)", "org.neo4j.helpers.collection.ExceptionHandlingIterable$1.hasNext(ExceptionHandlingIterable.java:61)", "org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)", "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:58)", "org.neo4j.server.rest.repr.Serializer.serialize(Serializer.java:75)", "org.neo4j.server.rest.repr.MappingSerializer.putList(MappingSerializer.java:61)", "org.neo4j.server.rest.repr.CypherResultRepresentation.serialize(CypherResultRepresentation.java:50)", "org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:42)", "org.neo4j.server.rest.repr.OutputFormat.format(OutputFormat.java:170)", "org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(Ou tputFormat.java:120)", "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:107)", "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:55)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:68)", "java.lang.reflect.Method.invoke(Unknown Source)" ] }

I also tried to build the query via a JS object like so:

        var query = {};
    query["query"] = text;
    query["params"] = JSON.parse("{" + params + "}");

Where text is the query string and params the parameters with right syntax. ("param1":"value1", ...)

Until now this seems like I mistyped something somewhere. Interestingly the whole thing works when omitting the parameters and writing a request with just a "query" property.

Also

JSONObject jObject = new JSONObject();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("groupId", "junit");
        params.put("artifactId", "junit");
        String query = "start n = node(*) where n.groupId! = {groupId} and n.artifactId! = {artifactId} return n.version";
        jObject.put("query", query);
        jObject.put("params", params);

and then sending jObject.toString() to the database in Java works like a charm... Well, I have to say I'm at my wit's end with this. Hope you guys can help me :)

您是否提供content-type:application/jsonaccept:application/json请求标头?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM