Search in sources :

Example 1 with ContextClassLoaderSetupAction

use of io.undertow.servlet.core.ContextClassLoaderSetupAction in project undertow by undertow-io.

the class Bootstrap method handleDeployment.

@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
    WebSocketDeploymentInfo info = (WebSocketDeploymentInfo) deploymentInfo.getServletContextAttributes().get(WebSocketDeploymentInfo.ATTRIBUTE_NAME);
    if (info == null) {
        return;
    }
    XnioWorker worker = info.getWorker();
    if (worker == null) {
        ServerWebSocketContainer defaultContainer = UndertowContainerProvider.getDefaultContainer();
        if (defaultContainer == null) {
            throw JsrWebSocketLogger.ROOT_LOGGER.xnioWorkerWasNullAndNoDefault();
        }
        JsrWebSocketLogger.ROOT_LOGGER.xnioWorkerWasNull();
        worker = defaultContainer.getXnioWorker();
    }
    ByteBufferPool buffers = info.getBuffers();
    if (buffers == null) {
        ServerWebSocketContainer defaultContainer = UndertowContainerProvider.getDefaultContainer();
        if (defaultContainer == null) {
            throw JsrWebSocketLogger.ROOT_LOGGER.bufferPoolWasNullAndNoDefault();
        }
        JsrWebSocketLogger.ROOT_LOGGER.bufferPoolWasNull();
        buffers = defaultContainer.getBufferPool();
    }
    final List<ThreadSetupHandler> setup = new ArrayList<>();
    setup.add(new ContextClassLoaderSetupAction(deploymentInfo.getClassLoader()));
    setup.addAll(deploymentInfo.getThreadSetupActions());
    InetSocketAddress bind = null;
    if (info.getClientBindAddress() != null) {
        bind = new InetSocketAddress(info.getClientBindAddress(), 0);
    }
    List<Extension> extensions = new ArrayList<>();
    for (ExtensionHandshake e : info.getExtensions()) {
        extensions.add(new ExtensionImpl(e.getName(), Collections.emptyList()));
    }
    ServerWebSocketContainer container = new ServerWebSocketContainer(deploymentInfo.getClassIntrospecter(), servletContext.getClassLoader(), worker, buffers, setup, info.isDispatchToWorkerThread(), bind, info.getReconnectHandler(), extensions);
    try {
        for (Class<?> annotation : info.getAnnotatedEndpoints()) {
            container.addEndpoint(annotation);
        }
        for (ServerEndpointConfig programatic : info.getProgramaticEndpoints()) {
            container.addEndpoint(programatic);
        }
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
    servletContext.setAttribute(ServerContainer.class.getName(), container);
    info.containerReady(container);
    SecurityActions.addContainer(deploymentInfo.getClassLoader(), container);
    deploymentInfo.addListener(Servlets.listener(WebSocketListener.class));
}
Also used : ByteBufferPool(io.undertow.connector.ByteBufferPool) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) ServletExtension(io.undertow.servlet.ServletExtension) Extension(javax.websocket.Extension) ThreadSetupHandler(io.undertow.servlet.api.ThreadSetupHandler) ContextClassLoaderSetupAction(io.undertow.servlet.core.ContextClassLoaderSetupAction) ExtensionHandshake(io.undertow.websockets.extensions.ExtensionHandshake) DeploymentException(javax.websocket.DeploymentException) ServerContainer(javax.websocket.server.ServerContainer)

Aggregations

ByteBufferPool (io.undertow.connector.ByteBufferPool)1 ServletExtension (io.undertow.servlet.ServletExtension)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 ContextClassLoaderSetupAction (io.undertow.servlet.core.ContextClassLoaderSetupAction)1 ExtensionHandshake (io.undertow.websockets.extensions.ExtensionHandshake)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 DeploymentException (javax.websocket.DeploymentException)1 Extension (javax.websocket.Extension)1 ServerContainer (javax.websocket.server.ServerContainer)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 XnioWorker (org.xnio.XnioWorker)1