From caa0199efea7310286d86c972702fcad2f4ec7df Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Fri, 1 Mar 2013 18:09:19 +1100 Subject: [PATCH] 400312 ServletContextListener.contextInitialized() is not called when added in ServletContainerInitializer.onStartup --- .../annotations/AnnotationConfiguration.java | 4 ++-- .../ServletContainerInitializerListener.java | 18 ++++++++++-------- .../jetty/server/handler/ContextHandler.java | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index ecd59f409be..85c366073f0 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -224,10 +224,10 @@ public class AnnotationConfiguration extends AbstractConfiguration } - //add a listener which will call the servletcontainerinitializers when appropriate + //add a bean which will call the servletcontainerinitializers when appropriate ServletContainerInitializerListener listener = new ServletContainerInitializerListener(); listener.setWebAppContext(context); - context.addEventListener(listener); + context.addBean(listener, true); } diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ServletContainerInitializerListener.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ServletContainerInitializerListener.java index fed2b6a4fc1..317d8f76bd3 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ServletContainerInitializerListener.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ServletContainerInitializerListener.java @@ -22,12 +22,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.plus.annotation.ContainerInitializer; import org.eclipse.jetty.util.MultiMap; +import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.webapp.WebAppContext; @@ -37,7 +35,7 @@ import org.eclipse.jetty.webapp.WebAppContext; * * */ -public class ServletContainerInitializerListener implements ServletContextListener +public class ServletContainerInitializerListener extends AbstractLifeCycle { private static final Logger LOG = Log.getLogger(ServletContainerInitializerListener.class); protected WebAppContext _context = null; @@ -48,10 +46,12 @@ public class ServletContainerInitializerListener implements ServletContextListen _context = context; } + /** - * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) + * Call the doStart method of the ServletContainerInitializers + * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() */ - public void contextInitialized(ServletContextEvent sce) + public void doStart() { List initializers = (List)_context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZERS); MultiMap classMap = (MultiMap)_context.getAttribute(AnnotationConfiguration.CLASS_INHERITANCE_MAP); @@ -131,10 +131,12 @@ public class ServletContainerInitializerListener implements ServletContextListen } + /** - * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) + * Nothing to do for ServletContainerInitializers on stop + * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop() */ - public void contextDestroyed(ServletContextEvent sce) + public void doStop() { } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index fbee38f6ad2..db61bf26771 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -2327,6 +2327,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. if (!_enabled) throw new UnsupportedOperationException(); ContextHandler.this.addEventListener(t); + ContextHandler.this.restrictEventListener(t); } @Override