You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ja...@apache.org on 2015/03/25 11:28:10 UTC

svn commit: r1669088 [2/3] - in /felix/trunk/http: base/src/main/java/org/apache/felix/http/base/internal/handler/ base/src/main/java/org/apache/felix/http/base/internal/runtime/ base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ base/...

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -20,25 +20,34 @@ package org.apache.felix.http.base.inter
 
 import javax.servlet.DispatcherType;
 
-import org.apache.felix.http.base.internal.handler.FilterHandler;
 import org.apache.felix.http.base.internal.runtime.FilterInfo;
 import org.osgi.service.http.runtime.dto.FilterDTO;
 
-final class FilterDTOBuilder extends BaseDTOBuilder<FilterHandler, FilterDTO>
+final class FilterDTOBuilder<T extends FilterDTO> extends BaseDTOBuilder<FilterRuntime, T>
 {
+    static FilterDTOBuilder<FilterDTO> create()
+    {
+        return new FilterDTOBuilder<FilterDTO>(DTOFactories.FILTER);
+    }
+
+    FilterDTOBuilder(DTOFactory<T> dtoFactory)
+    {
+        super(dtoFactory);
+    }
+
     @Override
-    FilterDTO buildDTO(FilterHandler filterHandler, long servletContextId)
+    T buildDTO(FilterRuntime filterRuntime, long servletContextId)
     {
-        FilterInfo info = filterHandler.getFilterInfo();
+        FilterInfo info = filterRuntime.getFilterInfo();
 
-        FilterDTO filterDTO = new FilterDTO();
+        T filterDTO = getDTOFactory().get();
         filterDTO.asyncSupported = info.isAsyncSupported();
         filterDTO.dispatcher = getNames(info.getDispatcher());
         filterDTO.initParams = info.getInitParameters();
         filterDTO.name = info.getName();
         filterDTO.patterns = copyWithDefault(info.getPatterns(), BuilderConstants.STRING_ARRAY);
         filterDTO.regexs = copyWithDefault(info.getRegexs(), BuilderConstants.STRING_ARRAY);
-        filterDTO.serviceId = filterHandler.getFilterInfo().getServiceId();
+        filterDTO.serviceId = info.getServiceId();
         filterDTO.servletContextId = servletContextId;
         filterDTO.servletNames = copyWithDefault(info.getServletNames(), BuilderConstants.STRING_ARRAY);
 

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.http.base.internal.runtime.dto;
+
+import java.util.Comparator;
+
+import org.apache.felix.http.base.internal.runtime.FilterInfo;
+
+
+
+public interface FilterRuntime extends WhiteboardServiceRuntime
+{
+    static final Comparator<FilterRuntime> COMPARATOR = new Comparator<FilterRuntime>()
+    {
+        @Override
+        public int compare(FilterRuntime o1, FilterRuntime o2)
+        {
+            return o1.getFilterInfo().compareTo(o2.getFilterInfo());
+        }
+    };
+
+    FilterInfo getFilterInfo();
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -22,12 +22,22 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.runtime.dto.ListenerDTO;
 
-final class ListenerDTOBuilder extends BaseDTOBuilder<ServiceReference<?>, ListenerDTO>
+final class ListenerDTOBuilder<T extends ListenerDTO> extends BaseDTOBuilder<ServiceReference<?>, T>
 {
+    static ListenerDTOBuilder<ListenerDTO> create()
+    {
+        return new ListenerDTOBuilder<ListenerDTO>(DTOFactories.LISTENER);
+    }
+
+    ListenerDTOBuilder(DTOFactory<T> dtoFactory)
+    {
+        super(dtoFactory);
+    }
+
     @Override
-    ListenerDTO buildDTO(ServiceReference<?> listenerRef, long servletContextId)
+    T buildDTO(ServiceReference<?> listenerRef, long servletContextId)
     {
-        ListenerDTO listenerDTO = new ListenerDTO();
+        T listenerDTO = getDTOFactory().get();
         listenerDTO.serviceId = (Long) listenerRef.getProperty(Constants.SERVICE_ID);
         listenerDTO.servletContextId = servletContextId;
         // TODO Is this the desired value?

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.http.base.internal.runtime.dto;
+
+import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.ServiceReference;
+
+public final class RegistryRuntime
+{
+    private final Collection<ServletContextHelperRuntime> contexts;
+    private final Map<Long, Collection<ServiceReference<?>>> listenerRuntimes;
+    private final Map<Long, ContextRuntime> handlerRuntimes;
+    private final FailureRuntime failureRuntime;
+
+    public RegistryRuntime(Collection<ServletContextHelperRuntime> contexts,
+            Collection<ContextRuntime> contextRuntimes,
+            Map<Long, Collection<ServiceReference<?>>> listenerRuntimes,
+            FailureRuntime failureRuntime)
+    {
+        this.contexts = contexts;
+        this.failureRuntime = failureRuntime;
+        this.handlerRuntimes = createServiceIdMap(contextRuntimes);
+        this.listenerRuntimes = listenerRuntimes;
+    }
+
+    private static Map<Long, ContextRuntime> createServiceIdMap(Collection<ContextRuntime> contextRuntimes)
+    {
+        Map<Long, ContextRuntime> runtimesMap = new HashMap<Long, ContextRuntime>();
+        for (ContextRuntime contextRuntime : contextRuntimes)
+        {
+            runtimesMap.put(contextRuntime.getServiceId(), contextRuntime);
+        }
+        return runtimesMap;
+    }
+
+    public ContextRuntime getHandlerRuntime(ServletContextHelperRuntime contextRuntime)
+    {
+        long serviceId = contextRuntime.getContextInfo().getServiceId();
+
+        if (handlerRuntimes.containsKey(serviceId) && isDefaultContext(contextRuntime))
+        {
+            // TODO Merge with the default context of the HttpService ( handlerRuntimes.get(0) )
+            return handlerRuntimes.get(serviceId);
+        }
+        else if (handlerRuntimes.containsKey(serviceId))
+        {
+            return handlerRuntimes.get(serviceId);
+        }
+        return ContextRuntime.empty(serviceId);
+    }
+
+    private boolean isDefaultContext(ServletContextHelperRuntime contextRuntime)
+    {
+        return contextRuntime.getContextInfo().getName().equals(HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME);
+    }
+
+    public Collection<ServiceReference<?>> getListenerRuntimes(ServletContextHelperRuntime contextRuntime)
+    {
+        if (listenerRuntimes.containsKey(contextRuntime.getContextInfo().getServiceId()))
+        {
+            return listenerRuntimes.get(contextRuntime.getContextInfo().getServiceId());
+        }
+        return Collections.emptyList();
+    }
+
+    public Collection<ServletContextHelperRuntime> getContexts()
+    {
+        return contexts;
+    }
+
+    public FailureRuntime getFailureRuntime()
+    {
+        return failureRuntime;
+    }
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -18,18 +18,27 @@
  */
 package org.apache.felix.http.base.internal.runtime.dto;
 
-import org.apache.felix.http.base.internal.handler.ServletHandler;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
 import org.osgi.service.http.runtime.dto.ResourceDTO;
 
-final class ResourceDTOBuilder extends BaseDTOBuilder<ServletHandler, ResourceDTO>
+final class ResourceDTOBuilder<T extends ResourceDTO> extends BaseDTOBuilder<ServletRuntime, T>
 {
+    static ResourceDTOBuilder<ResourceDTO> create()
+    {
+        return new ResourceDTOBuilder<ResourceDTO>(DTOFactories.RESOURCE);
+    }
+
+    ResourceDTOBuilder(DTOFactory<T> dtoFactory)
+    {
+        super(dtoFactory);
+    }
+
     @Override
-    ResourceDTO buildDTO(ServletHandler handler, long servletContextId)
+    T buildDTO(ServletRuntime runtime, long servletContextId)
     {
-        ServletInfo servletInfo = handler.getServletInfo();
+        ServletInfo servletInfo = runtime.getServletInfo();
 
-        ResourceDTO resourceDTO = new ResourceDTO();
+        T resourceDTO = getDTOFactory().get();
         resourceDTO.patterns = copyWithDefault(servletInfo.getPatterns(), BuilderConstants.STRING_ARRAY);
         resourceDTO.prefix = servletInfo.getPrefix();
         resourceDTO.serviceId = servletInfo.getServiceId();

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -20,28 +20,12 @@ package org.apache.felix.http.base.inter
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-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.AbstractInfo;
-import org.apache.felix.http.base.internal.runtime.HandlerRuntime;
-import org.apache.felix.http.base.internal.runtime.HandlerRuntime.ErrorPage;
-import org.apache.felix.http.base.internal.runtime.RegistryRuntime;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.whiteboard.ContextHandler;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.runtime.dto.DTOConstants;
 import org.osgi.service.http.runtime.dto.ErrorPageDTO;
-import org.osgi.service.http.runtime.dto.FailedErrorPageDTO;
-import org.osgi.service.http.runtime.dto.FailedFilterDTO;
-import org.osgi.service.http.runtime.dto.FailedListenerDTO;
-import org.osgi.service.http.runtime.dto.FailedResourceDTO;
-import org.osgi.service.http.runtime.dto.FailedServletContextDTO;
-import org.osgi.service.http.runtime.dto.FailedServletDTO;
 import org.osgi.service.http.runtime.dto.FilterDTO;
 import org.osgi.service.http.runtime.dto.ListenerDTO;
 import org.osgi.service.http.runtime.dto.ResourceDTO;
@@ -52,12 +36,6 @@ import org.osgi.service.http.runtime.dto
 public final class RuntimeDTOBuilder
 {
 
-    private static final ServletDTOBuilder SERVLET_DTO_BUILDER = new ServletDTOBuilder();
-    private static final ResourceDTOBuilder RESOURCE_DTO_BUILDER = new ResourceDTOBuilder();
-    private static final FilterDTOBuilder FILTER_DTO_BUILDER = new FilterDTOBuilder();
-    private static final ErrorPageDTOBuilder ERROR_PAGE_DTO_BUILDER = new ErrorPageDTOBuilder();
-    private static final ListenerDTOBuilder LISTENER_DTO_BUILDER = new ListenerDTOBuilder();
-
     private final RegistryRuntime registry;
     private final Map<String, Object> serviceProperties;
 
@@ -69,44 +47,16 @@ public final class RuntimeDTOBuilder
 
     public RuntimeDTO build()
     {
+        FailureRuntime failureRuntime = registry.getFailureRuntime();
+
         RuntimeDTO runtimeDTO = new RuntimeDTO();
         runtimeDTO.attributes = createAttributes();
-        final List<FailedErrorPageDTO> failedErrorPageDTOs = new ArrayList<FailedErrorPageDTO>();
-        final List<FailedFilterDTO> failedFilterDTOs = new ArrayList<FailedFilterDTO>();
-        final List<FailedListenerDTO> failedListenerDTOs = new ArrayList<FailedListenerDTO>();
-        final List<FailedResourceDTO> failedResourceDTOs = new ArrayList<FailedResourceDTO>();
-        final List<FailedServletContextDTO> failedServletContextDTOs = new ArrayList<FailedServletContextDTO>();
-        final List<FailedServletDTO> failedServletDTOs = new ArrayList<FailedServletDTO>();
-
-        for(final AbstractInfo<?> info : this.registry.getInvalidServices())
-        {
-            if ( info instanceof ServletContextHelperInfo )
-            {
-                final ServletContextHelperInfo sch = (ServletContextHelperInfo)info;
-                final FailedServletContextDTO dto = new FailedServletContextDTO();
-                dto.attributes = Collections.emptyMap();
-                dto.contextPath = sch.getPath();
-                dto.errorPageDTOs = BuilderConstants.ERROR_PAGE_DTO_ARRAY;
-                dto.failureReason = DTOConstants.FAILURE_REASON_VALIDATION_FAILED;
-                dto.filterDTOs = BuilderConstants.FILTER_DTO_ARRAY;
-                dto.initParams = sch.getInitParameters();
-                dto.listenerDTOs = BuilderConstants.LISTENER_DTO_ARRAY;
-                dto.name = sch.getName();
-                dto.resourceDTOs = BuilderConstants.RESOURCE_DTO_ARRAY;
-                dto.serviceId = sch.getServiceId();
-                dto.servletDTOs = BuilderConstants.SERVLET_DTO_ARRAY;
-
-                failedServletContextDTOs.add(dto);
-            }
-        }
-        //TODO <**
-        runtimeDTO.failedErrorPageDTOs = failedErrorPageDTOs.toArray(new FailedErrorPageDTO[failedErrorPageDTOs.size()]);
-        runtimeDTO.failedFilterDTOs = failedFilterDTOs.toArray(new FailedFilterDTO[failedFilterDTOs.size()]);
-        runtimeDTO.failedListenerDTOs = failedListenerDTOs.toArray(new FailedListenerDTO[failedListenerDTOs.size()]);
-        runtimeDTO.failedResourceDTOs = failedResourceDTOs.toArray(new FailedResourceDTO[failedResourceDTOs.size()]);
-        runtimeDTO.failedServletContextDTOs = failedServletContextDTOs.toArray(new FailedServletContextDTO[failedServletContextDTOs.size()]);
-        runtimeDTO.failedServletDTOs = failedServletDTOs.toArray(new FailedServletDTO[failedServletDTOs.size()]);
-        //**>
+        runtimeDTO.failedErrorPageDTOs = failureRuntime.getErrorPageDTOs();
+        runtimeDTO.failedFilterDTOs = failureRuntime.getFilterDTOs();
+        runtimeDTO.failedListenerDTOs = failureRuntime.getListenerDTOs();
+        runtimeDTO.failedResourceDTOs = failureRuntime.getResourceDTOs();
+        runtimeDTO.failedServletContextDTOs = failureRuntime.getServletContextDTOs();
+        runtimeDTO.failedServletDTOs = failureRuntime.getServletDTOs();
         runtimeDTO.servletContextDTOs = createContextDTOs();
         return runtimeDTO;
     }
@@ -124,37 +74,37 @@ public final class RuntimeDTOBuilder
     private ServletContextDTO[] createContextDTOs()
     {
         List<ServletContextDTO> contextDTOs = new ArrayList<ServletContextDTO>();
-        for (ContextHandler context : registry.getContexts())
+        for (ServletContextHelperRuntime context : registry.getContexts())
         {
             contextDTOs.add(createContextDTO(context,
                     registry.getHandlerRuntime(context),
-                    registry.getListenerRuntime(context)));
+                    registry.getListenerRuntimes(context)));
         }
         return contextDTOs.toArray(BuilderConstants.CONTEXT_DTO_ARRAY);
     }
 
-    private ServletContextDTO createContextDTO(ContextHandler context,
-            HandlerRuntime handlerRuntime,
-            Collection<ServiceReference<?>> listenerRefs)
+    private ServletContextDTO createContextDTO(ServletContextHelperRuntime context,
+            ContextRuntime contextRuntime,
+            Collection<ServiceReference<?>> listenerRuntimes)
     {
-        Collection<ServletHandler> servletHandlers = handlerRuntime.getServletHandlers();
-        Collection<ServletHandler> resourceHandlers = handlerRuntime.getResourceHandlers();
-        Collection<FilterHandler> filterHandlers = handlerRuntime.getFilterHandlers();
-        Collection<ErrorPage> errorPages = handlerRuntime.getErrorPages();
-        long servletContextId = handlerRuntime.getServiceId();
-
-        Collection<ServletDTO> servletDTOs = SERVLET_DTO_BUILDER.build(servletHandlers, servletContextId);
-        Collection<ResourceDTO> resourcesDTOs = RESOURCE_DTO_BUILDER.build(resourceHandlers, servletContextId);
-        Collection<FilterDTO> filtersDTOs = FILTER_DTO_BUILDER.build(filterHandlers, servletContextId);
-        Collection<ErrorPageDTO> errorsDTOs = ERROR_PAGE_DTO_BUILDER.build(errorPages, servletContextId);
-        Collection<ListenerDTO> listenersDTOs = LISTENER_DTO_BUILDER.build(listenerRefs, servletContextId);
+        Collection<ServletRuntime> servletRuntimes = contextRuntime.getServletRuntimes();
+        Collection<ServletRuntime> resourceRuntimes = contextRuntime.getResourceRuntimes();
+        Collection<FilterRuntime> filterRuntimes = contextRuntime.getFilterRuntimes();
+        Collection<ErrorPageRuntime> errorPageRuntimes = contextRuntime.getErrorPageRuntimes();
+        long servletContextId = contextRuntime.getServiceId();
+
+        Collection<ServletDTO> servletDTOs = ServletDTOBuilder.create().build(servletRuntimes, servletContextId);
+        Collection<ResourceDTO> resourceDTOs = ResourceDTOBuilder.create().build(resourceRuntimes, servletContextId);
+        Collection<FilterDTO> filterDTOs = FilterDTOBuilder.create().build(filterRuntimes, servletContextId);
+        Collection<ErrorPageDTO> errorDTOs = ErrorPageDTOBuilder.create().build(errorPageRuntimes, servletContextId);
+        Collection<ListenerDTO> listenerDTOs = ListenerDTOBuilder.create().build(listenerRuntimes, servletContextId);
 
         return new ServletContextDTOBuilder(context,
                     servletDTOs,
-                    resourcesDTOs,
-                    filtersDTOs,
-                    errorsDTOs,
-                    listenersDTOs)
+                    resourceDTOs,
+                    filterDTOs,
+                    errorDTOs,
+                    listenerDTOs)
                 .build();
     }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -21,13 +21,13 @@ package org.apache.felix.http.base.inter
 import static java.util.Collections.list;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
 
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.whiteboard.ContextHandler;
 import org.osgi.dto.DTO;
 import org.osgi.service.http.runtime.dto.ErrorPageDTO;
 import org.osgi.service.http.runtime.dto.FilterDTO;
@@ -39,21 +39,24 @@ import org.osgi.service.http.runtime.dto
 final class ServletContextDTOBuilder
 {
 
-    private final ContextHandler contextHandler;
+    private final ServletContextDTO contextDTO;
+    private final ServletContextHelperRuntime contextRuntime;
     private final ServletDTO[] servletDTOs;
     private final ResourceDTO[] resourceDTOs;
     private final FilterDTO[] filterDTOs;
     private final ErrorPageDTO[] errorPageDTOs;
     private final ListenerDTO[] listenerDTOs;
 
-    public ServletContextDTOBuilder(ContextHandler contextHandler,
+    ServletContextDTOBuilder(ServletContextDTO contextDTO,
+            ServletContextHelperRuntime contextRuntime,
             Collection<ServletDTO> servletDTOs,
             Collection<ResourceDTO> resourceDTOs,
             Collection<FilterDTO> filterDTOs,
             Collection<ErrorPageDTO> errorPageDTOs,
             Collection<ListenerDTO> listenerDTOs)
     {
-        this.contextHandler = contextHandler;
+        this.contextDTO = contextDTO;
+        this.contextRuntime = contextRuntime;
         this.servletDTOs = servletDTOs != null ?
                 servletDTOs.toArray(BuilderConstants.SERVLET_DTO_ARRAY) : BuilderConstants.SERVLET_DTO_ARRAY;
         this.resourceDTOs = resourceDTOs != null ?
@@ -66,20 +69,34 @@ final class ServletContextDTOBuilder
                 listenerDTOs.toArray(BuilderConstants.LISTENER_DTO_ARRAY) : BuilderConstants.LISTENER_DTO_ARRAY;
     }
 
+    ServletContextDTOBuilder(ServletContextHelperRuntime contextRuntime,
+            Collection<ServletDTO> servletDTOs,
+            Collection<ResourceDTO> resourceDTOs,
+            Collection<FilterDTO> filterDTOs,
+            Collection<ErrorPageDTO> errorPageDTOs,
+            Collection<ListenerDTO> listenerDTOs)
+    {
+        this(new ServletContextDTO(), contextRuntime, servletDTOs, resourceDTOs, filterDTOs, errorPageDTOs, listenerDTOs);
+    }
+
+    ServletContextDTOBuilder(ServletContextDTO contextDTO, ServletContextHelperRuntime contextRuntime)
+    {
+        this(contextDTO, contextRuntime, null, null, null, null, null);
+    }
+
     ServletContextDTO build()
     {
-        ServletContext context  = contextHandler.getSharedContext();
-        ServletContextHelperInfo contextInfo = contextHandler.getContextInfo();
+        ServletContext context  = contextRuntime.getSharedContext();
+        ServletContextHelperInfo contextInfo = contextRuntime.getContextInfo();
         long contextId = contextInfo.getServiceId();
 
-        ServletContextDTO contextDTO = new ServletContextDTO();
         contextDTO.attributes = getAttributes(context);
-        contextDTO.contextPath = context.getContextPath();
+        contextDTO.contextPath = context == null ? contextInfo.getPath() : context.getContextPath();
         contextDTO.errorPageDTOs = errorPageDTOs;
         contextDTO.filterDTOs = filterDTOs;
         contextDTO.initParams = contextInfo.getInitParameters();
         contextDTO.listenerDTOs = listenerDTOs;
-        contextDTO.name = context.getServletContextName();
+        contextDTO.name = contextInfo.getName();
         contextDTO.resourceDTOs = resourceDTOs;
         contextDTO.servletDTOs = servletDTOs;
         contextDTO.serviceId = contextId;
@@ -89,6 +106,11 @@ final class ServletContextDTOBuilder
 
     private Map<String, Object> getAttributes(ServletContext context)
     {
+        if (context == null)
+        {
+            return Collections.emptyMap();
+        }
+
         Map<String, Object> attributes = new HashMap<String, Object>();
         for (String name : list(context.getAttributeNames()))
         {

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextHelperRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextHelperRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextHelperRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextHelperRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.http.base.internal.runtime.dto;
+
+import java.util.Comparator;
+
+import javax.servlet.ServletContext;
+
+import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
+
+public interface ServletContextHelperRuntime
+{
+    static final Comparator<ServletContextHelperRuntime> COMPARATOR = new Comparator<ServletContextHelperRuntime>()
+    {
+        @Override
+        public int compare(ServletContextHelperRuntime o1, ServletContextHelperRuntime o2)
+        {
+            return o1.getContextInfo().compareTo(o2.getContextInfo());
+        }
+    };
+
+    ServletContext getSharedContext();
+
+    ServletContextHelperInfo getContextInfo();
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextHelperRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -18,19 +18,27 @@
  */
 package org.apache.felix.http.base.internal.runtime.dto;
 
-import org.apache.felix.http.base.internal.handler.ServletHandler;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
 import org.osgi.service.http.runtime.dto.ServletDTO;
 
-final class ServletDTOBuilder extends BaseServletDTOBuilder<ServletHandler, ServletDTO>
+final class ServletDTOBuilder<T extends ServletDTO> extends BaseServletDTOBuilder<ServletRuntime, T>
 {
+    static ServletDTOBuilder<ServletDTO> create()
+    {
+        return new ServletDTOBuilder<ServletDTO>(DTOFactories.SERVLET);
+    }
+
+    ServletDTOBuilder(DTOFactory<T> dtoFactory)
+    {
+        super(dtoFactory);
+    }
+
     @Override
-    ServletDTO buildDTO(ServletHandler servletHandler, long servletContextId)
+    T buildDTO(ServletRuntime servletRuntime, long servletContextId)
     {
-        ServletInfo info = servletHandler.getServletInfo();
+        ServletInfo info = servletRuntime.getServletInfo();
 
-        ServletDTO servletDTO = new ServletDTO();
-        setBaseFields(servletDTO, servletHandler, servletContextId);
+        T servletDTO = super.buildDTO(servletRuntime, servletContextId);
         servletDTO.patterns = copyWithDefault(checkNotEmpty(info.getPatterns()), null);
         return servletDTO;
     }

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.http.base.internal.runtime.dto;
+
+import java.util.Comparator;
+
+import javax.servlet.Servlet;
+
+import org.apache.felix.http.base.internal.runtime.ServletInfo;
+
+
+
+public interface ServletRuntime extends WhiteboardServiceRuntime
+{
+    static final Comparator<ServletRuntime> COMPARATOR = new Comparator<ServletRuntime>()
+    {
+        @Override
+        public int compare(ServletRuntime o1, ServletRuntime o2)
+        {
+            return o1.getServletInfo().compareTo(o2.getServletInfo());
+        }
+    };
+
+    Servlet getServlet();
+
+    ServletInfo getServletInfo();
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/WhiteboardServiceRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/WhiteboardServiceRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/WhiteboardServiceRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/WhiteboardServiceRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.http.base.internal.runtime.dto;
+
+
+
+interface WhiteboardServiceRuntime
+{
+    long getContextServiceId();
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/WhiteboardServiceRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1669088&r1=1669087&r2=1669088&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 Wed Mar 25 10:28:08 2015
@@ -22,7 +22,7 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.apache.felix.http.base.internal.handler.HandlerRegistry;
-import org.apache.felix.http.base.internal.runtime.RegistryRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.RegistryRuntime;
 import org.apache.felix.http.base.internal.runtime.dto.RuntimeDTOBuilder;
 import org.apache.felix.http.base.internal.whiteboard.ServletContextHelperManager;
 import org.osgi.service.http.runtime.HttpServiceRuntime;
@@ -36,7 +36,6 @@ public final class HttpServiceRuntimeImp
     private final HandlerRegistry registry;
     private final ServletContextHelperManager contextManager;
 
-
     public HttpServiceRuntimeImpl(HandlerRegistry registry,
             ServletContextHelperManager contextManager)
     {
@@ -54,7 +53,6 @@ public final class HttpServiceRuntimeImp
     @Override
     public RequestInfoDTO calculateRequestInfoDTO(String path)
     {
-        // TODO Auto-generated method stub
         return null;
     }
 

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=1669088&r1=1669087&r2=1669088&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 Wed Mar 25 10:28:08 2015
@@ -31,6 +31,7 @@ import org.apache.felix.http.base.intern
 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.ServletInfo;
+import org.apache.felix.http.base.internal.whiteboard.RegistrationFailureException;
 import org.osgi.service.http.NamespaceException;
 
 public final class SharedHttpServiceImpl
@@ -103,7 +104,15 @@ public final class SharedHttpServiceImpl
             {
                 throw new IllegalArgumentException("Nothing registered at " + alias);
             }
-            return this.handlerRegistry.removeServlet(handler.getServletInfo(), true);
+
+            try
+            {
+                return this.handlerRegistry.removeServlet(handler.getServletInfo(), true);
+            } catch (RegistrationFailureException e)
+            {
+                // TODO create FailureDTO
+                return null;
+            }
         }
     }
 
@@ -111,7 +120,14 @@ public final class SharedHttpServiceImpl
     {
         if (servlet != null)
         {
-            this.handlerRegistry.removeServlet(servlet, destroy);
+            try
+            {
+                this.handlerRegistry.removeServlet(servlet, destroy);
+            } catch (RegistrationFailureException e)
+            {
+                // TODO create FailureDTO
+            }
+
             synchronized (this.aliasMap)
             {
                 final Iterator<Map.Entry<String, ServletHandler>> i = this.aliasMap.entrySet().iterator();

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java Wed Mar 25 10:28:08 2015
@@ -17,13 +17,19 @@
 package org.apache.felix.http.base.internal.util;
 
 import java.util.Collection;
-import java.util.Set;
+import java.util.Comparator;
+import java.util.SortedSet;
 import java.util.TreeSet;
 
 public class CollectionUtils {
-	public static <T extends Comparable<?>> Set<T> union(Collection<? extends T>... collections)
+    public static <T extends Comparable<?>> SortedSet<T> sortedUnion(Collection<? extends T>... collections)
     {
-        Set<T> union = new TreeSet<T>();
+        return sortedUnion(null, collections);
+    }
+
+    public static <T> SortedSet<T> sortedUnion(Comparator<T> comparator, Collection<? extends T>... collections)
+    {
+        SortedSet<T> union = comparator == null ? new TreeSet<T>() : new TreeSet<T>(comparator);
         for (Collection<? extends T> collection : collections)
         {
             union.addAll(collection);

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java Wed Mar 25 10:28:08 2015
@@ -24,11 +24,12 @@ import javax.servlet.ServletContext;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
+import org.apache.felix.http.base.internal.runtime.dto.ServletContextHelperRuntime;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceObjects;
 import org.osgi.service.http.context.ServletContextHelper;
 
-public final class ContextHandler implements Comparable<ContextHandler>
+public final class ContextHandler implements Comparable<ContextHandler>, ServletContextHelperRuntime
 {
     /** The info object for the context. */
     private final ServletContextHelperInfo info;
@@ -59,6 +60,7 @@ public final class ContextHandler implem
                 eventListener);
     }
 
+    @Override
     public ServletContextHelperInfo getContextInfo()
     {
         return this.info;
@@ -80,6 +82,7 @@ public final class ContextHandler implem
         this.ungetServletContext(bundle);
     }
 
+    @Override
     public ServletContext getSharedContext()
     {
         return sharedContext;

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java Wed Mar 25 10:28:08 2015
@@ -23,9 +23,13 @@ import java.util.TreeMap;
 
 import javax.annotation.Nonnull;
 
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
+import org.apache.felix.http.base.internal.runtime.ServletRequestAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.ServletRequestListenerInfo;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 
@@ -40,6 +44,23 @@ public final class ListenerRegistry
         this.bundle = bundle;
     }
 
+    public PerContextEventListener addContext(ServletContextHelperInfo info)
+    {
+        if (registriesByContext.containsKey(info))
+        {
+            throw new IllegalArgumentException("Context with id " + info.getServiceId() + "is already registered");
+        }
+
+        PerContextEventListener contextRegistry = new PerContextEventListener(bundle);
+        registriesByContext.put(info, contextRegistry);
+        return contextRegistry;
+    }
+
+    public void removeContext(ServletContextHelperInfo info)
+    {
+        registriesByContext.remove(info);
+    }
+
     public void initialized(@Nonnull final ServletContextListenerInfo listenerInfo,
             ContextHandler contextHandler)
     {
@@ -52,43 +73,74 @@ public final class ListenerRegistry
         registriesByContext.get(contextHandler.getContextInfo()).destroyed(listenerInfo, contextHandler);
     }
 
-    public <T extends ListenerInfo<?>> void addListener(@Nonnull final T info,
+    void addListener(@Nonnull final ServletContextAttributeListenerInfo info,
             final ContextHandler contextHandler)
     {
         getRegistryForContext(contextHandler).addListener(info);
     }
 
-    public <T extends ListenerInfo<?>> void removeListener(@Nonnull final T info,
-           final ContextHandler contextHandler)
+    void removeListener(@Nonnull final ServletContextAttributeListenerInfo info,
+            final ContextHandler contextHandler)
     {
         getRegistryForContext(contextHandler).removeListener(info);
     }
 
-    private PerContextEventListener getRegistryForContext(ContextHandler contextHandler)
+    void addListener(@Nonnull final HttpSessionAttributeListenerInfo info,
+            final ContextHandler contextHandler)
     {
-        PerContextEventListener contextRegistry = registriesByContext.get(contextHandler.getContextInfo());
-        if (contextRegistry == null)
-        {
-            throw new IllegalArgumentException("ContextHandler " + contextHandler.getContextInfo().getName() + " is not registered");
-        }
-        return contextRegistry;
+        getRegistryForContext(contextHandler).addListener(info);
     }
 
-    public PerContextEventListener addContext(ServletContextHelperInfo info)
+    void removeListener(@Nonnull final HttpSessionAttributeListenerInfo info,
+            final ContextHandler contextHandler)
     {
-        if (registriesByContext.containsKey(info))
-        {
-            throw new IllegalArgumentException("Context with id " + info.getServiceId() + "is already registered");
-        }
+        getRegistryForContext(contextHandler).removeListener(info);
+    }
 
-        PerContextEventListener contextRegistry = new PerContextEventListener(bundle);
-        registriesByContext.put(info, contextRegistry);
-        return contextRegistry;
+    void addListener(@Nonnull final HttpSessionListenerInfo info,
+            final ContextHandler contextHandler)
+    {
+        getRegistryForContext(contextHandler).addListener(info);
     }
 
-    public void removeContext(ServletContextHelperInfo info)
+    void removeListener(@Nonnull final HttpSessionListenerInfo info,
+            final ContextHandler contextHandler)
     {
-        registriesByContext.remove(info);
+        getRegistryForContext(contextHandler).removeListener(info);
+    }
+
+    void addListener(@Nonnull final ServletRequestListenerInfo info,
+            final ContextHandler contextHandler)
+    {
+        getRegistryForContext(contextHandler).addListener(info);
+    }
+
+    void removeListener(@Nonnull final ServletRequestListenerInfo info,
+            final ContextHandler contextHandler)
+    {
+        getRegistryForContext(contextHandler).removeListener(info);
+    }
+
+    void addListener(@Nonnull final ServletRequestAttributeListenerInfo info,
+            final ContextHandler contextHandler)
+    {
+        getRegistryForContext(contextHandler).addListener(info);
+    }
+
+    void removeListener(@Nonnull final ServletRequestAttributeListenerInfo info,
+            final ContextHandler contextHandler)
+    {
+        getRegistryForContext(contextHandler).removeListener(info);
+    }
+
+    private PerContextEventListener getRegistryForContext(ContextHandler contextHandler)
+    {
+        PerContextEventListener contextRegistry = registriesByContext.get(contextHandler.getContextInfo());
+        if (contextRegistry == null)
+        {
+            throw new IllegalArgumentException("ContextHandler " + contextHandler.getContextInfo().getName() + " is not registered");
+        }
+        return contextRegistry;
     }
 
     public Map<Long, Collection<ServiceReference<?>>> getContextRuntimes()
@@ -96,7 +148,8 @@ public final class ListenerRegistry
         Map<Long, Collection<ServiceReference<?>>> listenersByContext = new HashMap<Long, Collection<ServiceReference<?>>>();
         for (ServletContextHelperInfo contextInfo : registriesByContext.keySet())
         {
-            listenersByContext.put(contextInfo.getServiceId(), registriesByContext.get(contextInfo).getRuntime());
+            long serviceId = contextInfo.getServiceId();
+            listenersByContext.put(serviceId, registriesByContext.get(contextInfo).getRuntime());
         }
         return listenersByContext;
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java Wed Mar 25 10:28:08 2015
@@ -17,6 +17,7 @@
 package org.apache.felix.http.base.internal.whiteboard;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ConcurrentSkipListMap;
 
@@ -37,7 +38,6 @@ import javax.servlet.http.HttpSessionLis
 
 import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
 import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletRequestAttributeListenerInfo;
@@ -262,19 +262,6 @@ public final class PerContextEventListen
         }
     }
 
-    // Make calling from ListenerRegistry easier
-    <T extends ListenerInfo<?>> void addListener(@Nonnull T info)
-    {
-        throw new UnsupportedOperationException("Listeners of type "
-                + info.getClass() + "are not supported");
-    }
-
-    <T extends ListenerInfo<?>> void removeListener(@Nonnull T info)
-    {
-        throw new UnsupportedOperationException("Listeners of type "
-                + info.getClass() + "are not supported");
-    }
-
     @Override
     public void attributeReplaced(final HttpSessionBindingEvent event)
     {
@@ -404,7 +391,8 @@ public final class PerContextEventListen
     @SuppressWarnings("unchecked")
     Collection<ServiceReference<?>> getRuntime()
     {
-        return CollectionUtils.<ServiceReference<?>> union(
+        return CollectionUtils.<ServiceReference<?>>sortedUnion(
+                Collections.<ServiceReference<?>>reverseOrder(),
                 contextListeners.keySet(),
                 contextAttributeListeners.keySet(),
                 sessionAttributeListeners.keySet(),

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/RegistrationFailureException.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/RegistrationFailureException.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/RegistrationFailureException.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/RegistrationFailureException.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.http.base.internal.whiteboard;
+
+import javax.servlet.ServletException;
+
+import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
+
+@SuppressWarnings("serial")
+public class RegistrationFailureException extends ServletException
+{
+    private final WhiteboardServiceInfo<?> info;
+    private final int errorCode;
+
+    public RegistrationFailureException(WhiteboardServiceInfo<?> info, int errorCode)
+    {
+        super();
+        this.info = info;
+        this.errorCode = errorCode;
+    }
+
+    public RegistrationFailureException(WhiteboardServiceInfo<?> info, int errorCode, String message)
+    {
+        super(message);
+        this.info = info;
+        this.errorCode = errorCode;
+    }
+
+    public RegistrationFailureException(WhiteboardServiceInfo<?> info, int errorCode, Throwable exception)
+    {
+        super(exception);
+        this.info = info;
+        this.errorCode = errorCode;
+    }
+
+    public WhiteboardServiceInfo<?> getInfo()
+    {
+        return info;
+    }
+
+    public int getErrorCode()
+    {
+        return errorCode;
+    }
+}
\ No newline at end of file

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/RegistrationFailureException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java Wed Mar 25 10:28:08 2015
@@ -16,6 +16,11 @@
  */
 package org.apache.felix.http.base.internal.whiteboard;
 
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING;
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE;
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_UNKNOWN;
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_VALIDATION_FAILED;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -25,10 +30,9 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
-import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.ConcurrentSkipListMap;
 
 import javax.annotation.Nonnull;
 import javax.servlet.ServletContext;
@@ -38,14 +42,20 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.logger.SystemLogger;
 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.HandlerRuntime;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.apache.felix.http.base.internal.runtime.RegistryRuntime;
+import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ResourceInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
+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.RegistryRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.ServletContextHelperRuntime;
 import org.apache.felix.http.base.internal.util.MimeTypes;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -73,7 +83,7 @@ public final class ServletContextHelperM
 
     private final BundleContext bundleContext;
 
-    private final Set<AbstractInfo<?>> invalidRegistrations = new ConcurrentSkipListSet<AbstractInfo<?>>();
+    private final Map<AbstractInfo<?>, Integer> serviceFailures = new ConcurrentSkipListMap<AbstractInfo<?>, Integer>();
 
     private volatile ServletContext webContext;
 
@@ -176,6 +186,7 @@ public final class ServletContextHelperM
                 {
                     services.add(entry.getKey());
                 }
+                removeFailure(entry.getKey(), FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING);
             }
         }
         // context listeners first
@@ -222,7 +233,6 @@ public final class ServletContextHelperM
         handler.deactivate();
 
         this.httpService.unregisterContext(handler);
-
     }
 
     /**
@@ -257,17 +267,24 @@ public final class ServletContextHelperM
                         // check for deactivate
                         if ( handlerList.size() > 1 )
                         {
-                            this.deactivate(handlerList.get(1));
+                            ContextHandler oldHead = handlerList.get(1);
+                            this.deactivate(oldHead);
+                            this.serviceFailures.put(oldHead.getContextInfo(), FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
                         }
+                        removeFailure(handler.getContextInfo(), FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
                         this.activate(handler);
                     }
+                    else
+                    {
+                        this.serviceFailures.put(handler.getContextInfo(), FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
+                    }
                 }
             }
             else
             {
                 final String type = info.getClass().getSimpleName().substring(0, info.getClass().getSimpleName().length() - 4);
                 SystemLogger.debug("Ignoring " + type + " service " + info.getServiceReference());
-                this.invalidRegistrations.add(info);
+                this.serviceFailures.put(info, FAILURE_REASON_VALIDATION_FAILED);
             }
         }
     }
@@ -312,16 +329,15 @@ public final class ServletContextHelperM
                         }
                         else if ( activateNext )
                         {
-                            this.activate(handlerList.get(0));
+                            ContextHandler newHead = handlerList.get(0);
+                            this.activate(newHead);
+                            removeFailure(newHead.getContextInfo(), FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
                         }
                         listenerRegistry.removeContext(info);
                     }
                 }
             }
-            else
-            {
-                this.invalidRegistrations.remove(info);
-            }
+            this.serviceFailures.remove(info);
         }
     }
 
@@ -360,13 +376,17 @@ public final class ServletContextHelperM
                     {
                         this.registerWhiteboardService(h, info);
                     }
+                    if (handlerList.isEmpty())
+                    {
+                        this.serviceFailures.put(info, FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING);
+                    }
                 }
             }
             else
             {
                 final String type = info.getClass().getSimpleName().substring(0, info.getClass().getSimpleName().length() - 4);
                 SystemLogger.debug("Ignoring " + type + " service " + info.getServiceReference());
-                this.invalidRegistrations.add(info);
+                this.serviceFailures.put(info, FAILURE_REASON_VALIDATION_FAILED);
             }
         }
     }
@@ -393,10 +413,7 @@ public final class ServletContextHelperM
                     }
                 }
             }
-            else
-            {
-                this.invalidRegistrations.remove(info);
-            }
+            this.serviceFailures.remove(info);
         }
     }
 
@@ -407,21 +424,51 @@ public final class ServletContextHelperM
      */
     private void registerWhiteboardService(final ContextHandler handler, final WhiteboardServiceInfo<?> info)
     {
-        if ( info instanceof ServletInfo )
-        {
-            this.httpService.registerServlet(handler, (ServletInfo)info);
-        }
-        else if ( info instanceof FilterInfo )
+        try
         {
-            this.httpService.registerFilter(handler, (FilterInfo)info);
+            if ( info instanceof ServletInfo )
+            {
+                this.httpService.registerServlet(handler, (ServletInfo)info);
+            }
+            else if ( info instanceof FilterInfo )
+            {
+                this.httpService.registerFilter(handler, (FilterInfo)info);
+            }
+            else if ( info instanceof ResourceInfo )
+            {
+                this.httpService.registerResource(handler, (ResourceInfo)info);
+            }
+
+            else if ( info instanceof ServletContextAttributeListenerInfo )
+            {
+                this.listenerRegistry.addListener((ServletContextAttributeListenerInfo) info, handler);
+            }
+            else if ( info instanceof HttpSessionListenerInfo )
+            {
+                this.listenerRegistry.addListener((HttpSessionListenerInfo) info, handler);
+            }
+            else if ( info instanceof HttpSessionAttributeListenerInfo )
+            {
+                this.listenerRegistry.addListener((HttpSessionAttributeListenerInfo) info, handler);
+            }
+            else if ( info instanceof ServletRequestListenerInfo )
+            {
+                this.listenerRegistry.addListener((ServletRequestListenerInfo) info, handler);
+            }
+            else if ( info instanceof ServletRequestAttributeListenerInfo )
+            {
+                this.listenerRegistry.addListener((ServletRequestAttributeListenerInfo) info, handler);
+            }
         }
-        else if ( info instanceof ResourceInfo )
+        catch (RegistrationFailureException e)
         {
-            this.httpService.registerResource(handler, (ResourceInfo)info);
+            serviceFailures.put(e.getInfo(), e.getErrorCode());
+            SystemLogger.error("Exception while adding servlet", e);
         }
-        else if ( info instanceof ListenerInfo )
+        catch (RuntimeException e)
         {
-            this.listenerRegistry.addListener((ListenerInfo<?>)info, handler);
+            serviceFailures.put(info, FAILURE_REASON_UNKNOWN);
+            throw e;
         }
     }
 
@@ -432,21 +479,56 @@ public final class ServletContextHelperM
      */
     private void unregisterWhiteboardService(final ContextHandler handler, final WhiteboardServiceInfo<?> info)
     {
-        if ( info instanceof ServletInfo )
+        try
         {
-            this.httpService.unregisterServlet(handler, (ServletInfo)info);
-        }
-        else if ( info instanceof FilterInfo )
-        {
-            this.httpService.unregisterFilter(handler, (FilterInfo)info);
+            if ( info instanceof ServletInfo )
+            {
+                this.httpService.unregisterServlet(handler, (ServletInfo)info);
+            }
+            else if ( info instanceof FilterInfo )
+            {
+                this.httpService.unregisterFilter(handler, (FilterInfo)info);
+            }
+            else if ( info instanceof ResourceInfo )
+            {
+                this.httpService.unregisterResource(handler, (ResourceInfo)info);
+            }
+
+            else if ( info instanceof ServletContextAttributeListenerInfo )
+            {
+                this.listenerRegistry.removeListener((ServletContextAttributeListenerInfo) info, handler);
+            }
+            else if ( info instanceof HttpSessionListenerInfo )
+            {
+                this.listenerRegistry.removeListener((HttpSessionListenerInfo) info, handler);
+            }
+            else if ( info instanceof HttpSessionAttributeListenerInfo )
+            {
+                this.listenerRegistry.removeListener((HttpSessionAttributeListenerInfo) info, handler);
+            }
+            else if ( info instanceof ServletRequestListenerInfo )
+            {
+                this.listenerRegistry.removeListener((ServletRequestListenerInfo) info, handler);
+            }
+            else if ( info instanceof ServletRequestAttributeListenerInfo )
+            {
+                this.listenerRegistry.removeListener((ServletRequestAttributeListenerInfo) info, handler);
+            }
         }
-        else if ( info instanceof ResourceInfo )
+        catch (RegistrationFailureException e)
         {
-            this.httpService.unregisterResource(handler, (ResourceInfo)info);
+            serviceFailures.put(e.getInfo(), e.getErrorCode());
+            SystemLogger.error("Exception while removing servlet", e);
         }
-        else if ( info instanceof ListenerInfo )
+        serviceFailures.remove(info);
+    }
+
+    private void removeFailure(AbstractInfo<?> info, int failureCode)
+    {
+        Integer registeredFailureCode = this.serviceFailures.get(info);
+        if (registeredFailureCode != null && registeredFailureCode == failureCode)
         {
-            this.listenerRegistry.removeListener((ListenerInfo<?>)info, handler);
+            this.serviceFailures.remove(info);
         }
     }
 
@@ -506,21 +588,23 @@ public final class ServletContextHelperM
 
     public RegistryRuntime getRuntime(HandlerRegistry registry)
     {
-        List<HandlerRuntime> handlerRuntimes;
+        Collection<ServletContextHelperRuntime> contextRuntimes = new TreeSet<ServletContextHelperRuntime>(ServletContextHelperRuntime.COMPARATOR);
+        List<ContextRuntime> handlerRuntimes;
         Map<Long, Collection<ServiceReference<?>>> listenerRuntimes;
-        Set<ContextHandler> contextHandlers = new TreeSet<ContextHandler>();
+        FailureRuntime.Builder failureRuntime = FailureRuntime.builder();
         synchronized ( this.contextMap )
         {
             for (List<ContextHandler> contextHandlerList : this.contextMap.values())
             {
                 if ( !contextHandlerList.isEmpty() )
                 {
-                    contextHandlers.add(contextHandlerList.get(0));
+                    contextRuntimes.add(contextHandlerList.get(0));
                 }
             }
-            handlerRuntimes = registry.getRuntime();
+            handlerRuntimes = registry.getRuntime(failureRuntime);
             listenerRuntimes = listenerRegistry.getContextRuntimes();
+            failureRuntime.add(serviceFailures);
         }
-        return new RegistryRuntime(contextHandlers, handlerRuntimes, listenerRuntimes, this.invalidRegistrations);
+        return new RegistryRuntime(contextRuntimes, handlerRuntimes, listenerRuntimes, failureRuntime.build());
     }
 }

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=1669088&r1=1669087&r2=1669088&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 Wed Mar 25 10:28:08 2015
@@ -16,9 +16,11 @@
  */
 package org.apache.felix.http.base.internal.whiteboard;
 
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
+
 import javax.annotation.Nonnull;
 import javax.servlet.Filter;
-import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 
 import org.apache.felix.http.base.internal.handler.FilterHandler;
@@ -27,9 +29,9 @@ import org.apache.felix.http.base.intern
 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.ResourceInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceObjects;
 
 public final class WhiteboardHttpService
 {
@@ -53,33 +55,47 @@ public final class WhiteboardHttpService
      * Register a servlet.
      * @param contextInfo The servlet context helper info
      * @param servletInfo The servlet info
+     * @throws RegistrationFailureException 
      */
     public void registerServlet(@Nonnull final ContextHandler contextHandler,
             @Nonnull final ServletInfo servletInfo)
+            throws RegistrationFailureException
     {
-    	final PerContextHandlerRegistry registry = this.handlerRegistry.getRegistry(contextHandler.getContextInfo());
-    	if (registry != null)
-    	{
-    		try {
-    			ServletHandler handler = new ServletHandler(contextHandler.getContextInfo(), 
-    					contextHandler.getServletContext(servletInfo.getServiceReference().getBundle()), 
-    					servletInfo, 
-    					null, 
-    					true);
-    			
-    			registry.addServlet(handler);
-			} catch (ServletException e) {
-				// TODO create failure DTO
-			}
-    	}
+        ServletContextHelperInfo contextInfo = contextHandler.getContextInfo();
+        final PerContextHandlerRegistry registry = this.handlerRegistry.getRegistry(contextInfo);
+        if (registry != null)
+        {
+            try
+            {
+                ServletHandler handler = new ServletHandler(contextHandler.getContextInfo(),
+                        contextHandler.getServletContext(servletInfo.getServiceReference().getBundle()),
+                        servletInfo,
+                        null,
+                        true);
+
+                registry.addServlet(handler);
+            }
+            catch (final RegistrationFailureException e)
+            {
+                throw e;
+            }
+            catch (final ServletException e)
+            {
+                throw new RegistrationFailureException(servletInfo, FAILURE_REASON_EXCEPTION_ON_INIT, e);
+            }
+        } else
+        {
+            throw new RegistrationFailureException(servletInfo, FAILURE_REASON_SERVICE_NOT_GETTABLE);
+        }
     }
 
     /**
      * Unregister a servlet
      * @param contextInfo The servlet context helper info
      * @param servletInfo The servlet info
+     * @throws RegistrationFailureException 
      */
-    public void unregisterServlet(@Nonnull final ContextHandler contextHandler, @Nonnull final ServletInfo servletInfo)
+    public void unregisterServlet(@Nonnull final ContextHandler contextHandler, @Nonnull final ServletInfo servletInfo) throws RegistrationFailureException
     {
         final PerContextHandlerRegistry registry = this.handlerRegistry.getRegistry(contextHandler.getContextInfo());
         if (registry != null )
@@ -93,12 +109,12 @@ public final class WhiteboardHttpService
      * Register a filter
      * @param contextInfo The servlet context helper info
      * @param filterInfo The filter info
+     * @throws RegistrationFailureException 
      */
     public void registerFilter(@Nonnull  final ContextHandler contextHandler,
-            @Nonnull final FilterInfo filterInfo)
+            @Nonnull final FilterInfo filterInfo) throws RegistrationFailureException
     {
         final Filter filter = this.bundleContext.getServiceObjects(filterInfo.getServiceReference()).getService();
-        // TODO create failure DTO if null
         if ( filter != null )
         {
             final FilterHandler handler = new FilterHandler(contextHandler.getContextInfo(),
@@ -111,9 +127,19 @@ public final class WhiteboardHttpService
                 {
                     registry.addFilter(handler);
                 }
-            } catch (final ServletException e) {
-                // TODO create failure DTO
             }
+            catch (final RegistrationFailureException e)
+            {
+                throw e;
+            }
+            catch (final ServletException e)
+            {
+                throw new RegistrationFailureException(filterInfo, FAILURE_REASON_EXCEPTION_ON_INIT, e);
+            }
+        }
+        else
+        {
+            throw new RegistrationFailureException(filterInfo, FAILURE_REASON_SERVICE_NOT_GETTABLE);
         }
     }
 
@@ -140,9 +166,10 @@ public final class WhiteboardHttpService
      * Register a resource.
      * @param contextInfo The servlet context helper info
      * @param resourceInfo The resource info
+     * @throws RegistrationFailureException 
      */
     public void registerResource(@Nonnull final ContextHandler contextHandler,
-            @Nonnull final ResourceInfo resourceInfo)
+            @Nonnull final ResourceInfo resourceInfo) throws RegistrationFailureException
     {
     	final ServletInfo servletInfo = new ServletInfo(resourceInfo);
     	
@@ -159,7 +186,7 @@ public final class WhiteboardHttpService
     				registry.addServlet(handler);
     		}
     	} catch (ServletException e) {
-    		// TODO create failure DTO
+            throw new RegistrationFailureException(resourceInfo, FAILURE_REASON_EXCEPTION_ON_INIT, e);
     	}
     }
 
@@ -167,8 +194,9 @@ public final class WhiteboardHttpService
      * Unregister a resource.
      * @param contextInfo The servlet context helper info
      * @param resourceInfo The resource info
+     * @throws RegistrationFailureException 
      */
-    public void unregisterResource(@Nonnull final ContextHandler contextHandler, @Nonnull final ResourceInfo resourceInfo)
+    public void unregisterResource(@Nonnull final ContextHandler contextHandler, @Nonnull final ResourceInfo resourceInfo) throws RegistrationFailureException
     {
         final ServletInfo servletInfo = new ServletInfo(resourceInfo);
         final PerContextHandlerRegistry registry = this.handlerRegistry.getRegistry(contextHandler.getContextInfo());

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java Wed Mar 25 10:28:08 2015
@@ -19,7 +19,7 @@ package org.apache.felix.http.base.inter
 import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static javax.servlet.http.HttpServletResponse.SC_PAYMENT_REQUIRED;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -59,14 +59,14 @@ public class FilterHandlerTest extends A
         FilterHandler h2 = createHandler(10, "b");
         FilterHandler h3 = createHandler(10, "c");
 
-        assertEquals(0, h1.compareTo(h1));
+        assertTrue(h1.compareTo(h1) == 0);
 
-        assertEquals(1, h1.compareTo(h2));
-        assertEquals(-1, h2.compareTo(h1));
+        assertTrue(h1.compareTo(h2) > 0);
+        assertTrue(h2.compareTo(h1) < 0);
 
         // h2 is actually registered first, so should be called first...
-        assertEquals(-1, h2.compareTo(h3));
-        assertEquals(1, h3.compareTo(h2));
+        assertTrue(h2.compareTo(h3) < 0);
+        assertTrue(h3.compareTo(h2) > 0);
     }
 
     @Test

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistryTest.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistryTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistryTest.java Wed Mar 25 10:28:08 2015
@@ -17,6 +17,7 @@
 package org.apache.felix.http.base.internal.handler;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -32,7 +33,8 @@ import org.junit.Test;
 public class PerContextHandlerRegistryTest
 {
 
-    @Test public void testPathOrdering()
+    @Test
+    public void testPathOrdering()
     {
         final List<PerContextHandlerRegistry> list = new ArrayList<PerContextHandlerRegistry>();
         list.add(new PerContextHandlerRegistry(createServletContextHelperInfo("/", 1L, 0), null));
@@ -48,7 +50,8 @@ public class PerContextHandlerRegistryTe
         assertEquals(3L, list.get(3).getContextServiceId());
     }
 
-    @Test public void testRankingOrdering()
+    @Test
+    public void testRankingOrdering()
     {
         final List<PerContextHandlerRegistry> list = new ArrayList<PerContextHandlerRegistry>();
         list.add(new PerContextHandlerRegistry(createServletContextHelperInfo("/", 1L, 0), null));
@@ -64,7 +67,8 @@ public class PerContextHandlerRegistryTe
         assertEquals(3L, list.get(3).getContextServiceId());
     }
 
-    @Test public void testOrderingSymetry()
+    @Test
+    public void testOrderingSymetry()
     {
         testSymetry("/", "/foo", 1L, 2L, 0, 0);
         testSymetry("/", "/", 1L, 2L, 0, 10);
@@ -83,7 +87,8 @@ public class PerContextHandlerRegistryTe
         assertEquals(handlerRegistry.compareTo(other), -other.compareTo(handlerRegistry));
     }
 
-    @Test public void testOrderingTransitivity()
+    @Test
+    public void testOrderingTransitivity()
     {
         testTransitivity("/", "/foo", "/barrr", 1L, 2L, 3L, 0, 0, 0);
         testTransitivity("/", "/", "/", 0L, 1L, 2L, 1, 2, 3);
@@ -92,22 +97,18 @@ public class PerContextHandlerRegistryTe
         testTransitivity("/", "/", "/", -2L, -1L, 0L, 0, 0, 0);
     }
 
-    private void testTransitivity(String highPath, String midPath, String lowPath,
-            long highId, long midId, long lowId,
-            int highRanking, int midRanking, int lowRanking)
+    private void testTransitivity(String highPath, String midPath, String lowPath, long highId, long midId, long lowId, int highRanking, int midRanking, int lowRanking)
     {
         PerContextHandlerRegistry high = new PerContextHandlerRegistry(createServletContextHelperInfo(highPath, highId, highRanking), null);
         PerContextHandlerRegistry mid = new PerContextHandlerRegistry(createServletContextHelperInfo(midPath, midId, midRanking), null);
         PerContextHandlerRegistry low = new PerContextHandlerRegistry(createServletContextHelperInfo(lowPath, lowId, lowRanking), null);
 
-        assertEquals(1, high.compareTo(mid));
-        assertEquals(1, mid.compareTo(low));
-        assertEquals(1, high.compareTo(low));
+        assertTrue(high.compareTo(mid) > 0);
+        assertTrue(mid.compareTo(low) > 0);
+        assertTrue(high.compareTo(low) > 0);
     }
 
-    private ServletContextHelperInfo createServletContextHelperInfo(final String path,
-            final long serviceId,
-            final int ranking)
+    private ServletContextHelperInfo createServletContextHelperInfo(final String path, final long serviceId, final int ranking)
     {
         return WhiteboardServiceHelper.createContextInfo(ranking, serviceId, "", path, null);
     }

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java Wed Mar 25 10:28:08 2015
@@ -34,25 +34,28 @@ import javax.servlet.Servlet;
 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.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.HandlerRuntime.ErrorPage;
+import org.apache.felix.http.base.internal.runtime.dto.ErrorPageRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
+import org.osgi.framework.ServiceReference;
 
 public final class WhiteboardServiceHelper
 {
     public static final AtomicLong ID_COUNTER = new AtomicLong();
 
-    public static FilterHandler createTestFilterWithServiceId(String identifier,
+    public static FilterRuntime createTestFilterWithServiceId(String identifier,
             ExtServletContext context)
     {
         return createTestFilter(identifier, context, ID_COUNTER.incrementAndGet());
     }
 
-    public static FilterHandler createTestFilter(String identifier,
+    public static FilterRuntime createTestFilter(String identifier,
             ExtServletContext context)
     {
         return createTestFilter(identifier, context, -ID_COUNTER.incrementAndGet());
     }
 
-    private static FilterHandler createTestFilter(String identifier,
+    private static FilterRuntime createTestFilter(String identifier,
             ExtServletContext context,
             Long serviceId)
     {
@@ -94,18 +97,18 @@ public final class WhiteboardServiceHelp
         return info;
     }
 
-    public static ServletHandler createTestServletWithServiceId(String identifier,
+    public static ServletRuntime createTestServletWithServiceId(String identifier,
             ExtServletContext context)
     {
         return createTestServlet(identifier, context, ID_COUNTER.incrementAndGet());
     }
 
-    public static ServletHandler createTestServlet(String identifier, ExtServletContext context)
+    public static ServletRuntime createTestServlet(String identifier, ExtServletContext context)
     {
         return createTestServlet(identifier, context, -ID_COUNTER.incrementAndGet());
     }
 
-    private static ServletHandler createTestServlet(String identifier,
+    private static ServletRuntime createTestServlet(String identifier,
             ExtServletContext context,
             Long serviceId)
     {
@@ -136,7 +139,7 @@ public final class WhiteboardServiceHelp
                 serviceId,
                 name,
                 patterns,
-                null,
+                errorPages,
                 asyncSupported,
                 initParams);
     }
@@ -153,25 +156,25 @@ public final class WhiteboardServiceHelp
                 };
     }
 
-    public static ErrorPage createErrorPageWithServiceId(String identifier, ExtServletContext context)
+    public static ErrorPageRuntime createErrorPageWithServiceId(String identifier, ExtServletContext context)
     {
         return createErrorPage(identifier, context, ID_COUNTER.incrementAndGet());
     }
 
-    public static ErrorPage createErrorPage(String identifier, ExtServletContext context)
+    public static ErrorPageRuntime createErrorPage(String identifier, ExtServletContext context)
     {
         return createErrorPage(identifier, context, -ID_COUNTER.incrementAndGet());
     }
 
-    private static ErrorPage createErrorPage(String identifier,
+    private static ErrorPageRuntime createErrorPage(String identifier,
             ExtServletContext context,
             Long serviceId)
     {
-        ServletHandler servletHandler = createTestServlet(identifier, context, serviceId);
+        ServletRuntime servletHandler = createTestServlet(identifier, context, serviceId);
         Collection<Integer> errorCodes = Arrays.asList(400, 500);
         Collection<String> exceptions = Arrays.asList("Bad request", "Error");
 
-        return new ErrorPage(servletHandler, errorCodes, exceptions);
+        return new ErrorPageRuntime(servletHandler, errorCodes, exceptions);
     }
 
     public static ServletContextHelperInfo createContextInfo(int serviceRanking,
@@ -186,4 +189,9 @@ public final class WhiteboardServiceHelp
                 path,
                 initParams);
     }
+
+    public static ResourceInfo createContextInfo(ServiceReference<Object> ref)
+    {
+        return new ResourceInfo(ref);
+    }
 }