Search in sources :

Example 11 with ServletInfo

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

the class ServletInputStreamEarlyCloseTestCase method testServletInputStreamEarlyClose.

@Test
public void testServletInputStreamEarlyClose() throws Exception {
    DeploymentUtils.setupServlet(new ServletInfo(SERVLET, EarlyCloseServlet.class).addMapping("/" + SERVLET));
    TestHttpClient client = new TestHttpClient();
    try {
        String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + SERVLET;
        HttpPost post = new HttpPost(uri);
        post.setEntity(new StringEntity("A non-empty request body"));
        HttpResponse result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);
        result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);
        result = client.execute(post);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        HttpClientUtils.readResponse(result);
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 12 with ServletInfo

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

the class ServletRegistrationImpl method addMapping.

@Override
public Set<String> addMapping(final String... urlPatterns) {
    DeploymentInfo deploymentInfo = deployment.getDeploymentInfo();
    final Set<String> ret = new HashSet<>();
    final Set<String> existing = new HashSet<>();
    for (ServletInfo s : deploymentInfo.getServlets().values()) {
        if (!s.getName().equals(servletInfo.getName())) {
            existing.addAll(s.getMappings());
        }
    }
    for (String pattern : urlPatterns) {
        if (existing.contains(pattern)) {
            ret.add(pattern);
        }
    }
    //only update if no changes have been made
    if (ret.isEmpty()) {
        for (String pattern : urlPatterns) {
            if (!servletInfo.getMappings().contains(pattern)) {
                servletInfo.addMapping(pattern);
            }
        }
    }
    deployment.getServletPaths().invalidate();
    return ret;
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) HashSet(java.util.HashSet)

Example 13 with ServletInfo

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

the class DefaultServletCachingTestCase method setup.

@BeforeClass
public static void setup() throws ServletException, IOException {
    tmpDir = Files.createTempDirectory(DIR_NAME);
    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 CachingResourceManager(100, 10000, dataCache, new PathResourceManager(tmpDir, 10485760), METADATA_MAX_AGE));
    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default")).addFilter(Servlets.filter("message", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "FILTER_TEXT ")).addFilterUrlMapping("message", "*.txt", DispatcherType.REQUEST);
    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) CachingResourceManager(io.undertow.server.handlers.resource.CachingResourceManager) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) MessageFilter(io.undertow.servlet.test.util.MessageFilter) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) BeforeClass(org.junit.BeforeClass)

Example 14 with ServletInfo

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

the class DefaultServletTestCase 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(DefaultServletTestCase.class));
    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default"));
    builder.addServlet(new ServletInfo("default", DefaultServlet.class).addInitParam("directory-listing", "true").addMapping("/*"));
    //see UNDERTOW-458
    builder.addFilter(new FilterInfo("date-header", GetDateFilter.class));
    builder.addFilterUrlMapping("date-header", "/*", DispatcherType.REQUEST);
    builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
    builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);
    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) DefaultServlet(io.undertow.servlet.handlers.DefaultServlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) BeforeClass(org.junit.BeforeClass)

Example 15 with ServletInfo

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

the class ServletAndResourceWelcomeFileTestCase 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(ServletAndResourceWelcomeFileTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default");
    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("*.html"));
    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) ServletPathMappingTestCase(io.undertow.servlet.test.path.ServletPathMappingTestCase) BeforeClass(org.junit.BeforeClass)

Aggregations

ServletInfo (io.undertow.servlet.api.ServletInfo)67 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)58 ServletContainer (io.undertow.servlet.api.ServletContainer)51 DeploymentManager (io.undertow.servlet.api.DeploymentManager)50 PathHandler (io.undertow.server.handlers.PathHandler)49 BeforeClass (org.junit.BeforeClass)43 FilterInfo (io.undertow.servlet.api.FilterInfo)15 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)14 LoginConfig (io.undertow.servlet.api.LoginConfig)13 ListenerInfo (io.undertow.servlet.api.ListenerInfo)11 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)11 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)10 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)9 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)9 Test (org.junit.Test)9 TestHttpClient (io.undertow.testutils.TestHttpClient)8 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)7 MessageServlet (io.undertow.servlet.test.util.MessageServlet)6 Servlet (javax.servlet.Servlet)6 ServletException (javax.servlet.ServletException)6