use of org.apache.catalina.LifecycleEvent in project tomcat70 by apache.
the class TestStandardContextResources method testResourcesAbsoluteOrdering.
@Test
public void testResourcesAbsoluteOrdering() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0-fragments");
// app dir is relative to server home
StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
LifecycleListener[] listener = ctx.findLifecycleListeners();
Assert.assertEquals(3, listener.length);
Assert.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>");
// Check ordering, for BZ 54391
Assert.assertEquals(Arrays.asList("resources.jar", "resources2.jar"), ctx.getServletContext().getAttribute(ServletContext.ORDERED_LIBS));
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();
assertPageContains("/test/getresource?path=/resourceF.jsp", "<p>resourceF.jsp in resources2.jar</p>");
assertPageContains("/test/getresource?path=/resourceB.jsp", "<p>resourceB.jsp in resources2.jar</p>");
// Check ordering, for BZ 54391
Assert.assertEquals(Arrays.asList("resources2.jar", "resources.jar"), ctx.getServletContext().getAttribute(ServletContext.ORDERED_LIBS));
}
use of org.apache.catalina.LifecycleEvent in project tomcat70 by apache.
the class LifecycleSupport method fireLifecycleEvent.
/**
* Notify all lifecycle event listeners that a particular event has
* occurred for this Container. The default implementation performs
* this notification synchronously using the calling thread.
*
* @param type Event type
* @param data Event data
*/
public void fireLifecycleEvent(String type, Object data) {
LifecycleEvent event = new LifecycleEvent(lifecycle, type, data);
LifecycleListener[] interested = listeners;
for (int i = 0; i < interested.length; i++) interested[i].lifecycleEvent(event);
}
use of org.apache.catalina.LifecycleEvent in project spring-boot by spring-projects.
the class TomcatReactiveWebServerFactoryTests method tomcatListeners.
@Test
void tomcatListeners() {
TomcatReactiveWebServerFactory factory = getFactory();
LifecycleListener[] listeners = new LifecycleListener[4];
Arrays.setAll(listeners, (i) -> mock(LifecycleListener.class));
factory.setContextLifecycleListeners(Arrays.asList(listeners[0], listeners[1]));
factory.addContextLifecycleListeners(listeners[2], listeners[3]);
this.webServer = factory.getWebServer(mock(HttpHandler.class));
InOrder ordered = inOrder((Object[]) listeners);
for (LifecycleListener listener : listeners) {
then(listener).should(ordered).lifecycleEvent(any(LifecycleEvent.class));
}
}
use of org.apache.catalina.LifecycleEvent in project spring-boot by spring-projects.
the class TomcatServletWebServerFactoryTests method tomcatListeners.
@Test
void tomcatListeners() {
TomcatServletWebServerFactory factory = getFactory();
LifecycleListener[] listeners = new LifecycleListener[4];
Arrays.setAll(listeners, (i) -> mock(LifecycleListener.class));
factory.setContextLifecycleListeners(Arrays.asList(listeners[0], listeners[1]));
factory.addContextLifecycleListeners(listeners[2], listeners[3]);
this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) listeners);
for (LifecycleListener listener : listeners) {
then(listener).should(ordered).lifecycleEvent(any(LifecycleEvent.class));
}
}
use of org.apache.catalina.LifecycleEvent in project tomee by apache.
the class TomEEUndeployTest method justAContextStop.
@Test
public void justAContextStop() throws Exception {
container.start();
assertEquals(0, webapps().length);
final StandardHost standardHost = StandardHost.class.cast(TomcatHelper.getServer().findService("Tomcat").getContainer().findChild("localhost"));
// not done in embedded but that's the way autodeploy works in normal tomcat
final HostConfig listener = new HostConfig();
standardHost.addLifecycleListener(listener);
createWebapp(new File(WORK_DIR, "tomee/webapps/my-webapp"));
listener.lifecycleEvent(new LifecycleEvent(standardHost, Lifecycle.START_EVENT, standardHost));
assertEquals(1, webapps().length);
webapps()[0].stop();
assertEquals(1, webapps().length);
webapps()[0].start();
assertEquals(1, webapps().length);
assertEquals("test", IO.slurp(new URL("http://localhost:" + http + "/my-webapp/")));
}
Aggregations