Search in sources :

Example 6 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader 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.getWorker()).addEndpoint(DisconnectServerEndpoint.class).addEndpoint(AnnotatedClientReconnectEndpoint.class).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer container) {
            deployment = container;
        }
    }).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 manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Also used : WebSocketReconnectHandler(io.undertow.websockets.jsr.WebSocketReconnectHandler) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) 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 7 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class TestMessagesReceivedInOrder method setup.

@BeforeClass
public static void setup() throws ServletException {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(TestMessagesReceivedInOrder.class.getClassLoader()).setContextPath("/").setResourceManager(new TestResourceLoader(TestMessagesReceivedInOrder.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(EchoSocket.class)).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/", manager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) 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)

Example 8 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class AnnotatedEndpointTest method setup.

@BeforeClass
public static void setup() throws Exception {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedEndpointTest.class.getClassLoader()).setContextPath("/ws").setResourceManager(new TestResourceLoader(AnnotatedEndpointTest.class)).setClassIntrospecter(TestClassIntrospector.INSTANCE).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(MessageEndpoint.class).addEndpoint(AnnotatedClientEndpoint.class).addEndpoint(AnnotatedClientEndpointWithConfigurator.class).addEndpoint(IncrementEndpoint.class).addEndpoint(EncodingEndpoint.class).addEndpoint(EncodingGenericsEndpoint.class).addEndpoint(TimeoutEndpoint.class).addEndpoint(ErrorEndpoint.class).addEndpoint(RootContextEndpoint.class).addEndpoint(ThreadSafetyEndpoint.class).addEndpoint(RequestUriEndpoint.class).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer container) {
            deployment = container;
        }
    })).addServlet(new ServletInfo("redirect", RedirectServlet.class).addMapping("/redirect")).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 9 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class WebsocketStressTestCase method setup.

@BeforeClass
public static void setup() throws Exception {
    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).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer container) {
            deployment = container;
        }
    })).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(Handlers.path().addPrefixPath("/ws", manager.start()));
}
Also used : TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) 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)

Example 10 with TestResourceLoader

use of io.undertow.servlet.test.util.TestResourceLoader in project undertow by undertow-io.

the class SaveOriginalPostRequestTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo securedRequestDumper = new ServletInfo("SecuredRequestDumperServlet", RequestDumper.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/secured/dumpRequest");
    ServletInfo securedIndexRequestDumper = new ServletInfo("SecuredIndexRequestDumperServlet", RequestDumper.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/index.html");
    ServletInfo unsecuredRequestDumper = new ServletInfo("UnsecuredRequestDumperServlet", RequestDumper.class).addMapping("/dumpRequest");
    ServletInfo loginFormServlet = new ServletInfo("loginPage", FormLoginServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("group1")).addMapping("/FormLoginServlet");
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).addWelcomePage("index.html").setResourceManager(new TestResourceLoader(SaveOriginalPostRequestTestCase.class)).setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")).addServlets(securedRequestDumper, unsecuredRequestDumper, loginFormServlet, securedIndexRequestDumper);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) BeforeClass(org.junit.BeforeClass)

Aggregations

DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)17 DeploymentManager (io.undertow.servlet.api.DeploymentManager)17 ServletContainer (io.undertow.servlet.api.ServletContainer)17 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 BeforeClass (org.junit.BeforeClass)16 PathHandler (io.undertow.server.handlers.PathHandler)11 ServletInfo (io.undertow.servlet.api.ServletInfo)11 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)6 FilterInfo (io.undertow.servlet.api.FilterInfo)5 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)5 ServletPathMappingTestCase (io.undertow.servlet.test.path.ServletPathMappingTestCase)3 LoginConfig (io.undertow.servlet.api.LoginConfig)2 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)2 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)2 MessageFilter (io.undertow.servlet.test.util.MessageFilter)2 MessageServlet (io.undertow.servlet.test.util.MessageServlet)2 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)1 MetricsHandler (io.undertow.server.handlers.MetricsHandler)1 AccessLogHandler (io.undertow.server.handlers.accesslog.AccessLogHandler)1 DefaultServletConfig (io.undertow.servlet.api.DefaultServletConfig)1