0

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(OutputFormat.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 :)

4

1 回答 1

1

Are you providing content-type:application/json and accept:application/json request headers?

于 2013-04-16T11:32:15.500 回答