Search in sources :

Example 6 with ServletContainer

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

the class ChangeSessionIdTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", ChangeSessionIdServlet.class).addMapping("/aa");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addListener(new ListenerInfo(ChangeSessionIdListener.class)).addServlet(s);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(path);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ListenerInfo(io.undertow.servlet.api.ListenerInfo) 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 7 with ServletContainer

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

the class ServletSessionCrawlerTestCase method testCrawlerSessionUsage.

@Test
public void testCrawlerSessionUsage() throws IOException, InterruptedException {
    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setCrawlerSessionManagerConfig(new CrawlerSessionManagerConfig()).setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addListener(new ListenerInfo(SessionCookieConfigListener.class)).addServlets(new ServletInfo("servlet", SessionServlet.class).addMapping("/aa/b"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
    TestHttpClient client = new TestHttpClient();
    client.setCookieStore(new CookieStore() {

        @Override
        public void addCookie(Cookie cookie) {
        }

        @Override
        public List<Cookie> getCookies() {
            return Collections.EMPTY_LIST;
        }

        @Override
        public boolean clearExpired(Date date) {
            return false;
        }

        @Override
        public void clear() {
        }
    });
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa/b");
        get.addHeader(Headers.USER_AGENT_STRING, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        String response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("1", response);
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("2", response);
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("3", response);
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : Cookie(org.apache.http.cookie.Cookie) DeploymentManager(io.undertow.servlet.api.DeploymentManager) HttpGet(org.apache.http.client.methods.HttpGet) PathHandler(io.undertow.server.handlers.PathHandler) HttpResponse(org.apache.http.HttpResponse) Date(java.util.Date) TestHttpClient(io.undertow.testutils.TestHttpClient) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletException(javax.servlet.ServletException) CookieStore(org.apache.http.client.CookieStore) ListenerInfo(io.undertow.servlet.api.ListenerInfo) CrawlerSessionManagerConfig(io.undertow.servlet.api.CrawlerSessionManagerConfig) ServletContainer(io.undertow.servlet.api.ServletContainer) List(java.util.List) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Test(org.junit.Test)

Example 8 with ServletContainer

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

the class ServletSessionTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addListener(new ListenerInfo(SessionCookieConfigListener.class)).addServlets(new ServletInfo("servlet", SessionServlet.class).addMapping("/aa/b"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ServletException(javax.servlet.ServletException) ListenerInfo(io.undertow.servlet.api.ListenerInfo) 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 9 with ServletContainer

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

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

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