Websocket API issues during XML payload transmission via getSendWriter() handle

Facing weird issues with the WebSocket API

Use Case: Trying to send a XML payload back to the remote client using the java.io.Writer handle provided by the getSendWriter() method in RemoteEndpoint.Basic interface

Code snippet below

code1

 

SampleModel is just a POJO (the complete code has been omitted)

code2

 

Scenario 1 – GlassFish 4.0

Tested the WS endpoint behavior via simple JavaScript – just printing the received message to the console

js1

Observation 1 :  The result is just a String —> sdfsdfval2

What I expected was an XML payload of the form (without the formatting of course) —>>>

<?xml version=”1.0″ encoding=”UTF-8″?>
<samplemodel>
<id>sdfsdf</id>
<name>val2</name>
</samplemodel>

Observation 2 : I happened to have an error handler method annotated with javax.websocket.onError

code3Stumbled across a null pointer thrown by the WSocket implementation (Tyrus)

INFO: java.lang.NullPointerException
at org.glassfish.tyrus.websockets.Utf8Utils.encode(Utf8Utils.java:55)
at org.glassfish.tyrus.websockets.frametypes.TextFrameType.getBytes(TextFrameType.java:59)
at org.glassfish.tyrus.websockets.draft07.Draft07Handler.frame(Draft07Handler.java:72)
at org.glassfish.tyrus.servlet.ConnectionImpl.write(ConnectionImpl.java:86)
at org.glassfish.tyrus.websockets.ProtocolHandler.write(ProtocolHandler.java:182)
at org.glassfish.tyrus.websockets.ProtocolHandler.send(ProtocolHandler.java:82)
at org.glassfish.tyrus.websockets.ProtocolHandler.send(ProtocolHandler.java:77)
at org.glassfish.tyrus.websockets.ProtocolHandler.stream(ProtocolHandler.java:149)
at org.glassfish.tyrus.websockets.DefaultWebSocket.stream(DefaultWebSocket.java:205)
at org.glassfish.tyrus.server.TyrusRemoteEndpoint.sendText(TyrusRemoteEndpoint.java:105)
at org.glassfish.tyrus.core.WriterToAsyncTextAdapter.sendBuffer(WriterToAsyncTextAdapter.java:62)
at org.glassfish.tyrus.core.WriterToAsyncTextAdapter.flush(WriterToAsyncTextAdapter.java:76)
at java.io.BufferedWriter.flush(BufferedWriter.java:254)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.cleanUp(MarshallerImpl.java:342)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:335)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:131)
at com.abhirockzz.SimpleWSEndpoint.connectionOpen(SimpleWSEndpoint.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.glassfish.tyrus.core.AnnotatedEndpoint.callMethod(AnnotatedEndpoint.java:431)
at org.glassfish.tyrus.core.AnnotatedEndpoint.onOpen(AnnotatedEndpoint.java:468)
at org.glassfish.tyrus.core.EndpointWrapper.onConnect(EndpointWrapper.java:425)
at org.glassfish.tyrus.server.TyrusEndpoint.onConnect(TyrusEndpoint.java:135)
at org.glassfish.tyrus.websockets.DefaultWebSocket.onConnect(DefaultWebSocket.java:110)
at org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler.init(TyrusHttpUpgradeHandler.java:98)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:773)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:176)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
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:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Suppressed: java.lang.NullPointerException
at org.glassfish.tyrus.websockets.Utf8Utils.encode(Utf8Utils.java:55)
at org.glassfish.tyrus.websockets.frametypes.TextFrameType.getBytes(TextFrameType.java:59)
at org.glassfish.tyrus.websockets.draft07.Draft07Handler.frame(Draft07Handler.java:72)
at org.glassfish.tyrus.servlet.ConnectionImpl.write(ConnectionImpl.java:86)
at org.glassfish.tyrus.websockets.ProtocolHandler.write(ProtocolHandler.java:182)
at org.glassfish.tyrus.websockets.ProtocolHandler.send(ProtocolHandler.java:82)
at org.glassfish.tyrus.websockets.ProtocolHandler.send(ProtocolHandler.java:77)
at org.glassfish.tyrus.websockets.ProtocolHandler.stream(ProtocolHandler.java:149)
at org.glassfish.tyrus.websockets.DefaultWebSocket.stream(DefaultWebSocket.java:205)
at org.glassfish.tyrus.server.TyrusRemoteEndpoint.sendText(TyrusRemoteEndpoint.java:105)
at org.glassfish.tyrus.core.WriterToAsyncTextAdapter.sendBuffer(WriterToAsyncTextAdapter.java:62)
at org.glassfish.tyrus.core.WriterToAsyncTextAdapter.close(WriterToAsyncTextAdapter.java:82)
at com.abhirockzz.websocketapi.SimpleWSEndpoint.connectionOpen(SimpleWSEndpoint.java:39)
… 33 more

Scenario 2 : Wildfly 8.0

Same result as far as the output goes – just a simple string. But the error handler method (annotated with onError) was not invoked …. wondering why ?????

Note : The issue is reproducible with both JDK7 and JDK8

Not sure if this is actually an issue or am I being just plain dumb! The use case seems too straightforward to fail !

Anyone witnessed this behavior?

Advertisements

About Abhishek

Java EE & distributed systems junkie who frequently blogs at abhirockzz.wordpress.com as well as simplydistributed.wordpress.com. Oh, I have also authored a few (mini) books, articles, Refcards etc. :-)
This entry was posted in Java, Java EE and tagged , , , , , . Bookmark the permalink.

One Response to Websocket API issues during XML payload transmission via getSendWriter() handle

  1. Pingback: Just a follow up on WebSocket API issue with Tyrus (on GlassFish) | Object Oriented . .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s