[undertow-dev] WebSocketContainer configuration
Stuart Douglas
sdouglas at redhat.com
Mon Aug 25 03:43:33 EDT 2014
Ryan Hermanson wrote:
> 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.
The ssl context can be set in three ways.
1) Use the version of connect that takes a ClientEndpointConfig and set
the io.undertow.websocket.SSL_CONTEXT property to the SSL context you
want to use (unfortunatly this won't work with annotated endpoints).
2) Call
io.undertow.websockets.jsr.DefaultWebSocketClientSslProvider#setSslContext()
which sets the thread local SSL context.
3) Implement io.undertow.websockets.jsr.WebsocketClientSslProvider and
add a META-INF/services entry pointing to your implementation.
(The web socket API is sadly lacking when it comes to configuring SSL).
>
> 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:
Make sure you set the buffer pool on the WebSocketDeploymentInfo
(io.undertow.websockets.jsr.WebSocketDeploymentInfo#setBuffers).
Stuart
>
> 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);
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
More information about the undertow-dev
mailing list