tyrus
  1. tyrus
  2. TYRUS-51

Encoding binary return types is throwing EncodeException

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-b12, 1.0
    • Component/s: None
    • Labels:
      None

      Description

      I have an annotation-driven endpoint with the following method:

          @WebSocketMessage
          public ByteBuffer echoBinary(ByteBuffer data) {
              System.out.println("echoBinary: " + data);
              for (byte b : data.array()) {
                  System.out.print(b);
              }
              return data;
          }

      The JavaScript sends binary data as:

      function echoBinary() {
                      var buffer = new ArrayBuffer(myField2.value.length);
                      var bytes = new Uint8Array(buffer);
                      for (var i=0; i<bytes.length; i++) {
                          bytes[i] = i;
                      }
                      websocket.send(buffer);
                      writeToScreen("SENT (binary): " + buffer.byteLength + " bytes");
                  }

      The inbound payload in the POJO method is decoded and displayed correctly. But sending a response back throws the following exception:

      SEVERE: java.lang.RuntimeException: Error trying to send the response.
      	at org.glassfish.tyrus.AnnotatedEndpoint$Binary$1.onMessage(AnnotatedEndpoint.java:364)
      	at org.glassfish.tyrus.SessionImpl.notifyMessageHandlers(SessionImpl.java:315)
      	at org.glassfish.tyrus.EndpointWrapper.onMessage(EndpointWrapper.java:312)
      	at org.glassfish.tyrus.grizzly.GrizzlyEndpoint.onMessage(GrizzlyEndpoint.java:139)
      	at org.glassfish.grizzly.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:157)
      	at org.glassfish.grizzly.websockets.frametypes.BinaryFrameType.respond(BinaryFrameType.java:52)
      	at org.glassfish.grizzly.websockets.DataFrame.respond(DataFrame.java:104)
      	at org.glassfish.grizzly.websockets.WebSocketFilter.handleRead(WebSocketFilter.java:221)
      	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
      	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
      	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
      	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:781)
      	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
      	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
      	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
      	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:578)
      	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:558)
      	at java.lang.Thread.run(Thread.java:722)
      Caused by: javax.net.websocket.EncodeException: Unable to encode 
      	at org.glassfish.tyrus.EndpointWrapper.doEncode(EndpointWrapper.java:266)
      	at org.glassfish.tyrus.RemoteEndpointWrapper.sendPolymorphic(RemoteEndpointWrapper.java:173)
      	at org.glassfish.tyrus.RemoteEndpointWrapper.sendObject(RemoteEndpointWrapper.java:114)
      	at org.glassfish.tyrus.AnnotatedEndpoint$Binary$1.onMessage(AnnotatedEndpoint.java:362)
      	... 21 more

      If the POJO implementation is changed to:

          @WebSocketMessage
          public void echoBinary(ByteBuffer data, Session session) throws IOException {
              System.out.println("echoBinary: " + data);
              for (byte b : data.array()) {
                  System.out.print(b);
              }
              session.getRemote().sendBytes(data);
          }

      the a response is received on the client as a Blob.

        Activity

        arungupta created issue -
        Martin Matula made changes -
        Field Original Value New Value
        Fix Version/s 1.0 [ 16078 ]
        Fix Version/s 1.0-b08 [ 16095 ]
        Pavel Bucek made changes -
        Fix Version/s 1.0-b09 [ 16096 ]
        Fix Version/s 1.0-b08 [ 16095 ]
        Pavel Bucek made changes -
        Fix Version/s 1.0-b10 [ 16238 ]
        Fix Version/s 1.0-b09 [ 16096 ]
        Pavel Bucek made changes -
        Fix Version/s 1.0-b11 [ 16288 ]
        Fix Version/s 1.0-b10 [ 16238 ]
        Pavel Bucek made changes -
        Fix Version/s 1.0-b12 [ 16328 ]
        Fix Version/s 1.0-b11 [ 16288 ]
        Pavel Bucek made changes -
        Assignee Pavel Bucek [ pavel_bucek ]
        Pavel Bucek made changes -
        Description I have an annotation-driven endpoint with the following method:

            @WebSocketMessage
            public ByteBuffer echoBinary(ByteBuffer data) {
                System.out.println("echoBinary: " + data);
                for (byte b : data.array()) {
                    System.out.print(b);
                }
                return data;
            }

        The JavaScript sends binary data as:

        function echoBinary() {
                        var buffer = new ArrayBuffer(myField2.value.length);
                        var bytes = new Uint8Array(buffer);
                        for (var i=0; i<bytes.length; i++) {
                            bytes[i] = i;
                        }
                        websocket.send(buffer);
                        writeToScreen("SENT (binary): " + buffer.byteLength + " bytes");
                    }

        The inbound payload in the POJO method is decoded and displayed correctly. But sending a response back throws the following exception:

        SEVERE: java.lang.RuntimeException: Error trying to send the response.
        at org.glassfish.tyrus.AnnotatedEndpoint$Binary$1.onMessage(AnnotatedEndpoint.java:364)
        at org.glassfish.tyrus.SessionImpl.notifyMessageHandlers(SessionImpl.java:315)
        at org.glassfish.tyrus.EndpointWrapper.onMessage(EndpointWrapper.java:312)
        at org.glassfish.tyrus.grizzly.GrizzlyEndpoint.onMessage(GrizzlyEndpoint.java:139)
        at org.glassfish.grizzly.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:157)
        at org.glassfish.grizzly.websockets.frametypes.BinaryFrameType.respond(BinaryFrameType.java:52)
        at org.glassfish.grizzly.websockets.DataFrame.respond(DataFrame.java:104)
        at org.glassfish.grizzly.websockets.WebSocketFilter.handleRead(WebSocketFilter.java:221)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:781)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:578)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:558)
        at java.lang.Thread.run(Thread.java:722)
        Caused by: javax.net.websocket.EncodeException: Unable to encode
        at org.glassfish.tyrus.EndpointWrapper.doEncode(EndpointWrapper.java:266)
        at org.glassfish.tyrus.RemoteEndpointWrapper.sendPolymorphic(RemoteEndpointWrapper.java:173)
        at org.glassfish.tyrus.RemoteEndpointWrapper.sendObject(RemoteEndpointWrapper.java:114)
        at org.glassfish.tyrus.AnnotatedEndpoint$Binary$1.onMessage(AnnotatedEndpoint.java:362)
        ... 21 more

        If the POJO implementation is changed to:

            @WebSocketMessage
            public void echoBinary(ByteBuffer data, Session session) throws IOException {
                System.out.println("echoBinary: " + data);
                for (byte b : data.array()) {
                    System.out.print(b);
                }
                session.getRemote().sendBytes(data);
            }

        the a response is received on the client as a Blob.
        I have an annotation-driven endpoint with the following method:

        {code} @WebSocketMessage
            public ByteBuffer echoBinary(ByteBuffer data) {
                System.out.println("echoBinary: " + data);
                for (byte b : data.array()) {
                    System.out.print(b);
                }
                return data;
            }{code}

        The JavaScript sends binary data as:

        {code}function echoBinary() {
                        var buffer = new ArrayBuffer(myField2.value.length);
                        var bytes = new Uint8Array(buffer);
                        for (var i=0; i<bytes.length; i++) {
                            bytes[i] = i;
                        }
                        websocket.send(buffer);
                        writeToScreen("SENT (binary): " + buffer.byteLength + " bytes");
                    }{code}

        The inbound payload in the POJO method is decoded and displayed correctly. But sending a response back throws the following exception:

        {code}SEVERE: java.lang.RuntimeException: Error trying to send the response.
        at org.glassfish.tyrus.AnnotatedEndpoint$Binary$1.onMessage(AnnotatedEndpoint.java:364)
        at org.glassfish.tyrus.SessionImpl.notifyMessageHandlers(SessionImpl.java:315)
        at org.glassfish.tyrus.EndpointWrapper.onMessage(EndpointWrapper.java:312)
        at org.glassfish.tyrus.grizzly.GrizzlyEndpoint.onMessage(GrizzlyEndpoint.java:139)
        at org.glassfish.grizzly.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:157)
        at org.glassfish.grizzly.websockets.frametypes.BinaryFrameType.respond(BinaryFrameType.java:52)
        at org.glassfish.grizzly.websockets.DataFrame.respond(DataFrame.java:104)
        at org.glassfish.grizzly.websockets.WebSocketFilter.handleRead(WebSocketFilter.java:221)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:781)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:578)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:558)
        at java.lang.Thread.run(Thread.java:722)
        Caused by: javax.net.websocket.EncodeException: Unable to encode
        at org.glassfish.tyrus.EndpointWrapper.doEncode(EndpointWrapper.java:266)
        at org.glassfish.tyrus.RemoteEndpointWrapper.sendPolymorphic(RemoteEndpointWrapper.java:173)
        at org.glassfish.tyrus.RemoteEndpointWrapper.sendObject(RemoteEndpointWrapper.java:114)
        at org.glassfish.tyrus.AnnotatedEndpoint$Binary$1.onMessage(AnnotatedEndpoint.java:362)
        ... 21 more{code}

        If the POJO implementation is changed to:

        {code} @WebSocketMessage
            public void echoBinary(ByteBuffer data, Session session) throws IOException {
                System.out.println("echoBinary: " + data);
                for (byte b : data.array()) {
                    System.out.print(b);
                }
                session.getRemote().sendBytes(data);
            }{code}

        the a response is received on the client as a Blob.
        Hide
        Pavel Bucek added a comment -

        cannot reproduce.

        feel free to reopen with reproducible testcase.

        Show
        Pavel Bucek added a comment - cannot reproduce. feel free to reopen with reproducible testcase.
        Pavel Bucek made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Pavel Bucek
            Reporter:
            arungupta
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: