[undertow-dev] WebSocketContainer configuration

Ryan Hermanson ryan.hermanson at gmail.com
Fri Aug 22 10:49:39 EDT 2014


I have had good luck with use of Undertow recently but now I’ve come up
against a problem.  When the deployment is strictly a server (I.e. handling
inbound requests over web sockets), all is happy.  Recently, there is a
need to support outbound “client” sessions.  And, all is not well.  I’ll be
as detailed as possible to keep the speculation of specifics to a minimum.
Thanks for your patience.

My problem is two fold.  The client session needs to have associated
sslContext (presumably thru EndpointConfig instance), as well as a way to
control/configure the underlying HTTP timeouts (presumably thru
socketOptions).  When I do something as simple as

ContainerProvider.getWebSocketContainer().connectToServer(annotatedClientEndpoint.class,
path)

, the client connection is established with far-end as hoped, but the
sslContext defined for our undertow instance is not employed.  To add to
the headache, if the remote server is unresponsive, the connection attempt
blocks for roughly 5 minutes.  Neither of these scenarios is ideal,
obviously.

ServerWebSocketContainer serverContainer = (ServerWebSocketContainer)
deployment.getDeployment()

.getServletContext().getAttribute(ServerContainer.class.getName());
serverContainer.connectToServer(annotatedClientEndpoint.class, path);

The above attempt to leverage the deployed ServerWebSocketContainer
(simpleAnnotatedServerEndpoint), successfully establishes the remote
connection, but any attempt at handling a message via @OnMessage (public
void onMessage(String msg)), yields NPE (BufferPool is null) with stack
trace of:

2014-08-21 16:03:30,978;20667;DEBUG;core.request;(XNIO-1 I/O-1);Invoking
receive listener
2014-08-21 16:03:30,978;20667;ERROR;xnio.listener;(XNIO-1
I/O-1);XNIO001007: A channel event listener threw an exception
java.lang.NullPointerException
    at
io.undertow.server.protocol.framed.AbstractFramedChannel.receive(AbstractFramedChannel.java:234)
    at
io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:20)
    at
io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:15)
    at
org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at
io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:632)
    at
io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:618)
    at
org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
    at
org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
    at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87)
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)

Based on description above and the relevant code snippets below, how should
I proceed in order to successfully establish outbound “client” connection
with functional xnioWorker instance, including SSL_CONTEXT and working
channels?  Thank you for any suggestions.

Undertow version: 1.0.15 Final
Xnio version: 3.2.2 Final

My undertow instance:

      undertow = Undertow.builder()
            .addHttpListener(wsDefaultPort, WS_HOST)
            .addHttpsListener(wssDefaultPort, WS_HOST,
MySSLSocketFactory.getSslContext())
            .setHandler(rootPath)
            .build();
      undertow.start();

….
      final WebSocketDeploymentInfo deployment = new
WebSocketDeploymentInfo();

      try
      {
         final Xnio xnio = Xnio.getInstance("nio",
Undertow.class.getClassLoader());
         final XnioWorker xnioWorker =
xnio.createWorker(OptionMap.builder().getMap());

         deployment.setWorker(xnioWorker);
         deployment.addEndpoint(simpleAnnotatedServerEndpoint.class);
….
         final DeploymentManager deploymentManager =
defaultContainer().addDeployment(deployment()
            .setClassLoader(classLoader)
            .setContextPath(prefixPath)
            .setDeploymentName(prefixPath)
            .addServletContextAttribute(ATTRIBUTE_NAME, deployment));
         deploymentManager.deploy();
.…
         rootPath.addPrefixPath(prefixPath, deploymentManager.start());
         deployments.put(prefixPath, deploymentManager);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20140822/3b4b31ac/attachment.html 


More information about the undertow-dev mailing list