use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.
the class MarkSecureHandlerTestCase method testMarkSecureHandlerWithSecureCookieHandler.
@Test
public void testMarkSecureHandlerWithSecureCookieHandler() throws IOException, GeneralSecurityException, 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("/issecure");
DeploymentInfo builder = new DeploymentInfo().setClassLoader(MarkSecureHandlerTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(s);
builder.addFilter(new FilterInfo("issecure-filter", IsSecureFilter.class));
builder.addFilterUrlMapping("issecure-filter", "/*", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(new MarkSecureHandler(new SecureCookieHandler(root)));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/issecure");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
// When MarkSecureHandler is enabled, req.isSecure() should be true
Assert.assertEquals("true", result.getHeaders("issecure")[0].getValue());
// When SecureCookieHandler is enabled with MarkSecureHandler, secure cookie is enabled as this channel is treated as secure
Header header = result.getFirstHeader("set-cookie");
Assert.assertEquals("foo=bar; secure", header.getValue());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(HELLO_WORLD, response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.
the class MarkSecureHandlerTestCase method testMarkSecureHandler.
@Test
public void testMarkSecureHandler() throws IOException, GeneralSecurityException, 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("/issecure");
DeploymentInfo builder = new DeploymentInfo().setClassLoader(MarkSecureHandlerTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(s);
builder.addFilter(new FilterInfo("issecure-filter", IsSecureFilter.class));
builder.addFilterUrlMapping("issecure-filter", "/*", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(new MarkSecureHandler(root));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/issecure");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
// When MarkSecureHandler is enabled, req.isSecure() should be true
Assert.assertEquals("true", result.getHeaders("issecure")[0].getValue());
// When SecureCookieHandler is not enabled, secure cookie is not automatically enabled.
Header header = result.getFirstHeader("set-cookie");
Assert.assertEquals("foo=bar", header.getValue());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(HELLO_WORLD, response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.
the class ServletSessionListenerOrderingTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler path = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/listener").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("listener.war").addListener(new ListenerInfo(FirstListener.class)).addListener(new ListenerInfo(SecondListener.class)).addServlet(new ServletInfo("message", EmptyServlet.class).addMapping("/*"));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
path.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(path);
}
use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.
the class AsyncListenerOnErrorTest method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
ServletInfo f = new ServletInfo("faultyServlet", FaultyServlet.class).addMapping("/faulty");
ServletInfo a1 = new ServletInfo("asyncServlet1", AsyncServlet1.class).setAsyncSupported(true).addMapping("/async1");
ServletInfo a2 = new ServletInfo("asyncServlet2", AsyncServlet2.class).setAsyncSupported(true).addMapping("/async2");
ServletInfo a3 = new ServletInfo("asyncServlet3", AsyncServlet3.class).setAsyncSupported(true).addMapping("/async3");
ServletInfo a4 = new ServletInfo("asyncServlet4", AsyncServlet4.class).setAsyncSupported(true).addMapping("/async4");
ServletInfo a5 = new ServletInfo("asyncServlet5", AsyncServlet5.class).setAsyncSupported(true).addMapping("/async5");
DeploymentInfo builder = new DeploymentInfo().setClassLoader(AsyncListenerOnErrorTest.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(f, a1, a2, a3, a4, a5);
builder.setExceptionHandler(LoggingExceptionHandler.builder().add(IllegalStateException.class, "io.undertow", Logger.Level.DEBUG).build());
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.ServletContainer in project undertow by undertow-io.
the class NestedListenerInvocationTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class).setAsyncSupported(true).addMapping("/async");
DeploymentInfo builder = new DeploymentInfo().setClassLoader(NestedListenerInvocationTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlets(a).addListener(new ListenerInfo(SimpleRequestListener.class));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
Aggregations