Search code examples
websocketgremlintinkerpopjanusgraph

Connecting to JanusGraph over Websocket


I am currently running JanusGraph (0.1.1) and I am running into some difficulties trying to connect over Websocket - note that the Gremlin console works just fine, though.

I use Nodejs as a client and I have tried all the possible modules available. I can confirm that I do get past SSL security (providing the certificate itself or using the rejectUnauthorized option). Then, depending on the client library I am able to test that the connection is indeed open but no query seems to get through. The only clue I get is from the 'gremlin' module responding with error 401 - with the same credentials as the http endpoint (which works).

Would anyone be able to guide me through the right way to achieve this Websocket connection please? I have enclosed two examples with two different libraries.

// With Gremlin module
const Gremlin = require("gremlin");
const client = Gremlin.createClient(<my-port>, '<my-url>', { 
  path: '/', 
  user: '<my-user>', 
  password: '<my-password>', 
  ssl: true, 
  rejectUnauthorized: false, 
  session: true,
});
client.execute('def graph=ConfiguredGraphFactory.open("test3")', { }, (err, results) => {
    if (err) {
      return console.error(err)
    }
    console.log(results);
});

// With Ws module
const WebSocket = require('ws');
var fs = require('fs');
const ws = new WebSocket('wss://<my-url>:<my-port>', {
  ca: fs.readFileSync("./ssl.cert"), // required to get passed the leaf certificate error
  extraHeaders: {
    Authorization: 'Basic ' + new Buffer('<my-user>:<my-password>').toString('base64')
  },
  perMessageDeflate: false,
  ssl: true,
  json: true,
  strictSSL: false,
  // rejectUnauthorized: false, // does not work - needs the certificate
});
ws.onopen = function (event) {
  console.log('SSL OK: ', event.target._sender._socket.authorized);
  ws.send("{'gremlin': 'def graph=ConfiguredGraphFactory.open(\"test3\");graph.addVertex(label,\"some vertex\");graph.tx().commit();'}", function(res){
    console.log(res);
    ws.close();
  });
};

Solution

  • This problem is also described in this issue and the root cause was fixed with this issue: SASL parameter is incorrectly set.

    The problem has been fixed in the Javascript client with version 2.7.0, so make sure that you update your package.json to use that version.