FELIX-2394 Do not destroy any filters and servlets still registered with the HttpService when the service is ungotten before the servlets/filters have been unregistered.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1056877 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
index dbc04fb..6e6c503 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
@@ -80,22 +80,28 @@
updateFilterArray();
}
- public synchronized void removeServlet(Servlet servlet)
+ public synchronized void removeServlet(Servlet servlet, final boolean destroy)
{
ServletHandler handler = this.servletMap.remove(servlet);
if (handler != null) {
updateServletArray();
this.aliasMap.remove(handler.getAlias());
- handler.destroy();
+ if (destroy)
+ {
+ handler.destroy();
+ }
}
}
- public synchronized void removeFilter(Filter filter)
+ public synchronized void removeFilter(Filter filter, final boolean destroy)
{
FilterHandler handler = this.filterMap.remove(filter);
if (handler != null) {
updateFilterArray();
- handler.destroy();
+ if (destroy)
+ {
+ handler.destroy();
+ }
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
index fa7954d..60e069b 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
@@ -71,18 +71,12 @@
public void unregisterFilter(Filter filter)
{
- if (filter != null) {
- this.handlerRegistry.removeFilter(filter);
- this.localFilters.remove(filter);
- }
+ unregisterFilter(filter, true);
}
public void unregisterServlet(Servlet servlet)
{
- if (servlet != null) {
- this.handlerRegistry.removeServlet(servlet);
- this.localServlets.remove(servlet);
- }
+ unregisterServlet(servlet, true);
}
public void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext context)
@@ -129,12 +123,28 @@
{
HashSet<Servlet> servlets = new HashSet<Servlet>(this.localServlets);
for (Servlet servlet : servlets) {
- unregisterServlet(servlet);
+ unregisterServlet(servlet, false);
}
HashSet<Filter> filters = new HashSet<Filter>(this.localFilters);
for (Filter fiter : filters) {
- unregisterFilter(fiter);
+ unregisterFilter(fiter, false);
+ }
+ }
+
+ private void unregisterFilter(Filter filter, final boolean destroy)
+ {
+ if (filter != null) {
+ this.handlerRegistry.removeFilter(filter, destroy);
+ this.localFilters.remove(filter);
+ }
+ }
+
+ private void unregisterServlet(Servlet servlet, final boolean destroy)
+ {
+ if (servlet != null) {
+ this.handlerRegistry.removeServlet(servlet, destroy);
+ this.localServlets.remove(servlet);
}
}