JanusGraph / janusgraph

JanusGraph: an open-source, distributed graph database
https://janusgraph.org
Other
5.33k stars 1.17k forks source link

Version 0.4.0 does not return results with websocket connection #1674

Open shanequint opened 5 years ago

shanequint commented 5 years ago

I have a React app that connects to Janusgraph over a websocket connection. This worked well in version JanusGraph 0.3.1. I installed version 0.4.0 and it works with the gremlin console, but when trying to connect from javascript websocket with the following simplified sample websocket call:

const WebSocketAsPromised = require('websocket-as-promised');

getGraphNames = () => {
    let gremlin_query = 'ConfiguredGraphFactory.getGraphNames();';
    this.run_websocket_request(gremlin_query)
      .then(response => {
        if (response) {
          console.log('GetGraphIds: ', response);
        }
      });
}

run_websocket_request(gremlin_query, reqid = null, close = false) {
return new Promise((resolve, reject) => {
  var wsstring = 'ws://localhost:8182/gremlin';
  const wsp = new WebSocketAsPromised(wsstring, {
    packMessage: data => JSON.stringify(data),
    unpackMessage: message => JSON.parse(message)
  });
  wsp.onMessage.addListener(message => {
    var response = JSON.parse(message);
    //console.log('run_websocket_request: ', response.result.data);
    if (!reqid) {
      wsp.close();
      return resolve(response.result.data);
    } else {
      if (close) {
        wsp.close();
      }
      return resolve(response.result.data);
    }
  });

  wsp.onClose.addListener(event => console.log('Connections closed: ', event.reason));

  wsp.open()
    .then(() => wsp.sendPacked(msg))
    .catch(err => {
      console.log('Error: ', err);
      reject(err);
    }
    );
});
}

I get no response and I get the following error in the server logs:

    6645484 [gremlin-server-worker-1] WARN  io.netty.channel.DefaultChannelPipeline  - An 
    exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means 
    the last handler in the pipeline did not handle the exception.
    io.netty.handler.codec.DecoderException: java.lang.ClassCastException: 
    org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0 cannot be 
    cast to org.apache.tinkerpop.gremlin.driver.ser.MessageTextSerializer
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
    at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:204)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at org.apache.tinkerpop.gremlin.server.handler.WsAndHttpChannelizerHandler.channelRead(WsAndHttpChannelizerHandler.java:76)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassCastException: 
    org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0 cannot be 
    cast to org.apache.tinkerpop.gremlin.driver.ser.MessageTextSerializer
    at  
org.apache.tinkerpop.gremlin.server.handler.WsGremlinTextRequestDecoder.decode(WsGremlinTextRequestDecoder.java:55)
    at 
 org.apache.tinkerpop.gremlin.server.handler.WsGremlinTextRequestDecoder.decode(WsGremlinTextRequestDecoder.java:41)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
        ... 40 more

I also tried using Graphexp and get the same results.

I don't get any results back from the websocket call in the browser console or the network tab.

farodin91 commented 5 years ago

I think graphson v2 is not support in your backend. The gremlin-console normally doesn’t use graphson. You can checkout to update to graphson v3.

farodin91 commented 5 years ago

Is their a reason to use the official gremlin driver for JavaScript.

shanequint commented 5 years ago

I had tried the official gremlin driver for JavaScript when I first started my project and had trouble submitting scripts. I use the ConfiguredGraphManagement and JanusGraphManagement APIs to dynamically create graphs, create schema, Index properties and load CSV data from the browser and could not get these API calls to work. I basically re-engineered the graphExp javascript engine for my purposes. I will try the official driver again now that I have more experience with the product.

Is there some documentation I can read about the graphson V3 upgrade?

shanequint commented 5 years ago

I have now converted my project to use the official gremlin GLV for JavaScript and get the same results. It works fine for version 0.3.1, but does not work for version 0.4.0.

farodin91 commented 5 years ago

You have to configure GraphSON v3 on both site. http://tinkerpop.apache.org/docs/3.4.3/dev/io/#graphson

farodin91 commented 5 years ago

Or configure GraphSON v2 to be support on server side.

tfcace commented 4 years ago

@shanequint any progress on this? I'm trying to use gremlin-visualizer, and no matter what I try, I'm not getting back results

shanequint commented 4 years ago

@tfcace I could not get 0.4.0 to work, and was not sure how to configure the GraphSON v2 or v3 in my app and server side. I rolled back to version 0.3.3 now and all is working as expected. When I have some time I will try to figure out how to do the configuration @farodin91 suggested. I looked at the link provided above and did not see documentation on how to configure Janusgraph server to use GraphSON v2 as suggested.