<< Back to previous view

[TYRUS-51] Encoding binary return types is throwing EncodeException Created: 10/Nov/12  Updated: 20/Feb/13  Resolved: 20/Feb/13

Status: Resolved
Project: tyrus
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0-b12, 1.0

Type: Bug Priority: Major
Reporter: arungupta Assignee: Pavel Bucek
Resolution: Fixed Votes: 0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Tags:
Participants: arungupta and Pavel Bucek

 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.



 Comments   
Comment by Pavel Bucek [ 20/Feb/13 12:26 PM ]

cannot reproduce.

feel free to reopen with reproducible testcase.

Generated at Thu Apr 24 07:38:12 UTC 2014 using JIRA 4.0.2#472.