felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1669088 [1/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/...
Date Wed, 25 Mar 2015 10:28:10 GMT
Author: jawi
Date: Wed Mar 25 10:28:08 2015
New Revision: 1669088

URL: http://svn.apache.org/r1669088
Log:
FELIX-4546 - Implement HttpServiceRuntime service

- applied the patch from ThomasB.


Added:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactories.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactory.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureFilterRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletContextHelperRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextHelperRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/WhiteboardServiceRuntime.java   (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/RegistrationFailureException.java   (with props)
    felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/HttpServiceRuntimeTest.java   (with props)
Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ErrorsMapping.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
    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/handler/PerContextHandlerRegistry.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletContextDTOBuilder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ServletDTOBuilder.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/util/CollectionUtils.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistryTest.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
    felix/trunk/http/bundle/pom.xml
    felix/trunk/http/itest/pom.xml
    felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
    felix/trunk/http/itest/src/test/java/org/apache/felix/http/itest/EventListenerTest.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ErrorsMapping.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ErrorsMapping.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ErrorsMapping.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ErrorsMapping.java Wed Mar 25 10:28:08 2015
@@ -16,7 +16,7 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
-import static org.apache.felix.http.base.internal.util.CollectionUtils.union;
+import static org.apache.felix.http.base.internal.util.CollectionUtils.sortedUnion;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 
-import org.apache.felix.http.base.internal.runtime.HandlerRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.ErrorPageRuntime;
 
 public final class ErrorsMapping
 {
@@ -126,14 +126,14 @@ public final class ErrorsMapping
     @SuppressWarnings("unchecked")
     public Collection<ServletHandler> getMappedHandlers()
     {
-        return union(errorCodesMap.values(), exceptionsMap.values());
+        return sortedUnion(errorCodesMap.values(), exceptionsMap.values());
     }
 
-    public HandlerRuntime.ErrorPage getErrorPage(ServletHandler servletHandler)
+    public ErrorPageRuntime getErrorPage(ServletHandler servletHandler)
     {
         Collection<Integer> errorCodes = getCopy(servletHandler, invertedErrorCodesMap);
         Collection<String> exceptions = getCopy(servletHandler, invertedExceptionsMap);
-        return new HandlerRuntime.ErrorPage(servletHandler, errorCodes, exceptions);
+        return new ErrorPageRuntime(servletHandler, errorCodes, exceptions);
     }
 
     private static <T> List<T> getCopy(ServletHandler key, Map<Servlet, Collection<T>> map)

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java Wed Mar 25 10:28:08 2015
@@ -33,9 +33,10 @@ import javax.servlet.http.HttpServletRes
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 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.dto.FilterRuntime;
 import org.apache.felix.http.base.internal.util.PatternUtil;
 
-public final class FilterHandler extends AbstractHandler<FilterHandler>
+public final class FilterHandler extends AbstractHandler<FilterHandler> implements FilterRuntime
 {
     private final Filter filter;
     private final FilterInfo filterInfo;

Modified: 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/handler/HandlerRegistry.java?rev=1669088&r1=1669087&r2=1669088&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/handler/HandlerRegistry.java Wed Mar 25 10:28:08 2015
@@ -24,8 +24,9 @@ import java.util.List;
 import javax.annotation.Nonnull;
 import javax.servlet.DispatcherType;
 
-import org.apache.felix.http.base.internal.runtime.HandlerRuntime;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
+import org.apache.felix.http.base.internal.runtime.dto.ContextRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -225,12 +226,12 @@ public final class HandlerRegistry
         return null;
     }
 
-    public synchronized List<HandlerRuntime> getRuntime()
+    public synchronized List<ContextRuntime> getRuntime(FailureRuntime.Builder failureRuntimeBuilder)
     {
-        List<HandlerRuntime> handlerRuntimes = new ArrayList<HandlerRuntime>();
+        List<ContextRuntime> handlerRuntimes = new ArrayList<ContextRuntime>();
         for (PerContextHandlerRegistry contextRegistry : this.registrations)
         {
-            handlerRuntimes.add(contextRegistry.getRuntime());
+            handlerRuntimes.add(contextRegistry.getRuntime(failureRuntimeBuilder));
         }
         return handlerRuntimes;
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PerContextHandlerRegistry.java Wed Mar 25 10:28:08 2015
@@ -16,6 +16,10 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
+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_ALREAY_USED;
+import static org.osgi.service.http.runtime.dto.DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -23,6 +27,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedMap;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -35,30 +40,32 @@ import javax.servlet.Filter;
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 
-import org.apache.felix.http.base.internal.context.ExtServletContext;
 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.HandlerRuntime.ErrorPage;
 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.service.ResourceServlet;
+import org.apache.felix.http.base.internal.runtime.dto.ContextRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.ErrorPageRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.FailureRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
+import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
+import org.apache.felix.http.base.internal.whiteboard.ResourceServlet;
 import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.apache.felix.http.base.internal.whiteboard.ContextHandler;
+import org.apache.felix.http.base.internal.whiteboard.RegistrationFailureException;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceObjects;
 
 public final class PerContextHandlerRegistry implements Comparable<PerContextHandlerRegistry>
 {
-	private final BundleContext bundleContext;
+    private final BundleContext bundleContext;
 
     private final Map<Filter, FilterHandler> filterMap = new HashMap<Filter, FilterHandler>();
 
     private volatile HandlerMapping<ServletHandler> servletMapping = new HandlerMapping<ServletHandler>();
     private volatile HandlerMapping<FilterHandler> filterMapping = new HandlerMapping<FilterHandler>();
     private final ErrorsMapping errorsMapping = new ErrorsMapping();
-    
-    private SortedMap<Pattern, SortedSet<ServletHandler>> patternToServletHandler = new TreeMap<Pattern, SortedSet<ServletHandler>>(PatternUtil.PatternComparator.INSTANCE);
-    private Map<ServletHandler, Integer> servletHandlerToUses = new HashMap<ServletHandler, Integer>();
+
+    private final SortedMap<Pattern, SortedSet<ServletHandler>> patternToServletHandler = new TreeMap<Pattern, SortedSet<ServletHandler>>(PatternUtil.PatternComparator.INSTANCE);
+    private final Map<ServletHandler, Integer> servletHandlerToUses = new HashMap<ServletHandler, Integer>();
     private final SortedSet<ServletHandler> allServletHandlers = new TreeSet<ServletHandler>();
 
     private final long serviceId;
@@ -69,7 +76,8 @@ public final class PerContextHandlerRegi
 
     private final String prefix;
 
-    public PerContextHandlerRegistry(BundleContext bundleContext) {
+    public PerContextHandlerRegistry(BundleContext bundleContext)
+    {
         this.serviceId = 0;
         this.ranking = Integer.MAX_VALUE;
         this.path = "/";
@@ -83,22 +91,22 @@ public final class PerContextHandlerRegi
         this.ranking = info.getRanking();
         this.path = info.getPath();
         this.bundleContext = bundleContext;
-        if ( this.path.equals("/") )
+        if (this.path.equals("/"))
         {
-        	prefix = null;
+            prefix = null;
         }
         else
         {
-        	prefix = this.path + "/";
+            prefix = this.path + "/";
         }
     }
 
     public synchronized void addFilter(FilterHandler handler) throws ServletException
     {
-    	if(this.filterMapping.contains(handler))
-    	{
-    		throw new ServletException("Filter instance already registered");
-    	}
+        if (this.filterMapping.contains(handler))
+        {
+            throw new RegistrationFailureException(handler.getFilterInfo(), FAILURE_REASON_SERVICE_ALREAY_USED, "Filter instance " + handler.getName() + " already registered");
+        }
 
         handler.init();
         this.filterMapping = this.filterMapping.add(handler);
@@ -109,11 +117,12 @@ public final class PerContextHandlerRegi
     public int compareTo(final PerContextHandlerRegistry other)
     {
         final int result = Integer.compare(other.path.length(), this.path.length());
-        if ( result == 0 ) {
+        if (result == 0)
+        {
             if (this.ranking == other.ranking)
             {
                 // Service id's can be negative. Negative id's follow the reverse natural ordering of integers.
-                int reverseOrder = ( this.serviceId >= 0 && other.serviceId >= 0 ) ? 1 : -1;
+                int reverseOrder = (this.serviceId >= 0 && other.serviceId >= 0) ? 1 : -1;
                 return reverseOrder * Long.compare(this.serviceId, other.serviceId);
             }
 
@@ -127,63 +136,64 @@ public final class PerContextHandlerRegi
      */
     public synchronized void addServlet(final ServletHandler handler) throws ServletException
     {
-    	Pattern[] patterns = handler.getPatterns();
-    	String[] errorPages = handler.getServletInfo().getErrorPage();
-    	
-    	if(patterns.length > 0 && errorPages != null)
-    	{
-    		throw new ServletException("Servlet instance " + handler.getName() + " has both patterns and errorPage set");
-    	}
-    	
-    	SortedMap<Pattern, ServletHandler> toAdd = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
-    	SortedMap<Pattern, ServletHandler> toRemove = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
-    	
-    	this.servletHandlerToUses.put(handler, new Integer(0));
-    	
-    	for (Pattern p : patterns) 
-    	{
-    		ServletHandler prevHandler = null;
-
-    		if( !this.patternToServletHandler.containsKey(p))
-    		{
-    			this.patternToServletHandler.put(p, new TreeSet<ServletHandler>());
-    		}
-    		else
-    		{
-    			prevHandler = this.patternToServletHandler.get(p).first();
-    		}
-    		
-    		this.patternToServletHandler.get(p).add(handler);
-    		
-            if ( handler.equals(this.patternToServletHandler.get(p).first()))
-            {
-            	useServletHandler(handler);
-            	if (!handler.isWhiteboardService())
-            	{
-            		handler.init();
-            	}
-            	increaseUseCount(handler);
-
-            	if (prevHandler != null)
-            	{
-            		decreaseUseCount(prevHandler);
-            		toRemove.put(p, prevHandler);
-            	}
-            	toAdd.put(p, handler);
-            }
-    	}
-    	
-    	this.servletMapping = this.servletMapping.remove(toRemove);
-    	this.servletMapping = this.servletMapping.add(toAdd);
-    	this.allServletHandlers.add(handler);
-    	
-    	if(errorPages != null)
-    	{
-    		for(String errorPage : errorPages)
-    		{
-    			this.errorsMapping.addErrorServlet(errorPage, handler);
-    		}
-    	}
+        Pattern[] patterns = handler.getPatterns();
+        String[] errorPages = handler.getServletInfo().getErrorPage();
+
+        if (patterns.length > 0 && errorPages != null)
+        {
+            throw new ServletException("Servlet instance " + handler.getName() + " has both patterns and errorPage set");
+        }
+
+        SortedMap<Pattern, ServletHandler> toAdd = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
+        SortedMap<Pattern, ServletHandler> toRemove = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
+
+        this.servletHandlerToUses.put(handler, new Integer(0));
+
+        for (Pattern p : patterns)
+        {
+            ServletHandler prevHandler = null;
+
+            if (!this.patternToServletHandler.containsKey(p))
+            {
+                this.patternToServletHandler.put(p, new TreeSet<ServletHandler>());
+            }
+            else
+            {
+                prevHandler = this.patternToServletHandler.get(p).first();
+            }
+
+            this.patternToServletHandler.get(p).add(handler);
+
+            if (handler.equals(this.patternToServletHandler.get(p).first()))
+            {
+                useServletHandler(handler);
+                if (!handler.isWhiteboardService())
+                {
+                    handler.init();
+                }
+                increaseUseCount(handler);
+
+                if (prevHandler != null)
+                {
+                    decreaseUseCount(prevHandler);
+                    toRemove.put(p, prevHandler);
+                }
+                toAdd.put(p, handler);
+            }
+        }
+
+        this.servletMapping = this.servletMapping.remove(toRemove);
+        this.servletMapping = this.servletMapping.add(toAdd);
+        this.allServletHandlers.add(handler);
+
+        if (errorPages != null)
+        {
+            for (String errorPage : errorPages)
+            {
+                useServletHandler(handler);
+                this.errorsMapping.addErrorServlet(errorPage, handler);
+            }
+        }
     }
 
     /**
@@ -194,80 +204,83 @@ public final class PerContextHandlerRegi
      * @param handler
      * @throws ServletException
      */
-    private void useServletHandler(ServletHandler handler) throws ServletException 
+    private void useServletHandler(ServletHandler handler) throws ServletException
+    {
+        if ((!handler.isWhiteboardService()) || (handler.getServlet() != null))
+        {
+            return;
+        }
+
+        // isWhiteboardService && servlet == null
+        boolean isResource = handler.getServletInfo().isResource();
+        final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(handler.getServletInfo().getServiceReference());
+
+        Servlet servlet = getServiceObject(so, handler, isResource);
+        handler.setServlet(servlet);
+
+        try
+        {
+            handler.init();
+        }
+        catch (ServletException e)
+        {
+            ungetServiceObject(so, servlet, isResource);
+            throw e;
+        }
+    }
+
+    private Servlet getServiceObject(ServiceObjects<Servlet> so, ServletHandler handler, boolean isResource)
     {
-    	if( (!handler.isWhiteboardService()) || (handler.getServlet() != null) )
-    	{
-    		return;
-    	}
-    	
-    	// isWhiteboardService && servlet == null
-    	boolean isResource = handler.getServletInfo().isResource();
-    	final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(handler.getServletInfo().getServiceReference());
-    	
-    	Servlet servlet = getServiceObject(so, handler, isResource);
-    	handler.setServlet(servlet);
-    	
-    	try {
-			handler.init();
-		} catch (ServletException e) {
-			ungetServiceObject(so, servlet, isResource);
-			throw e;
-		}
-	}
-	
-	private Servlet getServiceObject(ServiceObjects<Servlet> so, ServletHandler handler, boolean isResource)
-	{
-		if(isResource) 
-		{
-			return new ResourceServlet(handler.getServletInfo().getPrefix());
-		}
-		if(so != null)
-		{
-			return so.getService();
-		}
-		return null;
-	}
-	
-	private void ungetServiceObject(ServiceObjects<Servlet> so, Servlet servlet, boolean isResource)
-	{
-		if(isResource || (so == null))
-		{
-			return;
-		}
-		so.ungetService(servlet);
-	}
-
-	private void increaseUseCount(ServletHandler handler) 
-	{
-		Integer uses = this.servletHandlerToUses.get(handler);
-		if(uses != null)
-		{
-			int newUsesValue = uses.intValue() + 1;
-			this.servletHandlerToUses.put(handler, new Integer(newUsesValue));
-		}
-	}
-	
-	private void decreaseUseCount(@Nonnull ServletHandler handler)
-	{
-		Integer uses = this.servletHandlerToUses.get(handler);
-		if(uses != null)
-		{
-			int newUsesValue = uses.intValue() - 1;
-			if(newUsesValue == 0 && handler.isWhiteboardService())
-			{		
-				// if the servlet is no longer used and it is registered as a whiteboard service
-				// call destroy, unget the service object and set the servlet in the handler to null
-				handler.destroy();
-				ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(handler.getServletInfo().getServiceReference());
-				ungetServiceObject(so, handler.getServlet(), handler.getServletInfo().isResource());
-				handler.setServlet(null);
-			}
-			this.servletHandlerToUses.put(handler, new Integer(newUsesValue));	
-		}
-	}
+        if (isResource)
+        {
+            return new ResourceServlet(handler.getServletInfo().getPrefix());
+        }
+        if (so != null)
+        {
+            return so.getService();
+        }
+        return null;
+    }
 
-	public ErrorsMapping getErrorsMapping()
+    private void ungetServiceObject(ServiceObjects<Servlet> so, Servlet servlet, boolean isResource)
+    {
+        if (isResource || (so == null))
+        {
+            return;
+        }
+        so.ungetService(servlet);
+    }
+
+    private void increaseUseCount(ServletHandler handler)
+    {
+        Integer uses = this.servletHandlerToUses.get(handler);
+        if (uses != null)
+        {
+            int newUsesValue = uses.intValue() + 1;
+            this.servletHandlerToUses.put(handler, new Integer(newUsesValue));
+        }
+    }
+
+    private void decreaseUseCount(@Nonnull ServletHandler handler)
+    {
+        Integer uses = this.servletHandlerToUses.get(handler);
+        if (uses != null)
+        {
+            int newUsesValue = uses.intValue() - 1;
+            if (newUsesValue == 0 && handler.isWhiteboardService())
+            {
+                // if the servlet is no longer used and it is registered as a whiteboard service
+                // call destroy, unget the service object and set the servlet in the handler to null
+                handler.destroy();
+                ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(handler.getServletInfo().getServiceReference());
+                ungetServiceObject(so, handler.getServlet(), handler.getServletInfo().isResource());
+                handler.setServlet(null);
+            }
+            this.servletHandlerToUses.put(handler, new Integer(newUsesValue));
+        }
+    }
+
+    public ErrorsMapping getErrorsMapping()
     {
         return this.errorsMapping;
     }
@@ -300,10 +313,10 @@ public final class PerContextHandlerRegi
 
         // TODO - we should already check for the context when building up the result set
         final Iterator<FilterHandler> i = result.iterator();
-        while ( i.hasNext() )
+        while (i.hasNext())
         {
             final FilterHandler handler = i.next();
-            if ( handler.getContextServiceId() != servletHandler.getContextServiceId() )
+            if (handler.getContextServiceId() != servletHandler.getContextServiceId())
             {
                 i.remove();
             }
@@ -378,105 +391,107 @@ public final class PerContextHandlerRegi
 
     private FilterHandler getFilterHandler(final FilterInfo filterInfo)
     {
-        for(final FilterHandler handler : this.filterMap.values())
+        for (final FilterHandler handler : this.filterMap.values())
         {
-            if ( handler.getFilterInfo().compareTo(filterInfo) == 0)
+            if (handler.getFilterInfo().compareTo(filterInfo) == 0)
             {
                 return handler;
             }
         }
         return null;
     }
-    
-    public synchronized Servlet removeServlet(ServletInfo servletInfo, final boolean destroy)
+
+    public synchronized Servlet removeServlet(ServletInfo servletInfo, final boolean destroy) throws RegistrationFailureException
     {
-    	ServletHandler handler = getServletHandler(servletInfo);
-    	
-    	Pattern[] patterns = (handler == null) ? new Pattern[0] : handler.getPatterns();
-    	SortedMap<Pattern, ServletHandler> toAdd = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
-    	SortedMap<Pattern, ServletHandler> toRemove = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
-
-    	for(Pattern p : patterns)
-    	{    		
-    		SortedSet<ServletHandler> handlers = this.patternToServletHandler.get(p);
-    		if(handlers != null && (!handlers.isEmpty()))
-    		{
-    			if(handlers.first().equals(handler))
-    			{
-    				toRemove.put(p, handler);
-    			}
-    			handlers.remove(handler);
-    			
-    			ServletHandler activeHandler = null;
-    			if( !handlers.isEmpty() )
-    			{
-    				activeHandler = handlers.first();
-    				
-    				try {
-    					useServletHandler(activeHandler);
-						increaseUseCount(activeHandler);
-						toAdd.put(p, activeHandler);
-					} catch (ServletException e) {
-						// TODO: next servlet handling this pattern could not be initialized, it belongs to failure DTOs
-					}
-    			}
-    			else 
-    			{
-    				this.patternToServletHandler.remove(p);
-				}
-    		}
-    	}
-    	
-    	Servlet servlet = null;
-    	if(handler != null)
-    	{
-    		servlet = handler.getServlet();
-    		if(destroy)
-    		{
-    			servlet.destroy();
-    		}
-    		if(handler.isWhiteboardService())
-    		{
-    			ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(handler.getServletInfo().getServiceReference());
-    			ungetServiceObject(so, servlet, servletInfo.isResource());
-    		}
-    	}
-    	
-    	this.servletHandlerToUses.remove(handler);
-    	
-		this.servletMapping = this.servletMapping.remove(toRemove);
-		this.servletMapping = this.servletMapping.add(toAdd);
+        ServletHandler handler = getServletHandler(servletInfo);
+
+        Pattern[] patterns = (handler == null) ? new Pattern[0] : handler.getPatterns();
+        SortedMap<Pattern, ServletHandler> toAdd = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
+        SortedMap<Pattern, ServletHandler> toRemove = new TreeMap<Pattern, ServletHandler>(PatternUtil.PatternComparator.INSTANCE);
+
+        for (Pattern p : patterns)
+        {
+            SortedSet<ServletHandler> handlers = this.patternToServletHandler.get(p);
+            if (handlers != null && (!handlers.isEmpty()))
+            {
+                if (handlers.first().equals(handler))
+                {
+                    toRemove.put(p, handler);
+                }
+                handlers.remove(handler);
+
+                ServletHandler activeHandler = null;
+                if (!handlers.isEmpty())
+                {
+                    activeHandler = handlers.first();
+
+                    try
+                    {
+                        useServletHandler(activeHandler);
+                        increaseUseCount(activeHandler);
+                        toAdd.put(p, activeHandler);
+                    }
+                    catch (ServletException e)
+                    {
+                        throw new RegistrationFailureException(activeHandler.getServletInfo(), FAILURE_REASON_EXCEPTION_ON_INIT, e);
+                    }
+                }
+                else
+                {
+                    this.patternToServletHandler.remove(p);
+                }
+            }
+        }
+
+        Servlet servlet = null;
+        if (handler != null && handler.getServlet() != null)
+        {
+            servlet = handler.getServlet();
+            if (destroy)
+            {
+                servlet.destroy();
+            }
+            if (handler.isWhiteboardService())
+            {
+                ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(handler.getServletInfo().getServiceReference());
+                ungetServiceObject(so, servlet, servletInfo.isResource());
+            }
+        }
+
+        this.servletHandlerToUses.remove(handler);
 
-		return servlet;
+        this.servletMapping = this.servletMapping.remove(toRemove);
+        this.servletMapping = this.servletMapping.add(toAdd);
+
+        return servlet;
     }
 
     private ServletHandler getServletHandler(final ServletInfo servletInfo)
     {
-    	Iterator<ServletHandler> it = this.allServletHandlers.iterator();
-    	while(it.hasNext())
-    	{
-    		ServletHandler handler = it.next();
-    		if(handler.getServletInfo().compareTo(servletInfo) == 0)
-    		{
-    			return handler;
-    		}
-    	}
-    	return null;
-    }
-    
-    public synchronized void removeServlet(Servlet servlet, final boolean destroy)
-    {
-    	Iterator<ServletHandler> it = this.allServletHandlers.iterator();
-    	while(it.hasNext())
-    	{
-    		ServletHandler handler = it.next();
-    		if(handler.getServlet() == servlet) 
-    		{
-    			removeServlet(handler.getServletInfo(), destroy);
-    		}
-    	}
+        Iterator<ServletHandler> it = this.allServletHandlers.iterator();
+        while (it.hasNext())
+        {
+            ServletHandler handler = it.next();
+            if (handler.getServletInfo().compareTo(servletInfo) == 0)
+            {
+                return handler;
+            }
+        }
+        return null;
+    }
+
+    public synchronized void removeServlet(Servlet servlet, final boolean destroy) throws RegistrationFailureException
+    {
+        Iterator<ServletHandler> it = this.allServletHandlers.iterator();
+        while (it.hasNext())
+        {
+            ServletHandler handler = it.next();
+            if (handler.getServlet() == servlet)
+            {
+                removeServlet(handler.getServletInfo(), destroy);
+            }
+        }
     }
-    
 
     private boolean referencesDispatcherType(FilterHandler handler, DispatcherType dispatcherType)
     {
@@ -499,17 +514,17 @@ public final class PerContextHandlerRegi
 
     public String isMatching(final String requestURI)
     {
-        if ( requestURI.equals(this.path) )
+        if (requestURI.equals(this.path))
         {
-        	return "";
+            return "";
         }
-        if ( this.prefix == null )
+        if (this.prefix == null)
         {
-        	return requestURI;
+            return requestURI;
         }
-        if ( requestURI.startsWith(this.prefix) )
+        if (requestURI.startsWith(this.prefix))
         {
-        	return requestURI.substring(this.prefix.length() - 1);
+            return requestURI.substring(this.prefix.length() - 1);
         }
         return null;
     }
@@ -519,34 +534,42 @@ public final class PerContextHandlerRegi
         return this.serviceId;
     }
 
-    public synchronized HandlerRuntime getRuntime() {
-        Collection<ErrorPage> errorPages = new ArrayList<HandlerRuntime.ErrorPage>();
+    public synchronized ContextRuntime getRuntime(FailureRuntime.Builder failureRuntimeBuilder)
+    {
+        Collection<ErrorPageRuntime> errorPages = new TreeSet<ErrorPageRuntime>(ServletRuntime.COMPARATOR);
         Collection<ServletHandler> errorHandlers = errorsMapping.getMappedHandlers();
         for (ServletHandler servletHandler : errorHandlers)
         {
             errorPages.add(errorsMapping.getErrorPage(servletHandler));
         }
 
-        List<FilterHandler> filterHandlers = new ArrayList<FilterHandler>(filterMap.values());
+        Collection<FilterRuntime> filterRuntimes = new TreeSet<FilterRuntime>(FilterRuntime.COMPARATOR);
+        for (FilterRuntime filterRuntime : filterMap.values())
+        {
+            filterRuntimes.add(filterRuntime);
+        }
 
-        List<ServletHandler> servletHandlers = new ArrayList<ServletHandler>();
-        List<ServletHandler> resourceHandlers = new ArrayList<ServletHandler>();
-        
-        Iterator<ServletHandler> it = this.allServletHandlers.iterator();
-        while(it.hasNext())
+        Collection<ServletRuntime> servletRuntimes = new TreeSet<ServletRuntime>(ServletRuntime.COMPARATOR);
+        Collection<ServletRuntime> resourceRuntimes = new TreeSet<ServletRuntime>(ServletRuntime.COMPARATOR);
+
+        for (Set<ServletHandler> patternHandlers : patternToServletHandler.values())
         {
-        	ServletHandler servletHandler = it.next();
-        	
-        	if (servletHandler.getServletInfo().isResource())
+            Iterator<ServletHandler> itr = patternHandlers.iterator();
+            ServletHandler activeHandler = itr.next();
+            if (activeHandler.getServletInfo().isResource())
             {
-                resourceHandlers.add(servletHandler);
+                resourceRuntimes.add(activeHandler);
             }
-            else if (!errorHandlers.contains(servletHandler))
+            else
             {
-                servletHandlers.add(servletHandler);
+                servletRuntimes.add(activeHandler);
+            }
+            while (itr.hasNext())
+            {
+                failureRuntimeBuilder.add(itr.next().getServletInfo(), FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
             }
         }
 
-        return new HandlerRuntime(servletHandlers, filterHandlers, resourceHandlers, errorPages, serviceId);
-    }    
+        return new ContextRuntime(servletRuntimes, filterRuntimes, resourceRuntimes, errorPages, serviceId);
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java Wed Mar 25 10:28:08 2015
@@ -31,12 +31,13 @@ import javax.servlet.http.HttpServletRes
 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.ServletInfo;
+import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
 import org.apache.felix.http.base.internal.util.PatternUtil;
 
 /**
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class ServletHandler extends AbstractHandler<ServletHandler>
+public final class ServletHandler extends AbstractHandler<ServletHandler> implements ServletRuntime
 {
     private final ServletInfo servletInfo;
 

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java Wed Mar 25 10:28:08 2015
@@ -49,11 +49,11 @@ public abstract class AbstractInfo<T> im
 
     public AbstractInfo(final ServiceReference<T> ref)
     {
-        this.serviceId = (Long)ref.getProperty(Constants.SERVICE_ID);
+        this.serviceId = (Long) ref.getProperty(Constants.SERVICE_ID);
         final Object rankingObj = ref.getProperty(Constants.SERVICE_RANKING);
-        if ( rankingObj instanceof Integer )
+        if (rankingObj instanceof Integer)
         {
-            this.ranking = (Integer)rankingObj;
+            this.ranking = (Integer) rankingObj;
         }
         else
         {
@@ -88,7 +88,7 @@ public abstract class AbstractInfo<T> im
             int reverseOrder = ( this.serviceId >= 0 && other.serviceId >= 0 ) ? 1 : -1;
             return reverseOrder * Long.compare(this.serviceId, other.serviceId);
         }
-
+        
         return Integer.compare(other.ranking, this.ranking);
     }
 
@@ -105,7 +105,7 @@ public abstract class AbstractInfo<T> im
     protected String getStringProperty(final ServiceReference<T> ref, final String key)
     {
         final Object value = ref.getProperty(key);
-        return (value instanceof String) ? ((String) value).trim(): null;
+        return (value instanceof String) ? ((String) value).trim() : null;
     }
 
     protected String[] getStringArrayProperty(ServiceReference<T> ref, String key)
@@ -118,12 +118,12 @@ public abstract class AbstractInfo<T> im
         }
         else if (value instanceof String[])
         {
-        	final String[] arr = (String[]) value;
-        	String[] values = new String[arr.length];
-        	
-            for(int i=0, j=0; i<arr.length; i++)
+            final String[] arr = (String[]) value;
+            String[] values = new String[arr.length];
+
+            for (int i = 0, j = 0; i < arr.length; i++)
             {
-                if ( arr[i] != null )
+                if (arr[i] != null)
                 {
                     values[j++] = arr[i].trim();
                 }
@@ -169,7 +169,7 @@ public abstract class AbstractInfo<T> im
         final Map<String, String> result = new HashMap<String, String>();
         for (final String key : ref.getPropertyKeys())
         {
-            if ( key.startsWith(prefix))
+            if (key.startsWith(prefix))
             {
                 final String paramKey = key.substring(prefix.length());
                 final String paramValue = getStringProperty(ref, key);
@@ -205,10 +205,10 @@ public abstract class AbstractInfo<T> im
 
     public T getService(final Bundle bundle)
     {
-        if ( this.serviceReference != null )
+        if (this.serviceReference != null)
         {
             final ServiceObjects<T> so = bundle.getBundleContext().getServiceObjects(this.serviceReference);
-            if ( so != null )
+            if (so != null)
             {
                 return so.getService();
             }
@@ -218,10 +218,10 @@ public abstract class AbstractInfo<T> im
 
     public void ungetService(final Bundle bundle, final T service)
     {
-        if ( this.serviceReference != null )
+        if (this.serviceReference != null)
         {
             final ServiceObjects<T> so = bundle.getBundleContext().getServiceObjects(this.serviceReference);
-            if ( so != null )
+            if (so != null)
             {
                 so.ungetService(service);
             }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java Wed Mar 25 10:28:08 2015
@@ -157,7 +157,7 @@ public class ServletInfo extends Whitebo
     @Override
     public boolean isValid()
     {
-        return super.isValid() && (!isEmpty(this.patterns) || !isEmpty(this.errorPage));
+        return super.isValid() && (isEmpty(this.patterns) ^ isEmpty(this.errorPage));
     }
 
     public String getName()

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -29,7 +29,14 @@ import org.osgi.dto.DTO;
 
 abstract class BaseDTOBuilder<T, U extends DTO>
 {
-    public Collection<U> build(Collection<T> whiteboardServices, long servletContextId)
+    private DTOFactory<U> dtoFactory;
+
+    BaseDTOBuilder(DTOFactory<U> dtoFactory)
+    {
+        this.dtoFactory = dtoFactory;
+    }
+
+    Collection<U> build(Collection<T> whiteboardServices, long servletContextId)
     {
         List<U> dtoList = new ArrayList<U>();
         for (T whiteboardService : whiteboardServices)
@@ -41,7 +48,12 @@ abstract class BaseDTOBuilder<T, U exten
 
     abstract U buildDTO(T whiteboardService, long servletContextId);
 
-    protected <V> V[] copyWithDefault(V[] array, V[] defaultArray)
+    DTOFactory<U> getDTOFactory()
+    {
+        return dtoFactory;
+    }
+
+    <V> V[] copyWithDefault(V[] array, V[] defaultArray)
     {
         return array == null ? defaultArray : copyOf(array, array.length);
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -20,23 +20,45 @@ package org.apache.felix.http.base.inter
 
 import javax.servlet.Servlet;
 
-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.BaseServletDTO;
 
-abstract class BaseServletDTOBuilder<T, U extends BaseServletDTO> extends BaseDTOBuilder<T, U>
+abstract class BaseServletDTOBuilder<T extends ServletRuntime, U extends BaseServletDTO> extends BaseDTOBuilder<T, U>
 {
-    final U setBaseFields(U dto, ServletHandler servletHandler, long servletContextId)
+    BaseServletDTOBuilder(DTOFactory<U> servletDTOFactory)
     {
-        ServletInfo info = servletHandler.getServletInfo();
-        Servlet servlet = servletHandler.getServlet();
+        super(servletDTOFactory);
+    }
+
+    @Override
+    U buildDTO(T servletRuntime, long servletContextId)
+    {
+        ServletInfo info = servletRuntime.getServletInfo();
+        Servlet servlet = servletRuntime.getServlet();
 
+        U dto = getDTOFactory().get();
         dto.asyncSupported = info.isAsyncSupported();
         dto.initParams = info.getInitParameters();
-        dto.name = info.getName();
-        dto.serviceId = servletHandler.getServletInfo().getServiceId();
+        dto.name = getName(info, servlet);
+        dto.serviceId = servletRuntime.getServletInfo().getServiceId();
         dto.servletContextId = servletContextId;
-        dto.servletInfo = servlet.getServletInfo();
+        dto.servletInfo = servlet != null ? servlet.getServletInfo() : null;
         return dto;
     }
+
+    private String getName(ServletInfo info, Servlet servlet)
+    {
+        String name = info.getName();
+        if (name != null)
+        {
+            return name;
+        }
+
+        if (servlet != null)
+        {
+            return servlet.getServletConfig().getServletName();
+        }
+
+        return null;
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java Wed Mar 25 10:28:08 2015
@@ -19,6 +19,12 @@
 package org.apache.felix.http.base.internal.runtime.dto;
 
 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;
@@ -37,4 +43,12 @@ public abstract class BuilderConstants
     public static final FilterDTO[] FILTER_DTO_ARRAY = new FilterDTO[0];
     public static final ErrorPageDTO[] ERROR_PAGE_DTO_ARRAY = new ErrorPageDTO[0];
     public static final ListenerDTO[] LISTENER_DTO_ARRAY = new ListenerDTO[0];
+
+    public static final FailedServletContextDTO[] CONTEXT_FAILURE_DTO_ARRAY = new FailedServletContextDTO[0];
+
+    public static final FailedServletDTO[] SERVLET_FAILURE_DTO_ARRAY = new FailedServletDTO[0];
+    public static final FailedFilterDTO[] FILTER_FAILURE_DTO_ARRAY = new FailedFilterDTO[0];
+    public static final FailedResourceDTO[] RESOURCE_FAILURE_DTO_ARRAY = new FailedResourceDTO[0];
+    public static final FailedErrorPageDTO[] ERROR_PAGE_FAILURE_DTO_ARRAY = new FailedErrorPageDTO[0];
+    public static final FailedListenerDTO[] LISTENER_FAILURE_DTO_ARRAY = new FailedListenerDTO[0];
 }

Added: 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=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ContextRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,78 @@
+/*
+ * 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.Collection;
+import java.util.Collections;
+
+public final class ContextRuntime
+{
+    private final Collection<ServletRuntime> servletRuntimes;
+    private final Collection<FilterRuntime> filterRuntimes;
+    private final Collection<ServletRuntime> resourceRuntimes;
+    private final Collection<ErrorPageRuntime> errorPageRuntimes;
+    private final long serviceId;
+
+    public ContextRuntime(Collection<ServletRuntime> servletRuntimes,
+            Collection<FilterRuntime> filterRuntimes,
+            Collection<ServletRuntime> resourceRuntimes,
+            Collection<ErrorPageRuntime> errorPageRuntimes,
+            long serviceId)
+    {
+        this.servletRuntimes = servletRuntimes;
+        this.filterRuntimes = filterRuntimes;
+        this.resourceRuntimes = resourceRuntimes;
+        this.errorPageRuntimes = errorPageRuntimes;
+        this.serviceId = serviceId;
+    }
+
+    public static ContextRuntime empty(long serviceId)
+    {
+        return new ContextRuntime(Collections.<ServletRuntime>emptyList(),
+                Collections.<FilterRuntime>emptyList(),
+                Collections.<ServletRuntime>emptyList(),
+                Collections.<ErrorPageRuntime> emptyList(),
+                serviceId);
+    }
+
+    public Collection<ServletRuntime> getServletRuntimes()
+    {
+        return servletRuntimes;
+    }
+
+    public Collection<FilterRuntime> getFilterRuntimes()
+    {
+        return filterRuntimes;
+    }
+
+    public Collection<ServletRuntime> getResourceRuntimes()
+    {
+        return resourceRuntimes;
+    }
+
+    public Collection<ErrorPageRuntime> getErrorPageRuntimes()
+    {
+        return errorPageRuntimes;
+    }
+
+    public long getServiceId()
+    {
+        return serviceId;
+    }
+}

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

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactories.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactories.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactories.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactories.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,123 @@
+/*
+ * 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 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.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;
+import org.osgi.service.http.runtime.dto.ServletDTO;
+
+final class DTOFactories
+{
+    static final DTOFactory<ServletDTO> SERVLET = new DTOFactory<ServletDTO>()
+    {
+        @Override
+        public ServletDTO get()
+        {
+            return new ServletDTO();
+        }
+    };
+
+    static final DTOFactory<FailedServletDTO> FAILED_SERVLET = new DTOFactory<FailedServletDTO>()
+    {
+        @Override
+        public FailedServletDTO get()
+        {
+            return new FailedServletDTO();
+        }
+    };
+
+    static final DTOFactory<FilterDTO> FILTER = new DTOFactory<FilterDTO>()
+    {
+        @Override
+        public FilterDTO get()
+        {
+            return new FilterDTO();
+        }
+    };
+
+    static final DTOFactory<FailedFilterDTO> FAILED_FILTER = new DTOFactory<FailedFilterDTO>()
+    {
+        @Override
+        public FailedFilterDTO get()
+        {
+            return new FailedFilterDTO();
+        }
+    };
+
+    static final DTOFactory<ResourceDTO> RESOURCE = new DTOFactory<ResourceDTO>()
+    {
+        @Override
+        public ResourceDTO get()
+        {
+            return new ResourceDTO();
+        }
+    };
+
+    static final DTOFactory<FailedResourceDTO> FAILED_RESOURCE = new DTOFactory<FailedResourceDTO>()
+    {
+        @Override
+        public FailedResourceDTO get()
+        {
+            return new FailedResourceDTO();
+        }
+    };
+
+    static final DTOFactory<ListenerDTO> LISTENER = new DTOFactory<ListenerDTO>()
+    {
+        @Override
+        public ListenerDTO get()
+        {
+            return new ListenerDTO();
+        }
+    };
+
+    static final DTOFactory<FailedListenerDTO> FAILED_LISTENER = new DTOFactory<FailedListenerDTO>()
+    {
+        @Override
+        public FailedListenerDTO get()
+        {
+            return new FailedListenerDTO();
+        }
+    };
+
+    static final DTOFactory<ErrorPageDTO> ERROR_PAGE = new DTOFactory<ErrorPageDTO>()
+    {
+        @Override
+        public ErrorPageDTO get()
+        {
+            return new ErrorPageDTO();
+        }
+    };
+
+    static final DTOFactory<FailedErrorPageDTO> FAILED_ERROR_PAGE = new DTOFactory<FailedErrorPageDTO>()
+    {
+        @Override
+        public FailedErrorPageDTO get()
+        {
+            return new FailedErrorPageDTO();
+        }
+    };
+}

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

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactory.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactory.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/DTOFactory.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,24 @@
+/*
+ * 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 DTOFactory<T>
+{
+    T get();
+}

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

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java?rev=1669088&r1=1669087&r2=1669088&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java Wed Mar 25 10:28:08 2015
@@ -21,16 +21,24 @@ package org.apache.felix.http.base.inter
 import java.util.Collection;
 import java.util.Iterator;
 
-import org.apache.felix.http.base.internal.runtime.HandlerRuntime.ErrorPage;
 import org.osgi.service.http.runtime.dto.ErrorPageDTO;
 
-final class ErrorPageDTOBuilder extends BaseServletDTOBuilder<ErrorPage, ErrorPageDTO>
+final class ErrorPageDTOBuilder<T extends ErrorPageDTO> extends BaseServletDTOBuilder<ErrorPageRuntime, T>
 {
+    static ErrorPageDTOBuilder<ErrorPageDTO> create()
+    {
+        return new ErrorPageDTOBuilder<ErrorPageDTO>(DTOFactories.ERROR_PAGE);
+    }
+
+    ErrorPageDTOBuilder(DTOFactory<T> dtoFactory)
+    {
+        super(dtoFactory);
+    }
+
     @Override
-    ErrorPageDTO buildDTO(ErrorPage errorPage, long servletConextId)
+    T buildDTO(ErrorPageRuntime errorPage, long servletConextId)
     {
-        ErrorPageDTO errorPageDTO = new ErrorPageDTO();
-        setBaseFields(errorPageDTO, errorPage.getServletHandler(), servletConextId);
+        T errorPageDTO = super.buildDTO(errorPage, servletConextId);
         errorPageDTO.errorCodes = getErrorCodes(errorPage.getErrorCodes());
         errorPageDTO.exceptions = errorPage.getExceptions().toArray(BuilderConstants.STRING_ARRAY);
         return errorPageDTO;

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,94 @@
+/*
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import javax.servlet.Servlet;
+
+import org.apache.felix.http.base.internal.runtime.ServletInfo;
+
+public class ErrorPageRuntime implements ServletRuntime
+{
+    private static final Pattern ERROR_CODE_PATTERN = Pattern.compile("\\d{3}");
+
+    private final ServletRuntime servletRuntime;
+    private final Collection<Integer> errorCodes;
+    private final Collection<String> exceptions;
+
+    public ErrorPageRuntime(ServletRuntime servletRuntime,
+            Collection<Integer> errorCodes,
+            Collection<String> exceptions)
+    {
+        this.servletRuntime = servletRuntime;
+        this.errorCodes = errorCodes;
+        this.exceptions = exceptions;
+    }
+
+    public static ErrorPageRuntime fromRuntime(ServletRuntime servletRuntime)
+    {
+        List<Integer> errorCodes = new ArrayList<Integer>();
+        List<String> exceptions = new ArrayList<String>();
+
+        for (String string : servletRuntime.getServletInfo().getErrorPage())
+        {
+            if (ERROR_CODE_PATTERN.matcher(string).matches())
+            {
+                errorCodes.add(Integer.valueOf(string));
+            }
+            else
+            {
+                exceptions.add(string);
+            }
+        }
+
+        return new ErrorPageRuntime(servletRuntime, errorCodes, exceptions);
+    }
+
+    public Collection<Integer> getErrorCodes()
+    {
+        return errorCodes;
+    }
+
+    public Collection<String> getExceptions()
+    {
+        return exceptions;
+    }
+
+    @Override
+    public long getContextServiceId()
+    {
+        return servletRuntime.getContextServiceId();
+    }
+
+    @Override
+    public Servlet getServlet()
+    {
+        return servletRuntime.getServlet();
+    }
+
+    @Override
+    public ServletInfo getServletInfo()
+    {
+        return servletRuntime.getServletInfo();
+    }
+}
\ No newline at end of file

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

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureFilterRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureFilterRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureFilterRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureFilterRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.felix.http.base.internal.runtime.FilterInfo;
+
+
+
+public class FailureFilterRuntime implements FilterRuntime
+{
+    private final FilterInfo filterInfo;
+
+    FailureFilterRuntime(FilterInfo FilterInfo)
+    {
+        this.filterInfo = FilterInfo;
+    }
+
+    @Override
+    public FilterInfo getFilterInfo()
+    {
+        return filterInfo;
+    }
+
+    @Override
+    public long getContextServiceId()
+    {
+        return 0L;
+    }
+}

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

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,318 @@
+/*
+ * 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.apache.felix.http.base.internal.runtime.dto.BuilderConstants.CONTEXT_FAILURE_DTO_ARRAY;
+import static org.apache.felix.http.base.internal.runtime.dto.BuilderConstants.ERROR_PAGE_FAILURE_DTO_ARRAY;
+import static org.apache.felix.http.base.internal.runtime.dto.BuilderConstants.FILTER_FAILURE_DTO_ARRAY;
+import static org.apache.felix.http.base.internal.runtime.dto.BuilderConstants.LISTENER_FAILURE_DTO_ARRAY;
+import static org.apache.felix.http.base.internal.runtime.dto.BuilderConstants.RESOURCE_FAILURE_DTO_ARRAY;
+import static org.apache.felix.http.base.internal.runtime.dto.BuilderConstants.SERVLET_FAILURE_DTO_ARRAY;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+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.ListenerInfo;
+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.ServiceReference;
+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;
+
+public final class FailureRuntime
+{
+    private static final FailureComparator<ErrorPageRuntime> ERROR_PAGE_COMPARATOR = FailureComparator.<ErrorPageRuntime>create(ServletRuntime.COMPARATOR);
+    private static final FailureComparator<FilterRuntime> FILTER_COMPARATOR = FailureComparator.create(FilterRuntime.COMPARATOR);
+    private static final FailureComparator<ServletContextHelperRuntime> CONTEXT_COMPARATOR = FailureComparator.create(ServletContextHelperRuntime.COMPARATOR);
+    private static final FailureComparator<ServletRuntime> SERVLET_COMPARATOR = FailureComparator.create(ServletRuntime.COMPARATOR);
+    private static final Comparator<Failure<ServiceReference<?>>> REFERENCE_COMPARATOR = new Comparator<Failure<ServiceReference<?>>>()
+    {
+        @Override
+        public int compare(Failure<ServiceReference<?>> o1, Failure<ServiceReference<?>> o2)
+        {
+            return o1.service.compareTo(o2.service);
+        }
+    };
+
+    private final List<Failure<ServletContextHelperRuntime>> contextRuntimes;
+    private final List<Failure<ServletRuntime>> servletRuntimes;
+    private final List<Failure<FilterRuntime>> filterRuntimes;
+    private final List<Failure<ServletRuntime>> resourceRuntimes;
+    private final List<Failure<ErrorPageRuntime>> errorPageRuntimes;
+    private final List<Failure<ServiceReference<?>>> listenerRuntimes;
+
+    private FailureRuntime(List<Failure<ServletContextHelperRuntime>> contextRuntimes,
+            List<Failure<ServiceReference<?>>> listenerRuntimes,
+            List<Failure<ServletRuntime>> servletRuntimes,
+            List<Failure<FilterRuntime>> filterRuntimes,
+            List<Failure<ServletRuntime>> resourceRuntimes,
+            List<Failure<ErrorPageRuntime>> errorPageRuntimes)
+    {
+        this.contextRuntimes = contextRuntimes;
+        this.servletRuntimes = servletRuntimes;
+        this.filterRuntimes = filterRuntimes;
+        this.resourceRuntimes = resourceRuntimes;
+        this.listenerRuntimes = listenerRuntimes;
+        this.errorPageRuntimes = errorPageRuntimes;
+    }
+
+    public static FailureRuntime empty()
+    {
+        return new FailureRuntime(Collections.<Failure<ServletContextHelperRuntime>>emptyList(),
+                Collections.<Failure<ServiceReference<?>>>emptyList(),
+                Collections.<Failure<ServletRuntime>>emptyList(),
+                Collections.<Failure<FilterRuntime>>emptyList(),
+                Collections.<Failure<ServletRuntime>>emptyList(),
+                Collections.<Failure<ErrorPageRuntime>>emptyList());
+    }
+
+    public static FailureRuntime.Builder builder()
+    {
+        return new Builder();
+    }
+
+    public FailedServletDTO[] getServletDTOs()
+    {
+        List<FailedServletDTO> servletDTOs = new ArrayList<FailedServletDTO>();
+        for (Failure<ServletRuntime> failure : servletRuntimes)
+        {
+            servletDTOs.add(getServletDTO(failure.service, failure.failureCode));
+        }
+        return servletDTOs.toArray(SERVLET_FAILURE_DTO_ARRAY);
+    }
+
+    private FailedServletDTO getServletDTO(ServletRuntime failedServlet, int failureCode)
+    {
+        ServletDTOBuilder<FailedServletDTO> dtoBuilder = new ServletDTOBuilder<FailedServletDTO>(DTOFactories.FAILED_SERVLET);
+        FailedServletDTO servletDTO = dtoBuilder.buildDTO(failedServlet, 0);
+        servletDTO.failureReason = failureCode;
+        return servletDTO;
+    }
+
+    public FailedFilterDTO[] getFilterDTOs()
+    {
+        List<FailedFilterDTO> filterDTOs = new ArrayList<FailedFilterDTO>();
+        for (Failure<FilterRuntime> failure : filterRuntimes)
+        {
+            filterDTOs.add(getFilterDTO(failure.service, failure.failureCode));
+        }
+        return filterDTOs.toArray(FILTER_FAILURE_DTO_ARRAY);
+    }
+
+    private FailedFilterDTO getFilterDTO(FilterRuntime failedFilter, int failureCode)
+    {
+        FilterDTOBuilder<FailedFilterDTO> dtoBuilder = new FilterDTOBuilder<FailedFilterDTO>(DTOFactories.FAILED_FILTER);
+        FailedFilterDTO filterDTO = dtoBuilder.buildDTO(failedFilter, 0);
+        filterDTO.failureReason = failureCode;
+        return filterDTO;
+    }
+
+    public FailedResourceDTO[] getResourceDTOs()
+    {
+        List<FailedResourceDTO> resourceDTOs = new ArrayList<FailedResourceDTO>();
+        for (Failure<ServletRuntime> failure : resourceRuntimes)
+        {
+            resourceDTOs.add(getResourceDTO(failure.service, failure.failureCode));
+        }
+        return resourceDTOs.toArray(RESOURCE_FAILURE_DTO_ARRAY);
+    }
+
+    private FailedResourceDTO getResourceDTO(ServletRuntime failedResource, int failureCode)
+    {
+        ResourceDTOBuilder<FailedResourceDTO> dtoBuilder = new ResourceDTOBuilder<FailedResourceDTO>(DTOFactories.FAILED_RESOURCE);
+        FailedResourceDTO resourceDTO = dtoBuilder.buildDTO(failedResource, 0);
+        resourceDTO.failureReason = failureCode;
+        return resourceDTO;
+    }
+
+    public FailedErrorPageDTO[] getErrorPageDTOs()
+    {
+        List<FailedErrorPageDTO> errorPageDTOs = new ArrayList<FailedErrorPageDTO>();
+        for (Failure<ErrorPageRuntime> failure : errorPageRuntimes)
+        {
+            errorPageDTOs.add(getErrorPageDTO(failure.service, failure.failureCode));
+        }
+        return errorPageDTOs.toArray(ERROR_PAGE_FAILURE_DTO_ARRAY);
+    }
+
+    private FailedErrorPageDTO getErrorPageDTO(ErrorPageRuntime failedErrorPage, int failureCode)
+    {
+        ErrorPageDTOBuilder<FailedErrorPageDTO> dtoBuilder = new ErrorPageDTOBuilder<FailedErrorPageDTO>(DTOFactories.FAILED_ERROR_PAGE);
+        FailedErrorPageDTO errorPageDTO = dtoBuilder.buildDTO(failedErrorPage, 0);
+        errorPageDTO.failureReason = failureCode;
+        return errorPageDTO;
+    }
+
+    public FailedListenerDTO[] getListenerDTOs()
+    {
+        List<FailedListenerDTO> listenerDTOs = new ArrayList<FailedListenerDTO>();
+        for (Failure<ServiceReference<?>> failure : listenerRuntimes)
+        {
+            listenerDTOs.add(getListenerDTO(failure.service, failure.failureCode));
+        }
+        return listenerDTOs.toArray(LISTENER_FAILURE_DTO_ARRAY);
+    }
+
+    private FailedListenerDTO getListenerDTO(ServiceReference<?> failedListener, int failureCode)
+    {
+        ListenerDTOBuilder<FailedListenerDTO> dtoBuilder = new ListenerDTOBuilder<FailedListenerDTO>(DTOFactories.FAILED_LISTENER);
+        FailedListenerDTO errorPageDTO = dtoBuilder.buildDTO(failedListener, 0);
+        errorPageDTO.failureReason = failureCode;
+        return errorPageDTO;
+    }
+
+    public FailedServletContextDTO[] getServletContextDTOs()
+    {
+        List<FailedServletContextDTO> contextDTOs = new ArrayList<FailedServletContextDTO>();
+        for (Failure<ServletContextHelperRuntime> failure : contextRuntimes)
+        {
+            contextDTOs.add(getServletContextDTO(failure.service, failure.failureCode));
+        }
+        return contextDTOs.toArray(CONTEXT_FAILURE_DTO_ARRAY);
+    }
+
+    private FailedServletContextDTO getServletContextDTO(ServletContextHelperRuntime failedContext, int failureCode)
+    {
+        ServletContextDTOBuilder dtoBuilder = new ServletContextDTOBuilder(new FailedServletContextDTO(), failedContext);
+        FailedServletContextDTO servletContextDTO = (FailedServletContextDTO) dtoBuilder.build();
+        servletContextDTO.failureReason = failureCode;
+        return servletContextDTO;
+    }
+
+    public static class Builder
+    {
+        private final List<Failure<ServletContextHelperRuntime>> contextRuntimes = new ArrayList<FailureRuntime.Failure<ServletContextHelperRuntime>>();
+        private final List<Failure<ServletRuntime>> servletRuntimes = new ArrayList<Failure<ServletRuntime>>();
+        private final List<Failure<FilterRuntime>> filterRuntimes = new ArrayList<Failure<FilterRuntime>>();
+        private final List<Failure<ServletRuntime>> resourceRuntimes = new ArrayList<Failure<ServletRuntime>>();
+        private final List<Failure<ErrorPageRuntime>> errorPageRuntimes = new ArrayList<Failure<ErrorPageRuntime>>();
+        private final List<Failure<ServiceReference<?>>> listenerRuntimes = new ArrayList<Failure<ServiceReference<?>>>();
+
+        public FailureRuntime.Builder add(Map<AbstractInfo<?>, Integer> failureInfos)
+        {
+            for (Map.Entry<AbstractInfo<?>, Integer> failureEntry : failureInfos.entrySet())
+            {
+                add(failureEntry.getKey(), failureEntry.getValue());
+            }
+            return this;
+        }
+
+        public FailureRuntime.Builder add(AbstractInfo<?> info, int failureCode)
+        {
+            if (info instanceof ServletContextHelperInfo)
+            {
+                ServletContextHelperRuntime servletRuntime = new FailureServletContextHelperRuntime((ServletContextHelperInfo) info);
+                contextRuntimes.add(new Failure<ServletContextHelperRuntime>(servletRuntime, failureCode));
+            }
+            else if (info instanceof ServletInfo && ((ServletInfo) info).getErrorPage() != null)
+            {
+                FailureServletRuntime servletRuntime = new FailureServletRuntime((ServletInfo) info);
+                ErrorPageRuntime errorPageRuntime = ErrorPageRuntime.fromRuntime(servletRuntime);
+                errorPageRuntimes.add(new Failure<ErrorPageRuntime>(errorPageRuntime, failureCode));
+            }
+            else if (info instanceof ServletInfo)
+            {
+                ServletRuntime servletRuntime = new FailureServletRuntime((ServletInfo) info);
+                servletRuntimes.add(new Failure<ServletRuntime>(servletRuntime, failureCode));
+            }
+            else if (info instanceof FilterInfo)
+            {
+                FilterRuntime filterRuntime = new FailureFilterRuntime((FilterInfo) info);
+                filterRuntimes.add(new Failure<FilterRuntime>(filterRuntime, failureCode));
+            }
+            else if (info instanceof ResourceInfo)
+            {
+                ServletRuntime servletRuntime = new FailureServletRuntime(new ServletInfo((ResourceInfo) info));
+                resourceRuntimes.add(new Failure<ServletRuntime>(servletRuntime, failureCode));
+            }
+            else if (info instanceof ListenerInfo)
+            {
+                ServiceReference<?> serviceReference = ((ListenerInfo<?>) info).getServiceReference();
+                listenerRuntimes.add(new Failure<ServiceReference<?>>(serviceReference, failureCode));
+            }
+            else
+            {
+                throw new IllegalArgumentException("Unsupported info type: " + info.getClass());
+            }
+            return this;
+        }
+
+        public FailureRuntime build()
+        {
+            Collections.sort(contextRuntimes, CONTEXT_COMPARATOR);
+            Collections.sort(listenerRuntimes, REFERENCE_COMPARATOR);
+            Collections.sort(servletRuntimes, SERVLET_COMPARATOR);
+            Collections.sort(filterRuntimes, FILTER_COMPARATOR);
+            Collections.sort(resourceRuntimes, SERVLET_COMPARATOR);
+            Collections.sort(errorPageRuntimes, ERROR_PAGE_COMPARATOR);
+
+            return new FailureRuntime(contextRuntimes,
+                    listenerRuntimes,
+                    servletRuntimes,
+                    filterRuntimes,
+                    resourceRuntimes,
+                    errorPageRuntimes);
+        }
+    }
+
+    private static class Failure<T>
+    {
+
+        final T service;
+        final int failureCode;
+
+        Failure(T service, int failureCode)
+        {
+            this.service = service;
+            this.failureCode = failureCode;
+        }
+    }
+
+    private static class FailureComparator<T> implements Comparator<Failure<T>>
+    {
+        final Comparator<? super T> serviceComparator;
+
+        FailureComparator(Comparator<? super T> serviceComparator)
+        {
+            this.serviceComparator = serviceComparator;
+        }
+
+        static <T> FailureComparator<T> create(Comparator<? super T> serviceComparator)
+        {
+            return new FailureComparator<T>(serviceComparator);
+        }
+
+        @Override
+        public int compare(Failure<T> o1, Failure<T> o2)
+        {
+            return serviceComparator.compare(o1.service, o2.service);
+        }
+    }
+}
+

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

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletContextHelperRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletContextHelperRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletContextHelperRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletContextHelperRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,51 @@
+/*
+ * 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 javax.servlet.ServletContext;
+
+import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
+
+public class FailureServletContextHelperRuntime implements ServletContextHelperRuntime, Comparable<FailureServletContextHelperRuntime>
+{
+    private final ServletContextHelperInfo info;
+
+    public FailureServletContextHelperRuntime(ServletContextHelperInfo info)
+    {
+        this.info = info;
+    }
+
+    @Override
+    public ServletContext getSharedContext()
+    {
+        return null;
+    }
+
+    @Override
+    public ServletContextHelperInfo getContextInfo()
+    {
+        return info;
+    }
+
+    @Override
+    public int compareTo(FailureServletContextHelperRuntime other)
+    {
+        return info.compareTo(other.info);
+    }
+}

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

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletRuntime.java?rev=1669088&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletRuntime.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailureServletRuntime.java Wed Mar 25 10:28:08 2015
@@ -0,0 +1,53 @@
+/*
+ * 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 javax.servlet.Servlet;
+
+import org.apache.felix.http.base.internal.runtime.ServletInfo;
+
+
+
+public class FailureServletRuntime implements ServletRuntime
+{
+    private final ServletInfo servletInfo;
+
+    FailureServletRuntime(ServletInfo servletInfo)
+    {
+        this.servletInfo = servletInfo;
+    }
+
+    @Override
+    public ServletInfo getServletInfo()
+    {
+        return servletInfo;
+    }
+
+    @Override
+    public long getContextServiceId()
+    {
+        return 0L;
+    }
+
+    @Override
+    public Servlet getServlet()
+    {
+        return null;
+    }
+}

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



Mime
View raw message