Remove special sorting for context handlers
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1682171 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
index bd8fe42..6855fd8 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
@@ -60,6 +60,15 @@
public ServletHandler handler;
}
+/*
+ public static final class RegistrationStatus
+ {
+ public ServletHandler handler;
+ public Map<Integer, String[]> statusToPath = new HashMap<Integer, String[]>();
+ }
+
+ public volatile Map<ServletInfo, RegistrationStatus> mapping = Collections.emptyMap();
+*/
/**
* Resolve a request uri
*
@@ -359,11 +368,6 @@
}
}
- Map<ServletInfo, ServletRegistrationStatus> getServletStatusMapping()
- {
- return this.statusMapping;
- }
-
public ServletHandler resolveByName(final @Nonnull String name)
{
final List<ServletHandler> handlerList = this.servletsByName.get(name);
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
index 30400a6..6bdca22 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardContextHandler.java
@@ -27,17 +27,21 @@
import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.service.HttpServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceObjects;
import org.osgi.service.http.context.ServletContextHelper;
+/**
+ * The whiteboard context handler provides some information and functionality for
+ * handling servlet context (helpers).
+ */
public class WhiteboardContextHandler implements Comparable<WhiteboardContextHandler>
{
/** The info object for the context. */
private final ServletContextHelperInfo info;
+ /** The web context. */
private final ServletContext webContext;
/** The http bundle. */
@@ -46,45 +50,34 @@
/** A map of all created servlet contexts. Each bundle gets it's own instance. */
private final Map<Long, ContextHolder> perBundleContextMap = new HashMap<Long, ContextHolder>();
+ /** The corresponding handler registry. */
private volatile PerContextHandlerRegistry registry;
/** The shared part of the servlet context. */
private volatile ServletContext sharedContext;
- public WhiteboardContextHandler(final ServletContextHelperInfo info,
- final ServletContext webContext,
- final Bundle httpBundle)
+ public WhiteboardContextHandler(@Nonnull final ServletContextHelperInfo info,
+ @Nonnull final ServletContext webContext,
+ @Nonnull final Bundle httpBundle)
{
this.webContext = webContext;
this.info = info;
this.httpBundle = httpBundle;
}
- public BundleContext getBundleContext()
+ public @Nonnull BundleContext getBundleContext()
{
return this.httpBundle.getBundleContext();
}
- public ServletContextHelperInfo getContextInfo()
+ public @Nonnull ServletContextHelperInfo getContextInfo()
{
return this.info;
}
@Override
- public int compareTo(final WhiteboardContextHandler o)
+ public int compareTo(@Nonnull final WhiteboardContextHandler o)
{
- if ( this.info.getName().equals(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME) )
- {
- if ( o.info.getName().equals(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME) )
- {
- return 0;
- }
- return -1;
- }
- if ( o.info.getName().equals(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME) )
- {
- return 1;
- }
return this.info.compareTo(o.getContextInfo());
}
@@ -92,7 +85,7 @@
* Activate this context.
* @return {@code true} if it succeeded.
*/
- public boolean activate(final HandlerRegistry registry)
+ public boolean activate(@Nonnull final HandlerRegistry registry)
{
this.registry = new PerContextHandlerRegistry(this.info);
this.sharedContext = new SharedServletContextImpl(webContext,
@@ -116,7 +109,7 @@
/**
* Deactivate this context.
*/
- public void deactivate(final HandlerRegistry registry)
+ public void deactivate(@Nonnull final HandlerRegistry registry)
{
registry.remove(this.info);
this.registry = null;
@@ -125,12 +118,12 @@
this.perBundleContextMap.clear();
}
- public ServletContext getSharedContext()
+ public @CheckForNull ServletContext getSharedContext()
{
return sharedContext;
}
- public ExtServletContext getServletContext(@CheckForNull final Bundle bundle)
+ public @CheckForNull ExtServletContext getServletContext(@CheckForNull final Bundle bundle)
{
if ( bundle == null )
{
@@ -195,7 +188,7 @@
}
}
- public PerContextHandlerRegistry getRegistry()
+ public @CheckForNull PerContextHandlerRegistry getRegistry()
{
return this.registry;
}
diff --git a/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java b/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
index e1654f3..a158c7a 100644
--- a/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
+++ b/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
@@ -26,8 +26,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.Map;
-
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -44,7 +42,6 @@
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.runtime.dto.DTOConstants;
import org.osgi.service.http.runtime.dto.FailedServletDTO;
import org.osgi.service.http.runtime.dto.ServletContextDTO;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
@@ -74,10 +71,7 @@
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
- final Map<ServletInfo, ServletRegistry.ServletRegistrationStatus> status = reg.getServletStatusMapping();
// empty reg
- assertEquals(0, status.size());
- // check DTO
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
@@ -88,12 +82,6 @@
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
// one entry in reg
- assertEquals(1, status.size());
- assertNotNull(status.get(h1.getServletInfo()));
- assertNotNull(status.get(h1.getServletInfo()).pathToStatus.get("/foo"));
- final int code = status.get(h1.getServletInfo()).pathToStatus.get("/foo");
- assertEquals(-1, code);
-
// check DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
@@ -111,8 +99,6 @@
verify(s).destroy();
// empty again
- assertEquals(0, status.size());
- // check DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
@@ -123,10 +109,7 @@
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
- final Map<ServletInfo, ServletRegistry.ServletRegistrationStatus> status = reg.getServletStatusMapping();
// empty reg
- assertEquals(0, status.size());
- // check DTO
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
@@ -141,21 +124,8 @@
verify(h1.getServlet(), never()).destroy();
// two entries in reg
- assertEquals(2, status.size());
- assertNotNull(status.get(h1.getServletInfo()));
- assertNotNull(status.get(h2.getServletInfo()));
-
// h1 is active
- assertNotNull(status.get(h1.getServletInfo()).pathToStatus.get("/foo"));
- final int code1 = status.get(h1.getServletInfo()).pathToStatus.get("/foo");
- assertEquals(-1, code1);
-
// h2 is hidden
- assertNotNull(status.get(h2.getServletInfo()).pathToStatus.get("/foo"));
- final int code2 = status.get(h2.getServletInfo()).pathToStatus.get("/foo");
- assertEquals(DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, code2);
-
- // check DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertNull(dto.resourceDTOs);
@@ -179,12 +149,6 @@
verify(h2.getServlet()).init(Matchers.any(ServletConfig.class));
// h2 is active
- assertEquals(1, status.size());
- assertNotNull(status.get(h2.getServletInfo()).pathToStatus.get("/foo"));
- final int code3 = status.get(h2.getServletInfo()).pathToStatus.get("/foo");
- assertEquals(-1, code3);
-
- // check DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertNull(dto.resourceDTOs);
@@ -202,8 +166,6 @@
verify(s2).destroy();
// empty again
- assertEquals(0, status.size());
- // check DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
diff --git a/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceRuntimeTest.java b/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceRuntimeTest.java
index 3c7ab41..b3771c9 100644
--- a/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceRuntimeTest.java
+++ b/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceRuntimeTest.java
@@ -1199,14 +1199,22 @@
assertEquals(3, runtimeDTO.servletContextDTOs.length);
- assertEquals(secondContextId.longValue(), runtimeDTO.servletContextDTOs[1].serviceId);
- assertEquals("test-context", runtimeDTO.servletContextDTOs[1].name);
- assertEquals("/second", runtimeDTO.servletContextDTOs[1].contextPath);
- assertEquals("default", runtimeDTO.servletContextDTOs[2].name);
- assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[0].name);
+ final List<String> names = new ArrayList<String>();
+ for(final ServletContextDTO dto : runtimeDTO.servletContextDTOs)
+ {
+ names.add(dto.name);
+ }
+ final int httpContextIndex = names.indexOf(HTTP_CONTEXT_NAME);
+ final int secondContextIndex = names.indexOf("test-context");
+ final int defaultContextIndex = names.indexOf("default");
+ assertEquals(secondContextId.longValue(), runtimeDTO.servletContextDTOs[secondContextIndex].serviceId);
+ assertEquals("test-context", runtimeDTO.servletContextDTOs[secondContextIndex].name);
+ assertEquals("/second", runtimeDTO.servletContextDTOs[secondContextIndex].contextPath);
+ assertEquals("default", runtimeDTO.servletContextDTOs[defaultContextIndex].name);
+ assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[httpContextIndex].name);
- assertEquals(1, runtimeDTO.servletContextDTOs[1].servletDTOs.length);
- assertEquals("servlet", runtimeDTO.servletContextDTOs[1].servletDTOs[0].name);
+ assertEquals(1, runtimeDTO.servletContextDTOs[secondContextIndex].servletDTOs.length);
+ assertEquals("servlet", runtimeDTO.servletContextDTOs[secondContextIndex].servletDTOs[0].name);
secondContext.unregister();