<div dir="ltr">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. <br>
<br>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 <br>
<br>ContainerProvider.getWebSocketContainer().connectToServer(annotatedClientEndpoint.class, path)<br><br>, 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.<br>
<br>ServerWebSocketContainer serverContainer = (ServerWebSocketContainer) deployment.getDeployment()<br>            .getServletContext().getAttribute(ServerContainer.class.getName());<br>serverContainer.connectToServer(annotatedClientEndpoint.class, path);<br>
<br>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:<br>
<br>2014-08-21 16:03:30,978;20667;DEBUG;core.request;(XNIO-1 I/O-1);Invoking receive listener<br>2014-08-21 16:03:30,978;20667;ERROR;xnio.listener;(XNIO-1 I/O-1);XNIO001007: A channel event listener threw an exception<br>
java.lang.NullPointerException<br>    at io.undertow.server.protocol.framed.AbstractFramedChannel.receive(AbstractFramedChannel.java:234)<br>    at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:20)<br>
    at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:15)<br>    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)<br>    at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:632)<br>
    at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:618)<br>    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)<br>    at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)<br>
    at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87)<br>    at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)<br><br>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.    <br>
<br>Undertow version: 1.0.15 Final<br>Xnio version: 3.2.2 Final<br><br>My undertow instance:<br>       <br>      undertow = Undertow.builder()<br>            .addHttpListener(wsDefaultPort, WS_HOST)<br>            .addHttpsListener(wssDefaultPort, WS_HOST, MySSLSocketFactory.getSslContext())<br>
            .setHandler(rootPath)<br>            .build();<br>      undertow.start();<br><br>….<br>      final WebSocketDeploymentInfo deployment = new WebSocketDeploymentInfo();<br>      <br>      try<br>      {<br>         final Xnio xnio = Xnio.getInstance(&quot;nio&quot;, Undertow.class.getClassLoader());<br>
         final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap());<br><br>         deployment.setWorker(xnioWorker);<br>         deployment.addEndpoint(simpleAnnotatedServerEndpoint.class);   <br>….<br>
         final DeploymentManager deploymentManager = defaultContainer().addDeployment(deployment()<br>            .setClassLoader(classLoader)<br>            .setContextPath(prefixPath)<br>            .setDeploymentName(prefixPath)<br>
            .addServletContextAttribute(ATTRIBUTE_NAME, deployment));<br>         deploymentManager.deploy();<br>.…<br>         rootPath.addPrefixPath(prefixPath, deploymentManager.start());<br>         deployments.put(prefixPath, deploymentManager);<br>
</div>