WebappContext context =
new WebappContext("TestContext", contextPathLocal);
if (servletClass != null) {
ServletRegistration registration =
context.addServlet(servletClass.getName(), servletClass);
for(String initParamName : initParams.keySet()) {
registration.setInitParameter(initParamName, initParams.get(initParamName));
}
registration.addMapping(servletPathLocal);
} else {
ServletRegistration registration =
context.addServlet("default", new HttpServlet() {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(404);
}
});
registration.addMapping("");
}
for(Class<? extends EventListener> eventListener : eventListeners) {
context.addListener(eventListener);
}