Search in sources :

Example 1 with ServletContainer

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

the class FilterPathMappingTestCase method testBasicFilterMappings.

@Test
public void testBasicFilterMappings() throws IOException, ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("/a/*", PathMappingServlet.class).addMapping("/a/*"));
    builder.addServlet(new ServletInfo("/aa", PathMappingServlet.class).addMapping("/aa"));
    builder.addServlet(new ServletInfo("/", PathMappingServlet.class).addMapping("/"));
    builder.addServlet(new ServletInfo("contextRoot", PathMappingServlet.class).addMapping(""));
    builder.addServlet(new ServletInfo("/myservlet/*", PathMappingServlet.class).addMapping("/myservlet/*"));
    builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp"));
    builder.addServlet(new ServletInfo("/hello/*", PathMappingServlet.class).addMapping("/hello/*"));
    builder.addServlet(new ServletInfo("/test/*", PathMappingServlet.class).addMapping("/test/*"));
    builder.addServlet(new ServletInfo("/test2", PathMappingServlet.class).addMapping("/test2"));
    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);
    // non standard, but we still support it
    builder.addFilter(new FilterInfo("*", PathFilter.class));
    builder.addFilterUrlMapping("*", "*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/a/*", PathFilter.class));
    builder.addFilterUrlMapping("/a/*", "/a/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/aa", PathFilter.class));
    builder.addFilterUrlMapping("/aa", "/aa", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("*.bop", PathFilter.class));
    builder.addFilterUrlMapping("*.bop", "*.bop", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/myservlet/myfilter/*", PathFilter.class));
    builder.addFilterUrlMapping("/myservlet/myfilter/*", "/myservlet/myfilter/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/myfilter/*", PathFilter.class));
    builder.addFilterUrlMapping("/myfilter/*", "/myfilter/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("contextRoot", PathFilter.class));
    builder.addFilterServletNameMapping("contextRoot", "contextRoot", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("defaultName", PathFilter.class));
    builder.addFilterServletNameMapping("defaultName", "/", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/helloworld/index.html", PathFilter.class));
    builder.addFilterUrlMapping("/helloworld/index.html", "/helloworld/index.html", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/test", PathFilter.class));
    builder.addFilterUrlMapping("/test", "/test", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("/test2/*", PathFilter.class));
    builder.addFilterUrlMapping("/test2/*", "/test2/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("allByName", PathFilter.class));
    builder.addFilterServletNameMapping("allByName", "*", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war");
    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "test", "/test/* - /test - null", "/*", "*", "/test", "allByName");
        runTest(client, "test2", "/test2 - /test2 - null", "/*", "*", "/test2/*", "allByName");
        runTest(client, "aa", "/aa - /aa - null", "/*", "*", "/aa", "allByName");
        runTest(client, "a/c", "/a/* - /a - /c", "/*", "*", "/a/*", "allByName");
        runTest(client, "a", "/a/* - /a - null", "/*", "*", "/a/*", "allByName");
        runTest(client, "aa/b", "/ - /aa/b - null", "/*", "*", "defaultName", "allByName");
        runTest(client, "a/b/c/d", "/a/* - /a - /b/c/d", "/*", "*", "/a/*", "allByName");
        runTest(client, "defaultStuff", "/ - /defaultStuff - null", "/*", "*", "defaultName", "allByName");
        runTest(client, "", "contextRoot - / - null", "/*", "*", "contextRoot", "allByName");
        runTest(client, "yyyy.bop", "/ - /yyyy.bop - null", "/*", "*", "*.bop", "defaultName", "allByName");
        runTest(client, "a/yyyy.bop", "/a/* - /a - /yyyy.bop", "/*", "*", "*.bop", "/a/*", "allByName");
        runTest(client, "myservlet/myfilter/file.dat", "/myservlet/* - /myservlet - /myfilter/file.dat", "/*", "*", "/myservlet/myfilter/*", "allByName");
        runTest(client, "myservlet/myfilter/file.jsp", "/myservlet/* - /myservlet - /myfilter/file.jsp", "/*", "*", "/myservlet/myfilter/*", "allByName");
        runTest(client, "otherservlet/myfilter/file.jsp", "*.jsp - /otherservlet/myfilter/file.jsp - null", "/*", "*", "allByName");
        runTest(client, "myfilter/file.jsp", "*.jsp - /myfilter/file.jsp - null", "/*", "*", "/myfilter/*", "allByName");
        runTest(client, "helloworld/index.html", "/ - /helloworld/index.html - null", "/*", "*", "/helloworld/index.html", "defaultName", "allByName");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
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) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 2 with ServletContainer

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

the class FilterPathMappingTestCase method testExtensionMatchServletWithGlobalFilter.

@Test
public void testExtensionMatchServletWithGlobalFilter() throws IOException, ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp"));
    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war");
    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "aa.jsp", "*.jsp - /aa.jsp - null", "/*");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
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) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 3 with ServletContainer

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

the class FilterPathMappingTestCase method test_WFLY_1935.

@Test
public void test_WFLY_1935() throws IOException, ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    builder.addServlet(new ServletInfo("*.a", PathMappingServlet.class).addMapping("*.a"));
    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);
    // non standard, but we still support it
    builder.addFilter(new FilterInfo("/SimpleServlet.a", PathFilter.class));
    builder.addFilterUrlMapping("/SimpleServlet.a", "/SimpleServlet.a", DispatcherType.REQUEST);
    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war");
    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "SimpleServlet.a", "*.a - /SimpleServlet.a - null", "/*", "/SimpleServlet.a");
    } finally {
        client.getConnectionManager().shutdown();
    }
}
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) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 4 with ServletContainer

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

the class DispatcherForwardTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    // we don't run this test on h2 upgrade, as if it is run with the original request
    // the protocols will not match
    Assume.assumeFalse(DefaultServer.isH2upgrade());
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DispatcherForwardTestCase.class)).addServlet(new ServletInfo("forward", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, "forwarded").addMapping("/forward")).addServlet(new ServletInfo("dispatcher", ForwardServlet.class).addMapping("/dispatch")).addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path")).addFilter(new FilterInfo("notforwarded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Not forwarded")).addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!")).addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Name!")).addFilterUrlMapping("notforwarded", "/forward", DispatcherType.REQUEST).addFilterUrlMapping("inc", "/forward", DispatcherType.FORWARD).addFilterServletNameMapping("nameFilter", "forward", DispatcherType.FORWARD);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(new AccessLogHandler(root, RECEIVER, "%r %U %R", AccessLogFileTestCase.class.getClassLoader()));
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) AccessLogHandler(io.undertow.server.handlers.accesslog.AccessLogHandler) 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) MessageFilter(io.undertow.servlet.test.util.MessageFilter) FilterInfo(io.undertow.servlet.api.FilterInfo) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Example 5 with ServletContainer

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

the class DispatcherIncludeTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DispatcherIncludeTestCase.class)).addServlet(new ServletInfo("include", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, "included").addMapping("/include")).addServlet(new ServletInfo("dispatcher", IncludeServlet.class).addMapping("/dispatch")).addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path")).addFilter(new FilterInfo("notIncluded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Not Included")).addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!")).addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Name!")).addFilterUrlMapping("notIncluded", "/include", DispatcherType.REQUEST).addFilterUrlMapping("inc", "/include", DispatcherType.INCLUDE).addFilterServletNameMapping("nameFilter", "include", DispatcherType.INCLUDE);
    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) MessageFilter(io.undertow.servlet.test.util.MessageFilter) FilterInfo(io.undertow.servlet.api.FilterInfo) MessageServlet(io.undertow.servlet.test.util.MessageServlet) BeforeClass(org.junit.BeforeClass)

Aggregations

ServletContainer (io.undertow.servlet.api.ServletContainer)90 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)86 DeploymentManager (io.undertow.servlet.api.DeploymentManager)76 PathHandler (io.undertow.server.handlers.PathHandler)74 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 FilterInfo (io.undertow.servlet.api.FilterInfo)18 LoginConfig (io.undertow.servlet.api.LoginConfig)18 ServletException (javax.servlet.ServletException)17 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