Search in sources :

Example 61 with DeploymentManager

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

the class ServletContextImpl method getSession.

public HttpSessionImpl getSession(final ServletContextImpl originalServletContext, final HttpServerExchange exchange, boolean create) {
    SessionConfig c = originalServletContext.getSessionConfig();
    HttpSessionImpl httpSession = exchange.getAttachment(sessionAttachmentKey);
    if (httpSession != null && httpSession.isInvalid()) {
        exchange.removeAttachment(sessionAttachmentKey);
        httpSession = null;
    }
    if (httpSession == null) {
        final SessionManager sessionManager = deployment.getSessionManager();
        Session session = sessionManager.getSession(exchange, c);
        if (session != null) {
            httpSession = SecurityActions.forSession(session, this, false);
            exchange.putAttachment(sessionAttachmentKey, httpSession);
        } else if (create) {
            String existing = c.findSessionId(exchange);
            if (originalServletContext != this) {
                //this is a cross context request
                //we need to make sure there is a top level session
                originalServletContext.getSession(originalServletContext, exchange, true);
            } else if (existing != null) {
                if (deploymentInfo.isCheckOtherSessionManagers()) {
                    boolean found = false;
                    for (String deploymentName : deployment.getServletContainer().listDeployments()) {
                        DeploymentManager deployment = this.deployment.getServletContainer().getDeployment(deploymentName);
                        if (deployment != null) {
                            if (deployment.getDeployment().getSessionManager().getSession(existing) != null) {
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found) {
                        c.clearSession(exchange, existing);
                    }
                } else {
                    c.clearSession(exchange, existing);
                }
            }
            final Session newSession = sessionManager.createSession(exchange, c);
            httpSession = SecurityActions.forSession(newSession, this, true);
            exchange.putAttachment(sessionAttachmentKey, httpSession);
        }
    }
    return httpSession;
}
Also used : DeploymentManager(io.undertow.servlet.api.DeploymentManager) SessionManager(io.undertow.server.session.SessionManager) SslSessionConfig(io.undertow.server.session.SslSessionConfig) PathParameterSessionConfig(io.undertow.server.session.PathParameterSessionConfig) SessionConfig(io.undertow.server.session.SessionConfig) Session(io.undertow.server.session.Session)

Example 62 with DeploymentManager

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

the class CrossContextClassLoaderTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("includer", IncludeServlet.class).addMapping("/a");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(new TempClassLoader("IncluderClassLoader")).setContextPath("/includer").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("includer.war").addServlet(s);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    s = new ServletInfo("included", IncludedServlet.class).addMapping("/a");
    builder = new DeploymentInfo().setClassLoader(new TempClassLoader("IncludedClassLoader")).setContextPath("/included").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("included.war").addServlet(s);
    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) BeforeClass(org.junit.BeforeClass)

Example 63 with DeploymentManager

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

the class WelcomeFileSecurityTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(WelcomeFileSecurityTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/path/default")).addSecurityConstraint(new SecurityConstraint().addRoleAllowed("role1").addWebResourceCollection(new WebResourceCollection().addUrlPattern("/index.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) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletPathMappingTestCase(io.undertow.servlet.test.path.ServletPathMappingTestCase) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 64 with DeploymentManager

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

the class SimpleServletTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo s = new ServletInfo("servlet", MessageServlet.class).addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).addMapping("/aa");
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(s);
    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) BeforeClass(org.junit.BeforeClass)

Example 65 with DeploymentManager

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

the class ServletMetricsHandlerTestCase method testMetrics.

@Test
public void testMetrics() throws Exception {
    final TestMetricsCollector metricsCollector = new TestMetricsCollector();
    CompletionLatchHandler completionLatchHandler;
    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("MetricTestServlet", MetricTestServlet.class).addMapping("/path/default"));
    builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
    builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);
    builder.setMetricsCollector(metricsCollector);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(completionLatchHandler = new CompletionLatchHandler(root));
    HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/path/default");
    TestHttpClient client = new TestHttpClient();
    try {
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric"));
        completionLatchHandler.await();
        completionLatchHandler.reset();
        MetricsHandler.MetricResult metrics = metricsCollector.getMetrics("MetricTestServlet");
        Assert.assertEquals(1, metrics.getTotalRequests());
        Assert.assertTrue(metrics.getMaxRequestTime() > 0);
        Assert.assertEquals(metrics.getMinRequestTime(), metrics.getMaxRequestTime());
        Assert.assertEquals(metrics.getMaxRequestTime(), metrics.getTotalRequestTime());
        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric"));
        completionLatchHandler.await();
        completionLatchHandler.reset();
        metrics = metricsCollector.getMetrics("MetricTestServlet");
        Assert.assertEquals(2, metrics.getTotalRequests());
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : HelloFilter(io.undertow.servlet.test.defaultservlet.HelloFilter) DefaultServletTestCase(io.undertow.servlet.test.defaultservlet.DefaultServletTestCase) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) CompletionLatchHandler(io.undertow.util.CompletionLatchHandler) HttpGet(org.apache.http.client.methods.HttpGet) PathHandler(io.undertow.server.handlers.PathHandler) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) ServletInfo(io.undertow.servlet.api.ServletInfo) ServletContainer(io.undertow.servlet.api.ServletContainer) MetricsHandler(io.undertow.server.handlers.MetricsHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo) Test(org.junit.Test)

Aggregations

DeploymentManager (io.undertow.servlet.api.DeploymentManager)84 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)75 ServletContainer (io.undertow.servlet.api.ServletContainer)69 PathHandler (io.undertow.server.handlers.PathHandler)58 BeforeClass (org.junit.BeforeClass)53 ServletInfo (io.undertow.servlet.api.ServletInfo)51 TestResourceLoader (io.undertow.servlet.test.util.TestResourceLoader)17 FilterInfo (io.undertow.servlet.api.FilterInfo)16 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)16 ServletException (javax.servlet.ServletException)14 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)8 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)8 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)8 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)8 Test (org.junit.Test)8 TestHttpClient (io.undertow.testutils.TestHttpClient)7 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)5