Catch potential exceptions from serlvet context listener
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1692518 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
index 22c2f43..566cefc 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
@@ -35,6 +35,7 @@
import javax.servlet.http.HttpSessionListener;
import org.apache.felix.http.base.internal.handler.ListenerHandler;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.apache.felix.http.base.internal.runtime.ListenerInfo;
import org.osgi.service.http.runtime.dto.FailedListenerDTO;
import org.osgi.service.http.runtime.dto.ListenerDTO;
@@ -129,7 +130,7 @@
*/
public void removeListeners(@Nonnull final ListenerInfo info)
{
- // each listener map returns the same handler, we just need it once to destory
+ // each listener map returns the same handler, we just need it once to destroy
ListenerHandler handler = null;
if ( info.isListenerType(ServletContextListener.class.getName()))
{
@@ -176,7 +177,7 @@
final ServletContextListener listener = (ServletContextListener)l.getListener();
if ( listener != null )
{
- listener.contextInitialized(new ServletContextEvent(l.getContext()));
+ contextInitialized(l.getListenerInfo(), listener, new ServletContextEvent(l.getContext()));
}
}
}
@@ -187,7 +188,7 @@
final ServletContextListener listener = (ServletContextListener) l.getListener();
if ( listener != null )
{
- listener.contextDestroyed(new ServletContextEvent(l.getContext()));
+ contextDestroyed(l.getListenerInfo(), listener, new ServletContextEvent(l.getContext()));
}
}
}
@@ -336,4 +337,34 @@
dto.listenerDTOs = listenerDTOs.toArray(new ListenerDTO[listenerDTOs.size()]);
}
}
+
+ public static void contextInitialized(
+ @Nonnull final ListenerInfo info,
+ @Nonnull final ServletContextListener listener,
+ @Nonnull final ServletContextEvent event)
+ {
+ try
+ {
+ listener.contextInitialized(event);
+ }
+ catch (final Throwable t)
+ {
+ SystemLogger.error(info.getServiceReference(), "Exception while calling servlet context listener.", t);
+ }
+ }
+
+ public static void contextDestroyed(
+ @Nonnull final ListenerInfo info,
+ @Nonnull final ServletContextListener listener,
+ @Nonnull final ServletContextEvent event)
+ {
+ try
+ {
+ listener.contextDestroyed(event);
+ }
+ catch (final Throwable t)
+ {
+ SystemLogger.error(info.getServiceReference(), "Exception while calling servlet context listener.", t);
+ }
+ }
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
index 1c59355..bab2f82 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
@@ -50,6 +50,7 @@
import org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler;
import org.apache.felix.http.base.internal.handler.WhiteboardServletHandler;
import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.registry.EventListenerRegistry;
import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.runtime.AbstractInfo;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
@@ -588,7 +589,7 @@
final ServletContextListener listener = (ServletContextListener)handler.getListener();
if ( listener != null )
{
- listener.contextInitialized(new ServletContextEvent(handler.getContext()));
+ EventListenerRegistry.contextInitialized(handler.getListenerInfo(), listener, new ServletContextEvent(handler.getContext()));
}
}
}
@@ -633,7 +634,7 @@
final ServletContextListener listener = (ServletContextListener) handler.getListener();
if ( listener != null )
{
- listener.contextDestroyed(new ServletContextEvent(handler.getContext()));
+ EventListenerRegistry.contextDestroyed(handler.getListenerInfo(), listener, new ServletContextEvent(handler.getContext()));
}
}
}