Consistent with the SO rules, I answer my own question here.
I got my clue when I tried to cast it to TyrusSession
and Jetty complained (raised ClassCastException
) in the error logs saying it was a JsrSession
which cannot be cast into a TyrusSession
. However, I had just printed the Session
object in my logs, and something like this showed up:
session: WebSocketSession[....]
I then tried to cast it to org.eclipse.jetty.websocket.common.WebSocketSession
which then complained about the object actually being a JsrSession
which then led to my discovering the following solution:
@ServerEndpoint (value="/mySillyApp", configurator= ..., decoders={...})
public class MySillyWebSocketServer
{
@OnOpen
public void open (Session session, EndpointConfig config)
{
JsrSession jsrSession = (JsrSession) session; // import org.eclipse.jetty.websocket.jsr356.JsrSession;
WebSocketSession webSocketSession = jsrSession.getWebSocketSession (); // import org.eclipse.jetty.websocket.common.WebSocketSession;
String clientIPAddressString = webSocketSession.getRemoteAddress ().getHostString ();
....
}
...
}
Obviously, you will have to include the appropriate jars in your classpath. For gradle, you do this in the dependencies {...}
section:
compile 'org.eclipse.jetty.websocket:javax-websocket-client-impl:9.3.6.v20151106'
compile 'org.eclipse.jetty.websocket:websocket-common:9.1.0.v20131115'
Hope my methodology and details helps someone.