StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
appDir.getAbsolutePath());
LifecycleListener[] listener = ctx.findLifecycleListeners();
assertEquals(3,listener.length);
assertTrue(listener[1] instanceof ContextConfig);
ContextConfig config = new ContextConfig() {
@Override
protected WebXml createWebXml() {
WebXml wxml = new WebXml();
wxml.addAbsoluteOrdering("resources");
wxml.addAbsoluteOrdering("resources2");
return wxml;
}
};
// prevent it from looking ( if it finds one - it'll have dup error )
config.setDefaultWebXml(Constants.NoDefaultWebXml);
listener[1] = config;
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMapping("/getresource", "getresource");
tomcat.start();
assertPageContains("/test/getresource?path=/resourceF.jsp",
"<p>resourceF.jsp in resources2.jar</p>");
assertPageContains("/test/getresource?path=/resourceB.jsp",
"<p>resourceB.jsp in resources.jar</p>");
ctx.stop();
LifecycleListener[] listener1 = ctx.findLifecycleListeners();
// change ordering and reload
ContextConfig config1 = new ContextConfig() {
@Override
protected WebXml createWebXml() {
WebXml wxml = new WebXml();
wxml.addAbsoluteOrdering("resources2");
wxml.addAbsoluteOrdering("resources");
return wxml;
}
};
// prevent it from looking ( if it finds one - it'll have dup error )
config1.setDefaultWebXml(Constants.NoDefaultWebXml);
listener1[1] = config1;
// Need to init since context won't call init
config1.lifecycleEvent(
new LifecycleEvent(ctx, Lifecycle.AFTER_INIT_EVENT, null));
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMapping("/getresource", "getresource");
ctx.start();