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;
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations