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));
}
Aggregations