Hi,
I had an issue with some simple clientcode:
container = ContainerProvider.getClientContainer();
Session session = container.connectToServer(MyEndpoint.class, null, new
URI(server));
session.addMessageHandler(myHandler);
The onMessage call on myHandler never got called.
I debugged this, and it turned out that there were 2 Session objects:
the one returned by Container.connectToServer, and a second one that
was created during handshake. Since I didn't add a handler to the
second one, my callback method never got called.
I could easily fix this by having the handler added in the onOpen
method on the Endpoint in MyEndpoint.class:
@Override
public void onOpen(Session session, EndpointConfiguration config) {
LOGGER.info("RedFXWebSocketEndpoint is opened, session
= "+session);
this.session = session;
session.addMessageHandler(this);
}
The Session object that is passed into this onOpen method is the second
SessionImpl.
I wonder however, if it is intentional that a second SessionImpl is
created?
For debugging info, I dumped the stacktrace for the 2 calls to the
SessionImpl constructor:
at java.lang.Thread.dumpStack(Thread.java:1342)
at org.glassfish.tyrus.SessionImpl.<init>(SessionImpl.java:115)
at
org.glassfish.tyrus.EndpointWrapper.createSessionForRemoteEndpoint(Endp
ointWrapper.java:305)
at
org.glassfish.tyrus.container.grizzly.GrizzlyClientSocket.addEndpoint(G
rizzlyClientSocket.java:244)
at
org.glassfish.tyrus.container.grizzly.GrizzlyEngine.openClientSocket(Gr
izzlyEngine.java:112)
at
org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.
java:198)
at
org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.
java:140)
at
org.redfx.client.websocket.WebSocketCommunicator.initialize(WebSocketCo
mmunicator.java:79)
...
And
at java.lang.Thread.dumpStack(Thread.java:1342)
at org.glassfish.tyrus.SessionImpl.<init>(SessionImpl.java:115)
at
org.glassfish.tyrus.EndpointWrapper.onConnect(EndpointWrapper.java:317)
at
org.glassfish.tyrus.container.grizzly.GrizzlyClientSocket.onConnect(Gri
zzlyClientSocket.java:336)
at
org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleClientHandS
hake(WebSocketFilter.java:317)
at
org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleHandshake(W
ebSocketFilter.java:308)
at
org.glassfish.tyrus.container.grizzly.WebSocketFilter.handleRead(WebSoc
ketFilter.java:230)
at
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorRe
solver.java:119)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(Defa
ultFilterChain.java:273)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(D
efaultFilterChain.java:200)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFil
terChain.java:134)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFil
terChain.java:112)
at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:
77)
at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOT
ransport.java:818)
at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(Abstrac
tIOStrategy.java:112)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThre
adIOStrategy.java:115)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(Work
erThreadIOStrategy.java:55)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRun
nable.run(WorkerThreadIOStrategy.java:135)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(Abstr
actThreadPool.java:562)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(Abstract
ThreadPool.java:542)
at java.lang.Thread.run(Thread.java:722)
- Johan