use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.
the class BypassServletTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(new ServletInfo("servlet", MessageServlet.class).addMapping("/").addInitParam(MessageServlet.MESSAGE, "This is a servlet")).addListener(new ListenerInfo(TestListener.class)).addInitialHandlerChainWrapper(new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
return new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (exchange.getRelativePath().equals("/async")) {
exchange.getResponseSender().send("This is not a servlet", IoCallback.END_EXCHANGE);
} else {
handler.handleRequest(exchange);
}
}
};
}
});
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 ContentTypeFilesTestCase 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(ContentTypeFilesTestCase.class.getClassLoader()).setContextPath("/app").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(ContentTypeServlet.class)).setDefaultServletConfig(new DefaultServletConfig(true)).addMimeMapping(new MimeMapping("jnlp", "application/x-java-jnlp-file"));
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 ResponseWriterTestCase 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(ResponseWriterTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").addServlet(Servlets.servlet("resp", ResponseWriterServlet.class).addMapping("/resp")).addServlet(Servlets.servlet("respLArget", LargeResponseWriterServlet.class).addMapping("/large"));
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 EagerServletLifecycleTestCase method testServletLifecycle.
@Test
public void testServletLifecycle() throws Exception {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);
DeploymentInfo builder = new DeploymentInfo().setClassLoader(EagerServletLifecycleTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").setEagerFilterInit(true).addFilter(f).addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
Assert.assertTrue(LifecycleFilter.initCalled);
}
use of io.undertow.servlet.api.DeploymentManager in project undertow by undertow-io.
the class ServletLifecycleTestCase method testServletLifecycle.
@Test
public void testServletLifecycle() throws Exception {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
ServletInfo s = new ServletInfo("servlet", LifeCycleServlet.class).addMapping("/aa");
FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ServletLifecycleTestCase.class.getClassLoader()).setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServlet(s).addFilter(f).addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
manager.stop();
manager.undeploy();
Assert.assertTrue(LifeCycleServlet.initCalled);
Assert.assertTrue(LifeCycleServlet.destroyCalled);
Assert.assertTrue(LifecycleFilter.initCalled);
Assert.assertTrue(LifecycleFilter.destroyCalled);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations