You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2015/05/18 13:07:35 UTC
svn commit: r1679990 - in /felix/trunk/http/base/src:
main/java/org/apache/felix/http/base/internal/
main/java/org/apache/felix/http/base/internal/dispatch/
main/java/org/apache/felix/http/base/internal/handler/
main/java/org/apache/felix/http/base/int...
Author: cziegeler
Date: Mon May 18 11:07:34 2015
New Revision: 1679990
URL: http://svn.apache.org/r1679990
Log:
FELIX-4888 : ServletHandler's are not sorted by longest matching path. Finish error page registry. Start DTO handling (WiP)
Added:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
- copied, changed from r1679975, felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/HandlerRegistryTest.java
- copied, changed from r1679974, felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java
Removed:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/HandlerRegistryRuntime.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRegistryRuntime.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java Mon May 18 11:07:34 2015
@@ -25,8 +25,8 @@ import javax.servlet.http.HttpSessionIdL
import javax.servlet.http.HttpSessionListener;
import org.apache.felix.http.base.internal.dispatch.Dispatcher;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.service.HttpServiceFactory;
import org.apache.felix.http.base.internal.service.listener.ServletContextAttributeListenerManager;
import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java Mon May 18 11:07:34 2015
@@ -52,9 +52,9 @@ import javax.servlet.http.HttpSession;
import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.registry.PathResolution;
import org.apache.felix.http.base.internal.registry.ServletResolution;
import org.apache.felix.http.base.internal.util.UriUtils;
@@ -94,11 +94,11 @@ public final class Dispatcher implements
try
{
ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
- this.resolution.holder.getContext(),
+ this.resolution.handler.getContext(),
this.requestInfo,
DispatcherType.FORWARD,
- this.resolution.holder.getContextServiceId(),
- this.resolution.holder.getServletInfo().isAsyncSupported());
+ this.resolution.handler.getContextServiceId(),
+ this.resolution.handler.getServletInfo().isAsyncSupported());
Dispatcher.this.forward(this.resolution, req, (HttpServletResponse) response);
}
finally
@@ -117,11 +117,11 @@ public final class Dispatcher implements
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
- this.resolution.holder.getContext(),
+ this.resolution.handler.getContext(),
this.requestInfo,
DispatcherType.INCLUDE,
- this.resolution.holder.getContextServiceId(),
- this.resolution.holder.getServletInfo().isAsyncSupported());
+ this.resolution.handler.getContextServiceId(),
+ this.resolution.handler.getServletInfo().isAsyncSupported());
Dispatcher.this.include(this.resolution, req, (HttpServletResponse) response);
}
}
@@ -204,7 +204,7 @@ public final class Dispatcher implements
final FilterHandler[] filterHandlers = handlerRegistry.getFilters(errorResolution, DispatcherType.ERROR, request.getRequestURI());
// TODO - is async = false correct?
- invokeChain(errorResolution.holder, filterHandlers, new ServletRequestWrapper(request, errorResolution.holder.getContext(), requestInfo, this.serviceId, false), this);
+ invokeChain(errorResolution.handler, filterHandlers, new ServletRequestWrapper(request, errorResolution.handler.getContext(), requestInfo, this.serviceId, false), this);
invokeSuper = false;
}
@@ -593,7 +593,7 @@ public final class Dispatcher implements
final PathResolution pr = this.handlerRegistry.resolveServlet(requestURI);
final HttpServletResponse wrappedResponse = new ServletResponseWrapper(req, res,
- pr == null ? null : pr.holder);
+ pr == null ? null : pr.handler);
if ( pr == null )
{
wrappedResponse.sendError(404);
@@ -601,12 +601,12 @@ public final class Dispatcher implements
}
- final ExtServletContext servletContext = pr.holder.getContext();
+ final ExtServletContext servletContext = pr.handler.getContext();
final RequestInfo requestInfo = new RequestInfo(pr.servletPath, pr.pathInfo, null);
final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext, requestInfo,
- pr.holder.getContextServiceId(),
- pr.holder.getServletInfo().isAsyncSupported());
+ pr.handler.getContextServiceId(),
+ pr.handler.getServletInfo().isAsyncSupported());
final FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
try
@@ -615,7 +615,7 @@ public final class Dispatcher implements
{
servletContext.getServletRequestListener().requestInitialized(new ServletRequestEvent(servletContext, wrappedRequest));
}
- invokeChain(pr.holder, filterHandlers, wrappedRequest, wrappedResponse);
+ invokeChain(pr.handler, filterHandlers, wrappedRequest, wrappedResponse);
}
catch ( final Exception e)
{
@@ -683,7 +683,7 @@ public final class Dispatcher implements
String requestURI = getRequestURI(request);
FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(resolution, DispatcherType.FORWARD, requestURI);
- invokeChain(resolution.holder, filterHandlers, request, response);
+ invokeChain(resolution.handler, filterHandlers, request, response);
}
/**
@@ -696,7 +696,7 @@ public final class Dispatcher implements
String requestURI = getRequestURI(request);
FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(resolution, DispatcherType.INCLUDE, requestURI);
- invokeChain(resolution.holder, filterHandlers, request, response);
+ invokeChain(resolution.handler, filterHandlers, request, response);
}
private String getRequestURI(HttpServletRequest req)
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java Mon May 18 11:07:34 2015
@@ -36,6 +36,9 @@ import org.apache.felix.http.base.intern
import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
import org.osgi.service.http.runtime.dto.DTOConstants;
+/**
+ * TODO - check if add/remove needs syncing
+ */
public final class ErrorPageRegistry
{
private static final String CLIENT_ERROR = "4xx";
@@ -87,7 +90,7 @@ public final class ErrorPageRegistry
}
private static final class ErrorRegistrationStatus {
- ServletHandler holder;
+ ServletHandler handler;
final Map<Long, Integer> errorCodeMapping = new ConcurrentHashMap<Long, Integer>();
final Map<String, Integer> exceptionMapping = new ConcurrentHashMap<String, Integer>();
}
@@ -112,38 +115,38 @@ public final class ErrorPageRegistry
/**
* Add the servlet for error handling
- * @param holder The servlet holder.
+ * @param handler The servlet handler.
*/
- public void addServlet(@Nonnull final ServletHandler holder)
+ public void addServlet(@Nonnull final ServletHandler handler)
{
- final ErrorRegistration reg = getErrorRegistration(holder.getServletInfo());
+ final ErrorRegistration reg = getErrorRegistration(handler.getServletInfo());
if ( reg != null )
{
final ErrorRegistrationStatus status = new ErrorRegistrationStatus();
- status.holder = holder;
+ status.handler = handler;
for(final long code : reg.errorCodes)
{
List<ServletHandler> list = errorCodesMap.get(code);
if ( list == null )
{
// activate
- if ( tryToActivate(code, holder, status) )
+ if ( tryToActivate(code, handler, status) )
{
final List<ServletHandler> newList = new ArrayList<ServletHandler>(1);
- newList.add(holder);
+ newList.add(handler);
errorCodesMap.put(code, newList);
}
}
else
{
final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
- newList.add(holder);
+ newList.add(handler);
Collections.sort(newList);
- if ( newList.get(0) == holder )
+ if ( newList.get(0) == handler )
{
// activate and reactive
- if ( tryToActivate(code, holder, status) )
+ if ( tryToActivate(code, handler, status) )
{
final ServletHandler old = list.get(0);
old.destroy();
@@ -164,23 +167,23 @@ public final class ErrorPageRegistry
if ( list == null )
{
// activate
- if ( tryToActivate(exception, holder, status) )
+ if ( tryToActivate(exception, handler, status) )
{
final List<ServletHandler> newList = new ArrayList<ServletHandler>(1);
- newList.add(holder);
+ newList.add(handler);
exceptionsMap.put(exception, newList);
}
}
else
{
final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
- newList.add(holder);
+ newList.add(handler);
Collections.sort(newList);
- if ( newList.get(0) == holder )
+ if ( newList.get(0) == handler )
{
// activate and reactive
- if ( tryToActivate(exception, holder, status) )
+ if ( tryToActivate(exception, handler, status) )
{
final ServletHandler old = list.get(0);
old.destroy();
@@ -195,7 +198,7 @@ public final class ErrorPageRegistry
}
}
}
- this.statusMapping.put(holder.getServletInfo(), status);
+ this.statusMapping.put(handler.getServletInfo(), status);
}
}
@@ -218,13 +221,13 @@ public final class ErrorPageRegistry
final Iterator<ServletHandler> i = list.iterator();
while ( i.hasNext() )
{
- final ServletHandler holder = i.next();
- if ( holder.getServletInfo().equals(info) )
+ final ServletHandler handler = i.next();
+ if ( handler.getServletInfo().equals(info) )
{
- holder.destroy();
+ handler.destroy();
final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
- newList.remove(holder);
+ newList.remove(handler);
if ( index == 0 )
{
@@ -266,13 +269,13 @@ public final class ErrorPageRegistry
final Iterator<ServletHandler> i = list.iterator();
while ( i.hasNext() )
{
- final ServletHandler holder = i.next();
- if ( holder.getServletInfo().equals(info) )
+ final ServletHandler handler = i.next();
+ if ( handler.getServletInfo().equals(info) )
{
- holder.destroy();
+ handler.destroy();
final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
- newList.remove(holder);
+ newList.remove(handler);
if ( index == 0 )
{
@@ -364,19 +367,19 @@ public final class ErrorPageRegistry
return servletHandler;
}
- private boolean tryToActivate(final Long code, final ServletHandler holder, final ErrorRegistrationStatus status)
+ private boolean tryToActivate(final Long code, final ServletHandler handler, final ErrorRegistrationStatus status)
{
// add to active
- final int result = holder.init();
+ final int result = handler.init();
status.errorCodeMapping.put(code, result);
return result == -1;
}
- private boolean tryToActivate(final String exception, final ServletHandler holder, final ErrorRegistrationStatus status)
+ private boolean tryToActivate(final String exception, final ServletHandler handler, final ErrorRegistrationStatus status)
{
// add to active
- final int result = holder.init();
+ final int result = handler.init();
status.exceptionMapping.put(exception, result);
return result == -1;
@@ -418,7 +421,7 @@ public final class ErrorPageRegistry
}
if ( !activeCodes.isEmpty() || !activeExceptions.isEmpty() )
{
- errorPages.add(new ErrorPageRuntime(status.holder, activeCodes, activeExceptions));
+ errorPages.add(new ErrorPageRuntime(status.handler, activeCodes, activeExceptions));
}
if ( !inactiveCodes.isEmpty() || !inactiveExceptions.isEmpty() )
{
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java Mon May 18 11:07:34 2015
@@ -35,6 +35,9 @@ import org.apache.felix.http.base.intern
import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
+/**
+ * TODO - check if add/remove needs syncing
+ */
public final class FilterRegistry
{
private volatile HandlerMapping filterMapping = new HandlerMapping();
@@ -44,21 +47,21 @@ public final class FilterRegistry
private static final class FilterRegistrationStatus
{
public int result;
- public FilterHandler holder;
+ public FilterHandler handler;
}
- public void addFilter(@Nonnull final FilterHandler holder)
+ public void addFilter(@Nonnull final FilterHandler handler)
{
- final int result = holder.init();
+ final int result = handler.init();
if ( result == -1 )
{
- this.filterMapping = this.filterMapping.add(holder);
+ this.filterMapping = this.filterMapping.add(handler);
}
final FilterRegistrationStatus status = new FilterRegistrationStatus();
status.result = result;
- status.holder = holder;
+ status.handler = handler;
- statusMapping.put(holder.getFilterInfo(), status);
+ statusMapping.put(handler.getFilterInfo(), status);
}
public void removeFilter(@Nonnull final FilterInfo filterInfo, final boolean destroy)
@@ -68,16 +71,16 @@ public final class FilterRegistry
{
if ( status.result == -1 )
{
- this.filterMapping = this.filterMapping.remove(status.holder);
+ this.filterMapping = this.filterMapping.remove(status.handler);
if (destroy)
{
- status.holder.dispose();
+ status.handler.dispose();
}
}
}
}
- public FilterHandler[] getFilterHandlers(@CheckForNull final ServletHandler holder,
+ public FilterHandler[] getFilterHandlers(@CheckForNull final ServletHandler handler,
@CheckForNull DispatcherType dispatcherType,
@Nonnull String requestURI)
{
@@ -95,7 +98,7 @@ public final class FilterRegistry
}
}
- final String servletName = (holder != null) ? holder.getName() : null;
+ final String servletName = (handler != null) ? handler.getName() : null;
// TODO this is not the most efficient/fastest way of doing this...
for (FilterHandler filterHandler : this.filterMapping.values())
{
@@ -108,13 +111,13 @@ public final class FilterRegistry
return result.toArray(new FilterHandler[result.size()]);
}
- private boolean referencesDispatcherType(FilterHandler holder, DispatcherType dispatcherType)
+ private boolean referencesDispatcherType(FilterHandler handler, DispatcherType dispatcherType)
{
if (dispatcherType == null)
{
return true;
}
- return Arrays.asList(holder.getFilterInfo().getDispatcher()).contains(dispatcherType);
+ return Arrays.asList(handler.getFilterInfo().getDispatcher()).contains(dispatcherType);
}
private boolean referencesServletByName(FilterHandler handler, String servletName)
Copied: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java (from r1679975, felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java)
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java?p2=felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java&p1=felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java&r1=1679975&r2=1679990&rev=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java Mon May 18 11:07:34 2015
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.felix.http.base.internal.handler;
+package org.apache.felix.http.base.internal.registry;
import java.util.ArrayList;
import java.util.Collections;
@@ -24,15 +24,13 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.servlet.DispatcherType;
-import org.apache.felix.http.base.internal.registry.PathResolution;
-import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
-import org.apache.felix.http.base.internal.registry.ServletResolution;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.apache.felix.http.base.internal.runtime.dto.ContextRuntime;
import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
-import org.apache.felix.http.base.internal.runtime.dto.HandlerRegistryRuntime;
/**
* Registry for all services.
@@ -42,7 +40,7 @@ import org.apache.felix.http.base.intern
*/
public final class HandlerRegistry
{
- private static FilterHandler[] EMPTY_FILTER_HOLDER = new FilterHandler[0];
+ private static FilterHandler[] EMPTY_FILTER_HANDLER = new FilterHandler[0];
/** Current list of context registrations. */
private volatile List<PerContextHandlerRegistry> registrations = Collections.emptyList();
@@ -126,14 +124,14 @@ public final class HandlerRegistry
}
}
- public void addFilter(@Nonnull final FilterHandler holder)
+ public void addFilter(@Nonnull final FilterHandler handler)
{
- final PerContextHandlerRegistry reg = this.getRegistry(holder.getContextServiceId());
+ final PerContextHandlerRegistry reg = this.getRegistry(handler.getContextServiceId());
// TODO - check whether we need to handle the null case as well
// it shouldn't be required as we only get here if the context exists
if ( reg != null )
{
- reg.addFilter(holder);
+ reg.addFilter(handler);
}
}
@@ -186,11 +184,11 @@ public final class HandlerRegistry
}
if ( reg != null )
{
- final ServletHandler holder = reg.getErrorHandler(code, exception);
- if ( holder != null )
+ final ServletHandler handler = reg.getErrorHandler(code, exception);
+ if ( handler != null )
{
final ServletResolution res = new ServletResolution();
- res.holder = holder;
+ res.handler = handler;
res.handlerRegistry = reg;
return res;
@@ -205,19 +203,19 @@ public final class HandlerRegistry
{
if ( pr != null && pr.handlerRegistry != null )
{
- return pr.handlerRegistry.getFilterHandlers(pr.holder, dispatcherType, requestURI);
+ return pr.handlerRegistry.getFilterHandlers(pr.handler, dispatcherType, requestURI);
}
- return EMPTY_FILTER_HOLDER;
+ return EMPTY_FILTER_HANDLER;
}
- public void addServlet(final ServletHandler holder)
+ public void addServlet(final ServletHandler handler)
{
- final PerContextHandlerRegistry reg = this.getRegistry(holder.getContextServiceId());
+ final PerContextHandlerRegistry reg = this.getRegistry(handler.getContextServiceId());
// TODO - check whether we need to handle the null case as well
// it shouldn't be required as we only get here if the context exists
if ( reg != null )
{
- reg.addServlet(holder);
+ reg.addServlet(handler);
}
}
@@ -256,21 +254,21 @@ public final class HandlerRegistry
}
/**
- * Get the servlet holder for a servlet by name
+ * Get the servlet handler for a servlet by name
* @param contextId The context id or {@code null}
* @param name The servlet name
- * @return The servlet holder or {@code null}
+ * @return The servlet handler or {@code null}
*/
public ServletResolution resolveServletByName(final Long contextId, @Nonnull final String name)
{
final PerContextHandlerRegistry reg = (contextId == null ? null : this.getRegistry(contextId));
if ( reg != null )
{
- final ServletHandler holder = reg.resolveServletByName(name);
- if ( holder != null )
+ final ServletHandler handler = reg.resolveServletByName(name);
+ if ( handler != null )
{
final ServletResolution resolution = new ServletResolution();
- resolution.holder = holder;
+ resolution.handler = handler;
resolution.handlerRegistry = reg;
return resolution;
@@ -279,7 +277,7 @@ public final class HandlerRegistry
return null;
}
- public HandlerRegistryRuntime getRuntime(FailureRuntime.Builder failureRuntimeBuilder)
+ public List<ContextRuntime> getRuntime(FailureRuntime.Builder failureRuntimeBuilder)
{
final List<ContextRuntime> handlerRuntimes = new ArrayList<ContextRuntime>();
@@ -289,6 +287,6 @@ public final class HandlerRegistry
handlerRuntimes.add(contextRegistry.getRuntime(failureRuntimeBuilder));
}
- return new HandlerRegistryRuntime(handlerRuntimes);
+ return handlerRuntimes;
}
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java Mon May 18 11:07:34 2015
@@ -145,13 +145,12 @@ public final class PerContextHandlerRegi
/**
* Add a servlet
- * @param holder The servlet holder
- * @param info The servlet info
+ * @param handler The servlet handler
*/
- public void addServlet(@Nonnull final ServletHandler holder)
+ public void addServlet(@Nonnull final ServletHandler handler)
{
- this.servletRegistry.addServlet(holder);
- this.errorPageRegistry.addServlet(holder);
+ this.servletRegistry.addServlet(handler);
+ this.errorPageRegistry.addServlet(handler);
}
/**
@@ -164,9 +163,9 @@ public final class PerContextHandlerRegi
this.errorPageRegistry.removeServlet(info, destroy);
}
- public void addFilter(@Nonnull final FilterHandler holder)
+ public void addFilter(@Nonnull final FilterHandler handler)
{
- this.filterRegistry.addFilter(holder);
+ this.filterRegistry.addFilter(handler);
}
public void removeFilter(@Nonnull final FilterInfo info, final boolean destroy)
@@ -185,12 +184,14 @@ public final class PerContextHandlerRegi
return this.errorPageRegistry.get(exception, code);
}
- public synchronized ContextRuntime getRuntime(final FailureRuntime.Builder failureRuntimeBuilder)
+ public ContextRuntime getRuntime(final FailureRuntime.Builder failureRuntimeBuilder)
{
// TODO - add servlets
// TODO - add failures from filters and error pages
return new ContextRuntime(this.filterRegistry.getFilterRuntimes(failureRuntimeBuilder),
this.errorPageRegistry.getErrorPageRuntimes(),
- null, this.serviceId);
+ null,
+ null,
+ this.serviceId);
}
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistration.java Mon May 18 11:07:34 2015
@@ -25,7 +25,7 @@ import org.apache.felix.http.base.intern
import org.apache.felix.http.base.internal.util.UriUtils;
/**
- * Servlet handler is registered with a pattern and a servlet holder
+ * Servlet is registered with a pattern and a servlet handler
*/
public class ServletRegistration
{
@@ -51,7 +51,7 @@ public class ServletRegistration
final PathResolution pr = new PathResolution();
pr.servletPath = matcher.groupCount() > 0 ? matcher.group(1) : matcher.group();
pr.pathInfo = UriUtils.compactPath(UriUtils.relativePath(pr.servletPath, requestURI));
- pr.holder = this.handler;
+ pr.handler = this.handler;
return pr;
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java Mon May 18 11:07:34 2015
@@ -39,6 +39,10 @@ import org.osgi.service.http.runtime.dto
* TODO - servlet name handling
*
* TODO - sort active servlet mappings by pattern length, longest first (avoids looping over all)
+ *
+ * TODO - check if add/remove needs syncing
+ *
+ * TODO - replace patterns with own matchers
*/
public final class ServletRegistry
{
@@ -53,17 +57,17 @@ public final class ServletRegistry
private static final class ServletNameStatus implements Comparable<ServletNameStatus>
{
public volatile boolean isActive = false;
- public final ServletHandler holder;
+ public final ServletHandler handler;
public ServletNameStatus(final ServletHandler h)
{
- this.holder = h;
+ this.handler = h;
}
@Override
public int compareTo(final ServletNameStatus o)
{
- return holder.compareTo(o.holder);
+ return handler.compareTo(o.handler);
}
}
@@ -91,25 +95,25 @@ public final class ServletRegistry
/**
* Add a servlet.
*
- * @param holder The servlet holder
+ * @param handler The servlet handler
*/
- public void addServlet(@Nonnull final ServletHandler holder)
+ public void addServlet(@Nonnull final ServletHandler handler)
{
// we have to check for every pattern in the info
// Can be null in case of error-handling servlets...
- if ( holder.getServletInfo().getPatterns() != null )
+ if ( handler.getServletInfo().getPatterns() != null )
{
final ServletRegistrationStatus status = new ServletRegistrationStatus();
- for(final String pattern : holder.getServletInfo().getPatterns())
+ for(final String pattern : handler.getServletInfo().getPatterns())
{
final ServletRegistration regHandler = this.activeServletMappings.get(pattern);
if ( regHandler != null )
{
- if ( regHandler.getServletHandler().getServletInfo().getServiceReference().compareTo(holder.getServletInfo().getServiceReference()) < 0 )
+ if ( regHandler.getServletHandler().getServletInfo().getServiceReference().compareTo(handler.getServletInfo().getServiceReference()) < 0 )
{
// replace if no error with new servlet
- if ( this.tryToActivate(pattern, holder, status) )
+ if ( this.tryToActivate(pattern, handler, status) )
{
// nameStatus.isActive = true;
regHandler.getServletHandler().destroy();
@@ -120,19 +124,19 @@ public final class ServletRegistry
else
{
// add to inactive
- this.addToInactiveList(pattern, holder, status);
+ this.addToInactiveList(pattern, handler, status);
}
}
else
{
// add to active
- if ( this.tryToActivate(pattern, holder, status) )
+ if ( this.tryToActivate(pattern, handler, status) )
{
// nameStatus.isActive = true;
}
}
}
- this.statusMapping.put(holder.getServletInfo(), status);
+ this.statusMapping.put(handler.getServletInfo(), status);
}
}
@@ -145,7 +149,7 @@ public final class ServletRegistry
if ( info.getPatterns() != null )
{
this.statusMapping.remove(info);
- ServletHandler cleanupHolder = null;
+ ServletHandler cleanuphandler = null;
for(final String pattern : info.getPatterns())
{
@@ -153,7 +157,7 @@ public final class ServletRegistry
final ServletRegistration regHandler = this.activeServletMappings.get(pattern);
if ( regHandler != null && regHandler.getServletHandler().getServletInfo().equals(info) )
{
- cleanupHolder = regHandler.getServletHandler();
+ cleanuphandler = regHandler.getServletHandler();
final List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
if ( inactiveList == null )
{
@@ -189,7 +193,7 @@ public final class ServletRegistry
if ( h.getServletInfo().equals(info) )
{
i.remove();
- cleanupHolder = h;
+ cleanuphandler = h;
break;
}
}
@@ -201,14 +205,14 @@ public final class ServletRegistry
}
}
- if ( cleanupHolder != null )
+ if ( cleanuphandler != null )
{
- cleanupHolder.dispose();
+ cleanuphandler.dispose();
}
}
}
- private void addToInactiveList(final String pattern, final ServletHandler holder, final ServletRegistrationStatus status)
+ private void addToInactiveList(final String pattern, final ServletHandler handler, final ServletRegistrationStatus status)
{
List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
if ( inactiveList == null )
@@ -216,20 +220,20 @@ public final class ServletRegistry
inactiveList = new ArrayList<ServletHandler>();
this.inactiveServletMappings.put(pattern, inactiveList);
}
- inactiveList.add(holder);
+ inactiveList.add(handler);
Collections.sort(inactiveList);
status.pathToStatus.put(pattern, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
}
- private boolean tryToActivate(final String pattern, final ServletHandler holder, final ServletRegistrationStatus status)
+ private boolean tryToActivate(final String pattern, final ServletHandler handler, final ServletRegistrationStatus status)
{
// add to active
- final int result = holder.init();
+ final int result = handler.init();
if ( result == -1 )
{
final Pattern p = Pattern.compile(PatternUtil.convertToRegEx(pattern));
- final ServletRegistration handler = new ServletRegistration(holder, p);
- this.activeServletMappings.put(pattern, handler);
+ final ServletRegistration reg = new ServletRegistration(handler, p);
+ this.activeServletMappings.put(pattern, reg);
// add ok
status.pathToStatus.put(pattern, result);
@@ -250,13 +254,13 @@ public final class ServletRegistry
public ServletHandler resolveByName(@Nonnull String name)
{
- final List<ServletNameStatus> holderList = this.servletsByName.get(name);
- if ( holderList != null )
+ final List<ServletNameStatus> handlerList = this.servletsByName.get(name);
+ if ( handlerList != null )
{
- final ServletNameStatus status = holderList.get(0);
+ final ServletNameStatus status = handlerList.get(0);
if ( status != null && status.isActive )
{
- return status.holder;
+ return status.handler;
}
}
return null;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java Mon May 18 11:07:34 2015
@@ -20,7 +20,7 @@ import org.apache.felix.http.base.intern
public class ServletResolution {
- public ServletHandler holder;
+ public ServletHandler handler;
public PerContextHandlerRegistry handlerRegistry;
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java Mon May 18 11:07:34 2015
@@ -26,27 +26,42 @@ public final class ContextRuntime
private final Collection<FilterRuntime> filterRuntimes;
private final Collection<ErrorPageRuntime> errorPageRuntimes;
private final long serviceId;
- private final ServletRegistryRuntime servletRegistryRuntime;
+ private final Collection<ServletRuntime> servletRuntimes;
+ private final Collection<ServletRuntime> resourceRuntimes;
+
public ContextRuntime(Collection<FilterRuntime> filterRuntimes,
Collection<ErrorPageRuntime> errorPageRuntimes,
- final ServletRegistryRuntime servletRegistryRuntime,
+ Collection<ServletRuntime> servletRuntimes,
+ Collection<ServletRuntime> resourceRuntimes,
long serviceId)
{
this.filterRuntimes = filterRuntimes;
this.errorPageRuntimes = errorPageRuntimes;
- this.servletRegistryRuntime = servletRegistryRuntime;
this.serviceId = serviceId;
+ this.servletRuntimes = servletRuntimes;
+ this.resourceRuntimes = resourceRuntimes;
}
public static ContextRuntime empty(long serviceId)
{
return new ContextRuntime(Collections.<FilterRuntime>emptyList(),
Collections.<ErrorPageRuntime> emptyList(),
- null,
+ Collections.<ServletRuntime> emptyList(),
+ Collections.<ServletRuntime> emptyList(),
serviceId);
}
+ Collection<ServletRuntime> getServletRuntimes()
+ {
+ return servletRuntimes;
+ }
+
+ Collection<ServletRuntime> getResourceRuntimes()
+ {
+ return resourceRuntimes;
+ }
+
Collection<FilterRuntime> getFilterRuntimes()
{
return filterRuntimes;
@@ -57,12 +72,7 @@ public final class ContextRuntime
return errorPageRuntimes;
}
- ServletRegistryRuntime getServletRegistryRuntime()
- {
- return this.servletRegistryRuntime;
- }
-
- long getServiceId()
+ public long getServiceId()
{
return serviceId;
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java Mon May 18 11:07:34 2015
@@ -19,7 +19,7 @@ package org.apache.felix.http.base.inter
import static java.util.Arrays.asList;
import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.registry.PathResolution;
import org.osgi.service.http.runtime.dto.FilterDTO;
import org.osgi.service.http.runtime.dto.RequestInfoDTO;
@@ -49,21 +49,21 @@ public final class RequestInfoDTOBuilder
requestInfoDTO.filterDTOs = FILTER_DTO_ARRAY;
return requestInfoDTO;
}
- requestInfoDTO.servletContextId = pr.holder.getContextServiceId();
- if (pr.holder.getServletInfo().isResource())
+ requestInfoDTO.servletContextId = pr.handler.getContextServiceId();
+ if (pr.handler.getServletInfo().isResource())
{
requestInfoDTO.resourceDTO = ResourceDTOBuilder.create()
- .buildDTO(pr.holder, pr.holder.getContextServiceId());
+ .buildDTO(pr.handler, pr.handler.getContextServiceId());
}
else
{
requestInfoDTO.servletDTO = ServletDTOBuilder.create()
- .buildDTO(pr.holder, pr.holder.getContextServiceId());
+ .buildDTO(pr.handler, pr.handler.getContextServiceId());
}
final FilterHandler[] filterHandlers = registry.getFilters(pr, null, path);
requestInfoDTO.filterDTOs = FilterDTOBuilder.create()
- .build(asList(filterHandlers), pr.holder.getContextServiceId())
+ .build(asList(filterHandlers), pr.handler.getContextServiceId())
.toArray(FILTER_DTO_ARRAY);
return requestInfoDTO;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java Mon May 18 11:07:34 2015
@@ -23,7 +23,7 @@ import javax.servlet.http.HttpSessionAtt
import javax.servlet.http.HttpSessionListener;
import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.service.listener.HttpSessionAttributeListenerManager;
import org.apache.felix.http.base.internal.service.listener.HttpSessionListenerManager;
import org.apache.felix.http.base.internal.service.listener.ServletContextAttributeListenerManager;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java Mon May 18 11:07:34 2015
@@ -21,7 +21,7 @@ import static java.util.Collections.list
import java.util.Dictionary;
import java.util.Hashtable;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.runtime.dto.RegistryRuntime;
import org.apache.felix.http.base.internal.runtime.dto.RequestInfoDTOBuilder;
import org.apache.felix.http.base.internal.runtime.dto.RuntimeDTOBuilder;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/SharedHttpServiceImpl.java Mon May 18 11:07:34 2015
@@ -26,9 +26,9 @@ import javax.servlet.ServletException;
import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.osgi.service.http.NamespaceException;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java Mon May 18 11:07:34 2015
@@ -19,11 +19,11 @@ package org.apache.felix.http.base.inter
import javax.annotation.Nonnull;
import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
import org.apache.felix.http.base.internal.handler.ServletHandler;
import org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler;
import org.apache.felix.http.base.internal.handler.WhiteboardServletHandler;
+import org.apache.felix.http.base.internal.registry.HandlerRegistry;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ResourceInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java Mon May 18 11:07:34 2015
@@ -43,9 +43,9 @@ import javax.servlet.http.HttpSessionEve
import org.apache.felix.http.base.internal.console.HttpServicePlugin;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
import org.apache.felix.http.base.internal.logger.SystemLogger;
+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;
import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
@@ -59,8 +59,8 @@ import org.apache.felix.http.base.intern
import org.apache.felix.http.base.internal.runtime.ServletRequestAttributeListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletRequestListenerInfo;
import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
+import org.apache.felix.http.base.internal.runtime.dto.ContextRuntime;
import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
-import org.apache.felix.http.base.internal.runtime.dto.HandlerRegistryRuntime;
import org.apache.felix.http.base.internal.runtime.dto.InfoServletContextHelperRuntime;
import org.apache.felix.http.base.internal.runtime.dto.RegistryRuntime;
import org.apache.felix.http.base.internal.runtime.dto.ServletContextHelperRuntime;
@@ -747,7 +747,7 @@ public final class WhiteboardManager
public RegistryRuntime getRuntime(HandlerRegistry registry)
{
final Collection<ServletContextHelperRuntime> contextRuntimes = new TreeSet<ServletContextHelperRuntime>(ServletContextHelperRuntime.COMPARATOR);
- HandlerRegistryRuntime handlerRuntimes;
+ List<ContextRuntime> handlerRuntimes;
final Map<Long, Collection<ServiceReference<?>>> listenerRuntimes = new HashMap<Long, Collection<ServiceReference<?>>>();
final FailureRuntime.Builder failureRuntime = FailureRuntime.builder();
synchronized ( this.contextMap )
@@ -772,7 +772,7 @@ public final class WhiteboardManager
}
return new RegistryRuntime(contextRuntimes,
- handlerRuntimes.getContextRuntimes(),
+ handlerRuntimes,
listenerRuntimes,
failureRuntime.build());
}
Copied: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/HandlerRegistryTest.java (from r1679974, felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/HandlerRegistryTest.java?p2=felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/HandlerRegistryTest.java&p1=felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java&r1=1679974&r2=1679990&rev=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/HandlerRegistryTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/HandlerRegistryTest.java Mon May 18 11:07:34 2015
@@ -14,11 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.felix.http.base.internal.handler;
+package org.apache.felix.http.base.internal.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.felix.http.base.internal.runtime.dto.ContextRuntime;
+import org.junit.Test;
public class HandlerRegistryTest
{
+ private final HandlerRegistry registry = new HandlerRegistry();
+
+ @Test public void testInitialSetup()
+ {
+ List<ContextRuntime> runtimes = registry.getRuntime(null);
+ assertNotNull(runtimes);
+ assertTrue(runtimes.isEmpty());
+
+ registry.init();
+
+ runtimes = registry.getRuntime(null);
+ assertNotNull(runtimes);
+ assertFalse(runtimes.isEmpty());
+ assertEquals(1, runtimes.size());
+
+ final ContextRuntime cr = runtimes.get(0);
+
+ assertEquals(0, cr.getServiceId());
+
+ registry.shutdown();
+ runtimes = registry.getRuntime(null);
+ assertNotNull(runtimes);
+ assertTrue(runtimes.isEmpty());
+ }
/*
@Test
public void testAddRemoveServlet() throws Exception
Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java?rev=1679990&r1=1679989&r2=1679990&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java Mon May 18 11:07:34 2015
@@ -243,13 +243,13 @@ public class RuntimeDTOBuilderTest
resources.add(createTestServlet("1", context_0, ID_0));
List<FilterRuntime> filters_0 = asList(createTestFilter("1", context_0));
List<ErrorPageRuntime> errorPages_0 = asList(createErrorPage("E_1", context_0, ID_0));
- ContextRuntime contextRuntime_0 = new ContextRuntime(filters_0, errorPages_0, null, ID_0);
+ ContextRuntime contextRuntime_0 = new ContextRuntime(filters_0, errorPages_0, null, null, ID_0);
servlets.add(createTestServlet("A_1", context_A, ID_A));
resources.add(createTestServlet("A_1", context_A, ID_A));
List<FilterRuntime> filters_A = asList(createTestFilter("A_1", context_A));
List<ErrorPageRuntime> errorPages_A = asList(createErrorPage("E_A_1", context_A, ID_A));
- ContextRuntime contextRuntime_A = new ContextRuntime(filters_A, errorPages_A, null, ID_A);
+ ContextRuntime contextRuntime_A = new ContextRuntime(filters_A, errorPages_A, null, null, ID_A);
servlets.addAll(asList(createTestServletWithServiceId("B_1", context_B, ID_B),
createTestServletWithServiceId("B_2", context_B, ID_B)));
@@ -259,7 +259,7 @@ public class RuntimeDTOBuilderTest
createTestFilterWithServiceId("B_2", context_B));
List<ErrorPageRuntime> errorPages_B = asList(createErrorPageWithServiceId("E_B_1", context_B, ID_B),
createErrorPageWithServiceId("E_B_2", context_B, ID_B));
- ContextRuntime contextRuntime_B = new ContextRuntime(filters_B, errorPages_B, null, ID_B);
+ ContextRuntime contextRuntime_B = new ContextRuntime(filters_B, errorPages_B, null, null, ID_B);
Map<Long, Collection<ServiceReference<?>>> listenerRuntimes = setupListeners();
@@ -610,7 +610,7 @@ public class RuntimeDTOBuilderTest
ContextRuntime contextRuntime = new ContextRuntime(asList(filterHandler),
Collections.<ErrorPageRuntime>emptyList(),
- null,
+ null, null,
ID_0);
setupRegistry(asList(contextHandler), asList(contextRuntime),
// new ServletRegistryRuntime(asList(resourceHandler), asList(servletHandler)),
@@ -670,7 +670,7 @@ public class RuntimeDTOBuilderTest
ContextRuntime contextRuntime = new ContextRuntime(Collections.<FilterRuntime>emptyList(),
Collections.<ErrorPageRuntime>emptyList(),
- null,
+ null, null,
ID_0);
setupRegistry(asList(contextHandler), asList(contextRuntime),
// new ServletRegistryRuntime(asList(servletHandler), Collections.<ServletRuntime>emptyList()),