Search in sources :

Example 6 with WebSocketDeploymentInfo

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

the class ProgramaticAutobahnServer method run.

public void run() {
    Xnio xnio = Xnio.getInstance();
    try {
        XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
        OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
        DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8192);
        HttpOpenListener openListener = new HttpOpenListener(pool);
        ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
        AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
        server.resumeAccepts();
        final ServletContainer container = ServletContainer.Factory.newInstance();
        DeploymentInfo builder = new DeploymentInfo().setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).setDispatchToWorkerThread(true).addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")).addExtension(new PerMessageDeflateHandshake()));
        deploymentManager = container.addDeployment(builder);
        deploymentManager.deploy();
        openListener.setRootHandler(deploymentManager.start());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) ServerEndpointConfigImpl(io.undertow.websockets.jsr.ServerEndpointConfigImpl) StreamConnection(org.xnio.StreamConnection) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletException(javax.servlet.ServletException) Xnio(org.xnio.Xnio) JsrWebSocketFilter(io.undertow.websockets.jsr.JsrWebSocketFilter) OptionMap(org.xnio.OptionMap) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 7 with WebSocketDeploymentInfo

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

the class ClientEndpointReconnectTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(ClientEndpointReconnectTestCase.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(ClientEndpointReconnectTestCase.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 8192)).setWorker(DefaultServer.getWorkerSupplier()).addEndpoint(DisconnectServerEndpoint.class).addEndpoint(AnnotatedClientReconnectEndpoint.class).addListener(containerReady -> deployment = containerReady).setReconnectHandler(new WebSocketReconnectHandler() {

        @Override
        public long disconnected(CloseReason closeReason, URI connectionUri, Session session, int disconnectCount) {
            if (disconnectCount < 3) {
                return 1;
            } else {
                return -1;
            }
        }

        @Override
        public long reconnectFailed(IOException exception, URI connectionUri, Session session, int failedCount) {
            failed = true;
            return -1;
        }
    })).setDeploymentName("servletContext.war");
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", deploymentManager.start()));
}
Also used : AfterClass(org.junit.AfterClass) Handlers(io.undertow.Handlers) Session(javax.websocket.Session) BeforeClass(org.junit.BeforeClass) ServletException(javax.servlet.ServletException) TestClassIntrospector(io.undertow.servlet.test.util.TestClassIntrospector) CloseReason(javax.websocket.CloseReason) HttpOneOnly(io.undertow.testutils.HttpOneOnly) DefaultServer(io.undertow.testutils.DefaultServer) RunWith(org.junit.runner.RunWith) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Test(org.junit.Test) IOException(java.io.IOException) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) ServletContainer(io.undertow.servlet.api.ServletContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) WebSocketReconnectHandler(io.undertow.websockets.jsr.WebSocketReconnectHandler) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) URI(java.net.URI) Assert(org.junit.Assert) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) WebSocketReconnectHandler(io.undertow.websockets.jsr.WebSocketReconnectHandler) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) IOException(java.io.IOException) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) URI(java.net.URI) CloseReason(javax.websocket.CloseReason) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Session(javax.websocket.Session) BeforeClass(org.junit.BeforeClass)

Example 8 with WebSocketDeploymentInfo

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

the class WebsocketBasicAuthTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("charsetUser", "password-ΓΌ", "role1");
    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    Map<String, String> props = new HashMap<>();
    props.put("charset", "ISO_8859_1");
    props.put("user-agent-charsets", "Chrome,UTF-8,OPR,UTF-8");
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC", props));
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(loginConfig).addFilter(Servlets.filter("wrapper", WrapperFilter.class)).addFilterUrlMapping("wrapper", "/wrapper/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(SecuredEndpoint.class).addListener(containerReady -> deployment = containerReady));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    path.addPrefixPath(builder.getContextPath(), deploymentManager.start());
    DefaultServer.setRootHandler(path);
}
Also used : FilterChain(javax.servlet.FilterChain) ServletException(javax.servlet.ServletException) TestClassIntrospector(io.undertow.servlet.test.util.TestClassIntrospector) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) Endpoint(javax.websocket.Endpoint) MessageHandler(javax.websocket.MessageHandler) Map(java.util.Map) Filter(javax.servlet.Filter) URI(java.net.URI) BASIC(io.undertow.util.Headers.BASIC) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) AfterClass(org.junit.AfterClass) Session(javax.websocket.Session) ContainerProvider(javax.websocket.ContainerProvider) DefaultServer(io.undertow.testutils.DefaultServer) ServerEndpoint(javax.websocket.server.ServerEndpoint) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Principal(java.security.Principal) ServletResponse(javax.servlet.ServletResponse) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SecurityInfo(io.undertow.servlet.api.SecurityInfo) BeforeClass(org.junit.BeforeClass) CloseReason(javax.websocket.CloseReason) HttpOneOnly(io.undertow.testutils.HttpOneOnly) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) RunWith(org.junit.runner.RunWith) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) HashMap(java.util.HashMap) Servlets(io.undertow.servlet.Servlets) OnOpen(javax.websocket.OnOpen) HttpServletRequest(javax.servlet.http.HttpServletRequest) PathHandler(io.undertow.server.handlers.PathHandler) AUTHORIZATION(io.undertow.util.Headers.AUTHORIZATION) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) ClientConfigurator(io.undertow.websockets.jsr.test.annotated.ClientConfigurator) ServletRequest(javax.servlet.ServletRequest) LoginConfig(io.undertow.servlet.api.LoginConfig) EndpointConfig(javax.websocket.EndpointConfig) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) ServletContainer(io.undertow.servlet.api.ServletContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) TimeUnit(java.util.concurrent.TimeUnit) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) FilterConfig(javax.servlet.FilterConfig) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) DispatcherType(javax.servlet.DispatcherType) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) FlexBase64(io.undertow.util.FlexBase64) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) HashMap(java.util.HashMap) PathHandler(io.undertow.server.handlers.PathHandler) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 9 with WebSocketDeploymentInfo

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

the class AnnotatedAutobahnServer method run.

public void run() {
    Xnio xnio = Xnio.getInstance();
    DeploymentManager deploymentManager = null;
    try {
        XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
        OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
        DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8024);
        HttpOpenListener openListener = new HttpOpenListener(pool);
        ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
        AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
        server.resumeAccepts();
        final ServletContainer container = ServletContainer.Factory.newInstance();
        DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).addEndpoint(AutobahnAnnotatedEndpoint.class).setDispatchToWorkerThread(true).addExtension(new PerMessageDeflateHandshake())).addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);
        deploymentManager = container.addDeployment(builder);
        deploymentManager.deploy();
        openListener.setRootHandler(deploymentManager.start());
    } catch (Exception e) {
        log.error("failed to start server", e);
    } finally {
        if (deploymentManager != null) {
            deploymentManager.undeploy();
            try {
                deploymentManager.stop();
            } catch (ServletException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) StreamConnection(org.xnio.StreamConnection) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletException(javax.servlet.ServletException) ServletException(javax.servlet.ServletException) Xnio(org.xnio.Xnio) OptionMap(org.xnio.OptionMap) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 10 with WebSocketDeploymentInfo

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

the class WebsocketStressTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    defaultContainer = ContainerProvider.getWebSocketContainer();
    executor = Executors.newFixedThreadPool(NUM_THREADS);
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(WebsocketStressTestCase.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(WebsocketStressTestCase.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(StressEndpoint.class).setDispatchToWorkerThread(true).addListener(containerReady -> deployment = containerReady)).setDeploymentName("servletContext.war");
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", deploymentManager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

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