Search in sources :

Example 76 with ServletContainer

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

the class AsyncListenerOnCompleteTest method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo f = new ServletInfo("asyncServlet", OnCompleteServlet.class).addMapping("/async").setAsyncSupported(true);
    ServletInfo a1 = new ServletInfo("message", MessageServlet.class).setAsyncSupported(true).addInitParam(MessageServlet.MESSAGE, "Hello").addMapping("/message");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(AsyncListenerOnCompleteTest.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(f, a1);
    builder.setExceptionHandler(LoggingExceptionHandler.builder().add(IllegalStateException.class, "io.undertow", Logger.Level.DEBUG).build());
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Example 77 with ServletContainer

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

the class RealPathTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo realPathServlet = new ServletInfo("real path servlet", RealPathServlet.class).addMapping("/path/*");
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(RealPathTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(RealPathTestCase.class)).addServlets(realPathServlet);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) BeforeClass(org.junit.BeforeClass)

Example 78 with ServletContainer

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

the class ServletLifecycleTestCase method testServletLifecycle.

@Test
public void testServletLifecycle() throws Exception {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", LifeCycleServlet.class).addMapping("/aa");
    FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(ServletLifecycleTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(s).addFilter(f).addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        final String response = HttpClientUtils.readResponse(result);
        manager.stop();
        manager.undeploy();
        Assert.assertTrue(LifeCycleServlet.initCalled);
        Assert.assertTrue(LifeCycleServlet.destroyCalled);
        Assert.assertTrue(LifecycleFilter.initCalled);
        Assert.assertTrue(LifecycleFilter.destroyCalled);
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) HttpGet(org.apache.http.client.methods.HttpGet) PathHandler(io.undertow.server.handlers.PathHandler) HttpResponse(org.apache.http.HttpResponse) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 79 with ServletContainer

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

the class EagerServletLifecycleTestCase method testServletLifecycle.

@Test
public void testServletLifecycle() throws Exception {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(EagerServletLifecycleTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setEagerFilterInit(true).addFilter(f).addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    Assert.assertTrue(LifecycleFilter.initCalled);
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) Test(org.junit.Test)

Example 80 with ServletContainer

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

the class CrossContextServletSharedSessionTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final ServletContainer container = ServletContainer.Factory.newInstance();
    final PathHandler path = new PathHandler();
    DefaultServer.setRootHandler(path);
    InMemorySessionManager manager = new InMemorySessionManager("test");
    createDeployment("1", container, path, manager);
    createDeployment("2", container, path, manager);
}
Also used : ServletContainer(io.undertow.servlet.api.ServletContainer) PathHandler(io.undertow.server.handlers.PathHandler) InMemorySessionManager(io.undertow.server.session.InMemorySessionManager) BeforeClass(org.junit.BeforeClass)

Aggregations

ServletContainer (io.undertow.servlet.api.ServletContainer)92 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)88 DeploymentManager (io.undertow.servlet.api.DeploymentManager)78 PathHandler (io.undertow.server.handlers.PathHandler)76 BeforeClass (org.junit.BeforeClass)69 ServletInfo (io.undertow.servlet.api.ServletInfo)65 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)20 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)19 ServletException (javax.servlet.ServletException)19 FilterInfo (io.undertow.servlet.api.FilterInfo)18 LoginConfig (io.undertow.servlet.api.LoginConfig)18 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)16 Test (org.junit.Test)15 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)14 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)12 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)12 ListenerInfo (io.undertow.servlet.api.ListenerInfo)10 TestHttpClient (io.undertow.testutils.TestHttpClient)9 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)8 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)7