users@glassfish.java.net

Re: websocket : RuntimeException when after page is refreshed

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Fri, 25 Jan 2013 15:35:47 +0100

Hi Neil,

can you please file this to Tyrus JIRA as a bug?
http://java.net/jira/browse/TYRUS

and about your issue: Servlet API currently cannot detect connection
close invoked from client side, but we should be able to handle this
state. Does this affect your application in any other way (than printing
this message into server.log)?

btw, Tyrus has its own mailing list - users_at_tyrus.java.net.

Regards,
Pavel

On 1/25/13 2:27 PM, Neil Ghosh wrote:
> I am broadcasting to each peer in a loop. Looks like when I refresh
> the page the socket is not gracefully closed and peer reference still
> remains in server
> When messages are broadcasted it throws invocation target exception.
> Any suggestion to gracefully close the socket upon refresh ?
>
>
> @WebSocketOpen
> public void onOpen(Session peer) {
> System.out.println("New user got connected");
> peers.add(peer);
> }
>
> @WebSocketClose
> public void onClose(Session peer) {
> peers.remove(peer);
> }
> @WebSocketMessage
> public void boradcastFigure(String msg, Session session) throws
> IOException {
> System.out.println("Broadcasting the message " + msg);
> for (Session peer : peers) {
> if (!peer.equals(session)) {
> peer.getRemote().sendString(msg);
> }
> }
> }
>
> --
>
> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
> at
> org.glassfish.tyrus.AnnotatedEndpoint.callMethod(AnnotatedEndpoint.java:336)
> at
> org.glassfish.tyrus.AnnotatedEndpoint.access$000(AnnotatedEndpoint.java:74)
> at
> org.glassfish.tyrus.AnnotatedEndpoint$BasicHandler$1.onMessage(AnnotatedEndpoint.java:406)
> at
> org.glassfish.tyrus.SessionImpl.notifyMessageHandlers(SessionImpl.java:265)
> at org.glassfish.tyrus.EndpointWrapper.onMessage(EndpointWrapper.java:306)
> at
> org.glassfish.tyrus.grizzly.GrizzlyEndpoint.onMessage(GrizzlyEndpoint.java:138)
> at
> org.glassfish.grizzly.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:164)
> at
> org.glassfish.grizzly.websockets.frametypes.TextFrameType.respond(TextFrameType.java:70)
> 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:273)
> 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:818)
> 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:562)
> at
> org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:542)
> at java.lang.Thread.run(Thread.java:722)
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:474)
> at
> org.glassfish.tyrus.AnnotatedEndpoint.callMethod(AnnotatedEndpoint.java:334)
> ... 23 more
> Caused by: java.lang.RuntimeException: Socket is not connected.
> at
> org.glassfish.grizzly.websockets.DefaultWebSocket.send(DefaultWebSocket.java:208)
> at
> org.glassfish.tyrus.grizzly.GrizzlyRemoteEndpoint.sendString(GrizzlyRemoteEndpoint.java:82)
> at
> org.glassfish.tyrus.RemoteEndpointWrapper.sendString(RemoteEndpointWrapper.java:78)
> at com.mycompany.slate.Slate.boradcastFigure(Slate.java:52)
> ... 27 more
>