jbmusso / gremlin-javascript

JavaScript tools for graph processing in Node.js and the browser inspired by the Apache TinkerPop API
MIT License
214 stars 62 forks source link

Invalid OpProcessor requested [null] #55

Closed 37 closed 8 years ago

37 commented 8 years ago

This is probably not the most relevant issue (i'm not using this library) but I can't find anything relevant on the Tinkerpop3 JIRA or Titan 1.x docs or github generally.. So you'll have to forgive me if this is out of place.

I'm having an immense amount of trouble communicating with my gremlin / titan server via websockets using C++. Logically this shouldn't be too hard, though I think the API is changing so drastically that none of the documentation I find has an accurate explanation of the message structure / format.

I'm using the easywsclient library, and an example of my code (and format) is as follows:

std::unique_ptr ws(WebSocket::from_url("ws://SERVER:8182/"));

string command = "\"[1,2,3,4]\"";
string mime = "\"application/json\"";
string language = "\"gremlin-groovy\"";
string session = "\"\"";
string bindings = "\"\"";
string rebindings = "\"\"";
string op = "\"eval\"";
string processor = "\"org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor\"";
string accept = "\"application/json\"";
string executeHandler;
string request = "\"655BD810-B41E-429D-B78F-3CC5F3B8E9BA\"";

string msg = mime + "|-{" +
    "\"requestId\": " + request + "," +
    "\"op\": " + op + ","  +
    "\"processor\": " + processor + "," +
    "\"args\": {"  +
        "\"gremlin\": " + command + "," +
        "\"bindings\": " + bindings + "," +
        "\"language\": " + language + "," +
        "\"rebindings\": " + rebindings +
    "}" +
"}";

ws->send(msg);
//** then ws->poll and ws->dispatch to retrieve the response

To which my erroneous response is:

{"requestId":null,"status":{"message":"","code":499,"attributes":{}},"result":{"data":"Invalid OpProcessor requested [null]","meta":{}}}

I cannot seem to find any variation of op or processor (I have tried blank) that returns anything but the above.

Any help or tips would be greatly appreciated!

dmill-bz commented 8 years ago

Hey @LovelyHorse . This is probably better suited on the Apache TinkerPop dev mailing list, or on the gremlin-users mailing list.

For reference the documentation on writing drivers is located here and should be up to date. The part that you will be interested in is :

[...] The above JSON represents the "body" of the request to send to Gremlin Server. When sending this "body" over websockets Gremlin Server can accept a packet frame using a "text" (1) or a "binary" (2) opcode. Using "text" is a bit more limited in that Gremlin Server will always process the body of that request as JSON. Generally speaking "text" is just for testing purposes.

The preferred method for sending requests to Gremlin Server is to use the "binary" opcode. In this case, a "header" will need be sent in addition to to the "body". The "header" basically consists of a "mime type" so that Gremlin Server knows how to deserialize the RequestMessage.

The first byte represents the length of the "mime type" string value that follows. Given the default configuration of Gremlin Server, this value should be set to application/json. The "payload" represents the JSON message above encoded as bytes. Note : Gremlin Server will only accept masked packets as it pertains to websocket packet header construction.

So there are a few points you will need to look at in your code:

Also you should have :

dmill-bz commented 8 years ago

Feel free to link to a thread or something on the lists. I can definitely help you out if need be.

jbmusso commented 8 years ago

Hey @PommeVerte, thanks for taking the time to post such a detailed answer. Greatly appreciated :).

@LovelyHorse Did you have some luck by looking at the relevant part of the code here? I also suggest posting to the Apache TinkerPop dev mailing list. Closing this but please feel free to post your progress here.

37 commented 8 years ago

@PommeVerte thank you for the help!

@jbmusso Taking everything mentioned above into consideration I found that I had to change my bindings and rebindings entries from \" \" to {} and it worked perfectly. It was quite confusing that an improperly formatted bindings entry threw the error 'invalid opProcessor' though that's a bug I'll add to the TP3 Jira!

Side note for anyone who finds this with similar issues: The mimecode was unnecessary in my case. Simply beginning the request body with curly brackets did the job. Thanks again.

dmill-bz commented 8 years ago

Side note for anyone who finds this with similar issues: The mimecode was unnecessary in my case. Simply beginning the request body with curly brackets did the job. Thanks again.

FYI this refers to the following part of the TP3 documentation :

Gremlin Server can accept a packet frame using a "text" (1) or a "binary" (2) opcode. Using "text" is a bit more limited in that Gremlin Server will always process the body of that request as JSON. Generally speaking "text" is just for testing purposes.

Using "text" implies an application/json mimeType so you indeed do not need to add it and can just send the JSON. But it comes with some production level caveats. Like not being able to use the current typed JSON format, nor the new upcoming JSON format and Gremlin Language Variants (GLVs) features (like ByteCode queries). So in general it's best to move away from it for better coverage of TP3 features.

GuillaumeDesforges commented 1 year ago

For anyone landing on this issue because of Invalid OpProcessor requested [null] (sorry for piggybacking your issue :pray: ).

In my case I was trying to use TextP.regex but the server was not recent enough to use it, resulting in this error message. Server logs:

org.apache.tinkerpop.shaded.jackson.databind.JsonMappingException: Could not deserialize the JSON value as r
equired. Nested exception: org.apache.tinkerpop.shaded.jackson.databind.JsonMappingException: Could not deserialize the JSON value as required. N
ested exception: java.lang.IllegalStateException: org.apache.tinkerpop.gremlin.process.traversal.TextP.regex(java.lang.String)

Changing from TextP.regex to TextP.contains fixed it, possibly because I was not using the right version for the server.