Search in sources :

Example 21 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class BinaryEndpointTest method setup.

@BeforeClass
public static void setup() throws Exception {
    bytes = new byte[256 * 1024];
    new Random().nextBytes(bytes);
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(BinaryEndpointTest.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).addServlet(Servlets.servlet("bin", BinaryEndpointServlet.class).setLoadOnStartup(100)).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addListener(new WebSocketDeploymentInfo.ContainerReadyListener() {

        @Override
        public void ready(ServerWebSocketContainer container) {
            deployment = container;
        }
    })).setDeploymentName("servletContext.war");
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    DefaultServer.setRootHandler(new RequestDumpingHandler(manager.start()));
    DefaultServer.startSSLServer();
}
Also used : Random(java.util.Random) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) RequestDumpingHandler(io.undertow.server.handlers.RequestDumpingHandler) 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 ServletContainer

use of io.undertow.servlet.api.ServletContainer 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 23 with ServletContainer

use of io.undertow.servlet.api.ServletContainer 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 24 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class ServletClientCertAuthTestCase method setup.

@BeforeClass
public static void setup() throws ServletException, IOException {
    DefaultServer.startSSLServer();
    clientSSLContext = DefaultServer.getClientSSLContext();
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo usernameServlet = new ServletInfo("Username Servlet", SendUsernameServlet.class).addMapping("/secured/username");
    ServletInfo authTypeServlet = new ServletInfo("Auth Type Servlet", SendAuthTypeServlet.class).addMapping("/secured/authType");
    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("CLIENT_CERT"));
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(loginConfig).addServlets(usernameServlet, authTypeServlet);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) SendUsernameServlet(io.undertow.servlet.test.security.SendUsernameServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SendAuthTypeServlet(io.undertow.servlet.test.security.SendAuthTypeServlet) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 25 with ServletContainer

use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.

the class EmptyRoleSemanticTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", AuthenticationMessageServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).addMapping("/permit").addMapping("/deny").addMapping("/authenticate");
    ServletIdentityManager identityManager = new ServletIdentityManager();
    // Just one role less user.
    identityManager.addUser("user1", "password1");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addServlet(s);
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/permit")).setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/deny")).setEmptyRoleSemantic(EmptyRoleSemantic.DENY));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/authenticate")).setEmptyRoleSemantic(EmptyRoleSemantic.AUTHENTICATE));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) 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) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Aggregations

ServletContainer (io.undertow.servlet.api.ServletContainer)71 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)68 DeploymentManager (io.undertow.servlet.api.DeploymentManager)68 PathHandler (io.undertow.server.handlers.PathHandler)58 BeforeClass (org.junit.BeforeClass)55 ServletInfo (io.undertow.servlet.api.ServletInfo)51 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)17 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 FilterInfo (io.undertow.servlet.api.FilterInfo)16 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)13 LoginConfig (io.undertow.servlet.api.LoginConfig)12 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)10 ListenerInfo (io.undertow.servlet.api.ListenerInfo)9 ServletException (javax.servlet.ServletException)9 Test (org.junit.Test)9 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)8 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)8 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 TestHttpClient (io.undertow.testutils.TestHttpClient)7 MessageServlet (io.undertow.servlet.test.util.MessageServlet)6