@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")
.addServlets(
new ServletInfo("request", RequestPathServlet.class)
.addMapping("/req/*"),
new ServletInfo("DefaultServlet", RequestPathServlet.class)
.addMapping("/"),
new ServletInfo("ExactServlet", RequestPathServlet.class)
.addMapping("/exact"),
new ServletInfo("ExactTxtServlet", RequestPathServlet.class)
.addMapping("/exact.txt"),
new ServletInfo("HtmlServlet", RequestPathServlet.class)
.addMapping("*.html")
)
.addFilters(
new FilterInfo("header", SetHeaderFilter.class)
.addInitParam("header", "Filter").addInitParam("value", "true"),
new FilterInfo("all", SetHeaderFilter.class)
.addInitParam("header", "all").addInitParam("value", "true"))
.addFilterUrlMapping("header", "*.txt", DispatcherType.REQUEST)
.addFilterUrlMapping("all", "/*", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
try {
pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
} catch (ServletException e) {
throw new RuntimeException(e);
}
DefaultServer.setRootHandler(pathHandler);