Skip to content

Commit

Permalink
[PAXWEB-946] - Unregistering a servlet/filter from a shared HttpContext
Browse files Browse the repository at this point in the history
leaves the resource available
  • Loading branch information
ANierbeck committed Feb 3, 2016
1 parent d0cf13e commit 21a97fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -17,6 +17,8 @@
*/
package org.ops4j.pax.web.extender.whiteboard.internal.tracker;

import javax.servlet.Servlet;

import org.ops4j.lang.NullArgumentException;
import org.ops4j.pax.web.extender.whiteboard.ExtenderConstants;
import org.ops4j.pax.web.extender.whiteboard.internal.ExtenderContext;
Expand Down Expand Up @@ -201,6 +203,13 @@ public void removedService(final ServiceReference<T> serviceReference,
remove = true;
}
}

T registered = bundleContext.getService(serviceReference);
if (!remove && Servlet.class.isAssignableFrom(registered.getClass())) {
//special case where the removed service is a servlet, all other filters etc. should be stopped now too.
remove = true;
}
bundleContext.ungetService(serviceReference);
}

if (webApplication != null && remove) {
Expand Down
Expand Up @@ -19,6 +19,7 @@
import static org.ops4j.pax.exam.OptionUtils.combine;
import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;

import org.eclipse.jetty.http.HttpStatus;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -103,4 +104,15 @@ public void testStop() throws Exception {

testClient.testWebPath("http://127.0.0.1:8181/sharedContext/", "SimpleServlet: TEST OK");
}

@Test
public void testStopServletBundle() throws Exception {
for (final Bundle b : bundleContext.getBundles()) {
if (SERVLET_BUNDLE.equalsIgnoreCase(b.getSymbolicName())) {
b.stop();
}
}

testClient.testWebPath("http://127.0.0.1:8181/sharedContext/", HttpStatus.NOT_FOUND_404);
}
}

0 comments on commit 21a97fb

Please sign in to comment.