Search in sources :

Example 21 with FilterInfo

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

the class WelcomeFileTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(WelcomeFileTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default", "servletPath/servletFile.xhtml").addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default")).addServlet(new ServletInfo("ServletPath", PathTestServlet.class).addMapping("/foo/servletPath/*")).addFilter(new FilterInfo("Filter", NoOpFilter.class)).addFilterUrlMapping("Filter", "/*", DispatcherType.REQUEST).addFilterUrlMapping("Filter", "/", DispatcherType.REQUEST);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext2").setDeploymentName("servletContext2.war").setResourceManager(new TestResourceLoader(WelcomeFileTestCase.class)).addWelcomePages("doesnotexist.html", "index.do").addServlet(new ServletInfo("*.do", PathTestServlet.class).addMapping("*.do"));
    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) PathTestServlet(io.undertow.servlet.test.util.PathTestServlet) 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) ServletPathMappingTestCase(io.undertow.servlet.test.path.ServletPathMappingTestCase) BeforeClass(org.junit.BeforeClass)

Example 22 with FilterInfo

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

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

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

the class AbstractResponseWrapperTestCase method setup.

@Before
public void setup() throws ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    builder.setExceptionHandler(LoggingExceptionHandler.builder().add(IllegalArgumentException.class, "io.undertow", Logger.Level.DEBUG).build());
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("wrapperServlet", WrapperServlet.class).addMapping("/*"));
    builder.addFilter(new FilterInfo("standard", StandardRequestWrappingFilter.class));
    builder.addFilterUrlMapping("standard", "/standard", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("nonstandard", NonStandardRequestWrappingFilter.class));
    builder.addFilterUrlMapping("nonstandard", "/nonstandard", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(AbstractResponseWrapperTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setAllowNonStandardWrappers(isNonStandardAllowed());
    final 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) FilterInfo(io.undertow.servlet.api.FilterInfo) Before(org.junit.Before)

Aggregations

FilterInfo (io.undertow.servlet.api.FilterInfo)24 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)19 DeploymentManager (io.undertow.servlet.api.DeploymentManager)16 ServletContainer (io.undertow.servlet.api.ServletContainer)16 ServletInfo (io.undertow.servlet.api.ServletInfo)15 PathHandler (io.undertow.server.handlers.PathHandler)14 BeforeClass (org.junit.BeforeClass)6 Test (org.junit.Test)6 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)5 TestHttpClient (io.undertow.testutils.TestHttpClient)5 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)4 LoginConfig (io.undertow.servlet.api.LoginConfig)3 PerMessageDeflateHandshake (io.undertow.websockets.extensions.PerMessageDeflateHandshake)3 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)2 HandlerWrapper (io.undertow.server.HandlerWrapper)2 HttpHandler (io.undertow.server.HttpHandler)2 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)2 ServletExtension (io.undertow.servlet.ServletExtension)2 ErrorPage (io.undertow.servlet.api.ErrorPage)2 ListenerInfo (io.undertow.servlet.api.ListenerInfo)2