Search in sources :

Example 21 with WebSocketDeploymentInfo

use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project undertow by undertow-io.

the class JsrWebsocketExtensionTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(BinaryEndpointTest.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setDispatchToWorkerThread(true).setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorkerSupplier()).addExtension(new PerMessageDeflateHandshake()).addEndpoint(AutobahnAnnotatedEndpoint.class)).setDeploymentName("servletContext.war");
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    debug = new DebugExtensionsHeaderHandler(deploymentManager.start());
    DefaultServer.setRootHandler(debug);
}
Also used : DebugExtensionsHeaderHandler(io.undertow.websockets.extensions.DebugExtensionsHeaderHandler) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) BinaryEndpointTest(io.undertow.websockets.jsr.test.BinaryEndpointTest) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 22 with WebSocketDeploymentInfo

use of io.undertow.websockets.jsr.WebSocketDeploymentInfo in project spring-framework by spring-projects.

the class UndertowTestServer method deployConfig.

@Override
@SuppressWarnings("deprecation")
public void deployConfig(WebApplicationContext wac, Filter... filters) {
    DispatcherServletInstanceFactory servletFactory = new DispatcherServletInstanceFactory(wac);
    // manually building WebSocketDeploymentInfo in order to avoid class cast exceptions
    // with tomcat's implementation when using undertow 1.1.0+
    WebSocketDeploymentInfo info = new WebSocketDeploymentInfo();
    try {
        info.setWorker(Xnio.getInstance().createWorker(OptionMap.EMPTY));
        info.setBuffers(new org.xnio.ByteBufferSlicePool(1024, 1024));
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
    ServletInfo servletInfo = servlet("DispatcherServlet", DispatcherServlet.class, servletFactory).addMapping("/").setAsyncSupported(true);
    DeploymentInfo servletBuilder = deployment().setClassLoader(UndertowTestServer.class.getClassLoader()).setDeploymentName("undertow-websocket-test").setContextPath("/").addServlet(servletInfo).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, info);
    for (final Filter filter : filters) {
        String filterName = filter.getClass().getName();
        FilterInstanceFactory filterFactory = new FilterInstanceFactory(filter);
        FilterInfo filterInfo = new FilterInfo(filterName, filter.getClass(), filterFactory);
        servletBuilder.addFilter(filterInfo.setAsyncSupported(true));
        for (DispatcherType type : DispatcherType.values()) {
            servletBuilder.addFilterUrlMapping(filterName, "/*", type);
        }
    }
    try {
        this.manager = defaultContainer().addDeployment(servletBuilder);
        this.manager.deploy();
        HttpHandler httpHandler = this.manager.start();
        this.server = Undertow.builder().addHttpListener(0, "localhost").setHandler(httpHandler).build();
    } catch (ServletException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) IOException(java.io.IOException) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletException(jakarta.servlet.ServletException) Filter(jakarta.servlet.Filter) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) DispatcherType(jakarta.servlet.DispatcherType) FilterInfo(io.undertow.servlet.api.FilterInfo)

Aggregations

WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)22 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)19 ServletContainer (io.undertow.servlet.api.ServletContainer)14 BeforeClass (org.junit.BeforeClass)11 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)7 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)6 DeploymentManager (io.undertow.servlet.api.DeploymentManager)6 IOException (java.io.IOException)6 ServletException (javax.servlet.ServletException)5 HttpHandler (io.undertow.server.HttpHandler)4 FilterInfo (io.undertow.servlet.api.FilterInfo)4 ServletInfo (io.undertow.servlet.api.ServletInfo)4 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)4 URI (java.net.URI)4 ServerEndpoint (javax.websocket.server.ServerEndpoint)4 PathHandler (io.undertow.server.handlers.PathHandler)3 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)3 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)3 TestClassIntrospector (io.undertow.servlet.test.util.TestClassIntrospector)3 DefaultServer (io.undertow.testutils.DefaultServer)3