Clean up code, remove unused code

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1692059 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java b/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
index d0aa361..b75f253 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
@@ -29,7 +29,6 @@
 import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
 import org.apache.felix.http.base.internal.service.HttpServiceFactory;
-import org.apache.felix.http.base.internal.service.listener.ServletContextAttributeListenerManager;
 import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
 import org.osgi.framework.BundleContext;
 
@@ -57,11 +56,6 @@
         return this.dispatcher;
     }
 
-    ServletContextAttributeListenerManager getContextAttributeListener()
-    {
-        return this.httpServiceFactory.getContextAttributeListener();
-    }
-
     HttpSessionListener getSessionListener()
     {
         // we don't need to sync here, if the object gets created several times
@@ -85,6 +79,10 @@
         return httpSessionListener;
     }
 
+    /**
+     * TODO : we should try to remove this, it's only needed for
+     *        the proprietary support of the Felix implementation
+     */
     HttpSessionAttributeListener getSessionAttributeListener()
     {
         return httpServiceFactory.getSessionAttributeListener();
@@ -107,6 +105,10 @@
         this.whiteboardManager.setProperties(props);
     }
 
+    /**
+     * Start the http and http whiteboard service in the provided context.
+     * @param containerContext The container context.
+     */
     public void register(@Nonnull final ServletContext containerContext)
     {
         this.registry.init();
@@ -117,6 +119,9 @@
         this.dispatcher.setWhiteboardManager(this.whiteboardManager);
     }
 
+    /**
+     * Stops the http and http whiteboard service.
+     */
     public void unregister()
     {
         this.dispatcher.setWhiteboardManager(null);
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
index 2bffcbd..4d46872 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
@@ -18,7 +18,8 @@
 
 import java.io.IOException;
 import java.util.Set;
-import javax.servlet.DispatcherType;
+
+import javax.annotation.CheckForNull;
 import javax.servlet.FilterChain;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
@@ -32,27 +33,28 @@
 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.HttpSessionWrapper;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
 import org.apache.felix.http.base.internal.registry.PathResolution;
 import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
-import org.apache.felix.http.base.internal.registry.ServletResolution;
-import org.apache.felix.http.base.internal.util.UriUtils;
 import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
 
 public final class Dispatcher
 {
     private final HandlerRegistry handlerRegistry;
 
-    private WhiteboardManager whiteboardManager;
+    private volatile WhiteboardManager whiteboardManager;
 
     public Dispatcher(final HandlerRegistry handlerRegistry)
     {
         this.handlerRegistry = handlerRegistry;
     }
 
-    public void setWhiteboardManager(final WhiteboardManager service)
+    /**
+     * Set or unset the whiteboard manager.
+     * @param service The whiteboard manager or {@code null}
+     */
+    public void setWhiteboardManager(@CheckForNull final WhiteboardManager service)
     {
         this.whiteboardManager = service;
     }
@@ -72,7 +74,11 @@
         if ( session != null )
         {
             final Set<Long> ids = HttpSessionWrapper.getExpiredSessionContextIds(session);
-            this.whiteboardManager.sessionDestroyed(session, ids);
+            final WhiteboardManager mgr = this.whiteboardManager;
+            if ( mgr != null )
+            {
+                this.whiteboardManager.sessionDestroyed(session, ids);
+            }
         }
 
         // get full path
@@ -100,7 +106,6 @@
             return;
         }
 
-
         final ExtServletContext servletContext = pr.handler.getContext();
         final RequestInfo requestInfo = new RequestInfo(pr.servletPath, pr.pathInfo, null);
 
@@ -115,7 +120,9 @@
             {
                 servletContext.getServletRequestListener().requestInitialized(new ServletRequestEvent(servletContext, wrappedRequest));
             }
-            invokeChain(pr.handler, filterHandlers, wrappedRequest, wrappedResponse);
+            final FilterChain filterChain = new InvocationChain(pr.handler, filterHandlers);
+            filterChain.doFilter(wrappedRequest, wrappedResponse);
+
         }
         catch ( final Exception e)
         {
@@ -133,40 +140,4 @@
             }
         }
     }
-
-    /**
-     * @param servletHandler the servlet that should handle the forward request;
-     * @param request the {@link HttpServletRequest};
-     * @param response the {@link HttpServletResponse};
-     */
-    public void forward(final ServletResolution resolution, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
-    {
-        final String requestURI = UriUtils.relativePath(request.getContextPath(), request.getRequestURI());
-        final FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(resolution, DispatcherType.FORWARD, requestURI);
-
-        invokeChain(resolution.handler, filterHandlers, request, response);
-    }
-
-    /**
-     * @param servletHandler the servlet that should handle the include request;
-     * @param request the {@link HttpServletRequest};
-     * @param response the {@link HttpServletResponse};
-     */
-    public void include(final ServletResolution resolution, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
-    {
-        final String requestURI = UriUtils.relativePath(request.getContextPath(), request.getRequestURI());
-        final FilterHandler[] filterHandlers = this.handlerRegistry.getFilters(resolution, DispatcherType.INCLUDE, requestURI);
-
-        invokeChain(resolution.handler, filterHandlers, request, response);
-    }
-
-    private void invokeChain(final ServletHandler servletHandler,
-            final FilterHandler[] filterHandlers,
-            final HttpServletRequest request,
-            final HttpServletResponse response)
-    throws IOException, ServletException
-    {
-        final FilterChain filterChain = new InvocationChain(servletHandler, filterHandlers);
-        filterChain.doFilter(request, response);
-    }
 }
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
index 47fbd94..773bf83 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
@@ -65,7 +65,7 @@
      */
     private static final String FELIX_HTTP_SHARED_SERVLET_CONTEXT_ATTRIBUTES = "org.apache.felix.http.shared_servlet_context_attributes";
 
-    /** Compatiblity property for previous versions. */
+    /** Compatibility property with previous versions. */
     private static final String OBSOLETE_REG_PROPERTY_ENDPOINTS = "osgi.http.service.endpoints";
 
     private final BundleContext bundleContext;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java b/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java
deleted file mode 100644
index 0a2d00a..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/util/CollectionUtils.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.util;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-public class CollectionUtils {
-    public static <T extends Comparable<?>> SortedSet<T> sortedUnion(Collection<? extends T>... collections)
-    {
-        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);
-        }
-        return union;
-    }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java b/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
index e514c7b..84ab106 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/util/UriUtils.java
@@ -421,109 +421,6 @@
         return value == null || "".equals(value.trim());
     }
 
-    public static String statusToString(final int statusCode)
-    {
-        switch (statusCode)
-        {
-            case 100:
-                return "Continue";
-            case 101:
-                return "Switching Protocols";
-            case 102:
-                return "Processing (WebDAV)";
-            case 200:
-                return "OK";
-            case 201:
-                return "Created";
-            case 202:
-                return "Accepted";
-            case 203:
-                return "Non-Authoritative Information";
-            case 204:
-                return "No Content";
-            case 205:
-                return "Reset Content";
-            case 206:
-                return "Partial Content";
-            case 207:
-                return "Multi-Status (WebDAV)";
-            case 300:
-                return "Multiple Choices";
-            case 301:
-                return "Moved Permanently";
-            case 302:
-                return "Found";
-            case 303:
-                return "See Other";
-            case 304:
-                return "Not Modified";
-            case 305:
-                return "Use Proxy";
-            case 307:
-                return "Temporary Redirect";
-            case 400:
-                return "Bad Request";
-            case 401:
-                return "Unauthorized";
-            case 402:
-                return "Payment Required";
-            case 403:
-                return "Forbidden";
-            case 404:
-                return "Not Found";
-            case 405:
-                return "Method Not Allowed";
-            case 406:
-                return "Not Acceptable";
-            case 407:
-                return "Proxy Authentication Required";
-            case 408:
-                return "Request Time-out";
-            case 409:
-                return "Conflict";
-            case 410:
-                return "Gone";
-            case 411:
-                return "Length Required";
-            case 412:
-                return "Precondition Failed";
-            case 413:
-                return "Request Entity Too Large";
-            case 414:
-                return "Request-URI Too Large";
-            case 415:
-                return "Unsupported Media Type";
-            case 416:
-                return "Requested range not satisfiable";
-            case 417:
-                return "Expectation Failed";
-            case 422:
-                return "Unprocessable Entity (WebDAV)";
-            case 423:
-                return "Locked (WebDAV)";
-            case 424:
-                return "Failed Dependency (WebDAV)";
-            case 500:
-                return "Internal Server Error";
-            case 501:
-                return "Not Implemented";
-            case 502:
-                return "Bad Gateway";
-            case 503:
-                return "Service Unavailable";
-            case 504:
-                return "Gateway Time-out";
-            case 505:
-                return "HTTP Version not supported";
-            case 507:
-                return "Insufficient Storage (WebDAV)";
-            case 510:
-                return "Not Extended";
-            default:
-                return String.valueOf(statusCode);
-        }
-    }
-
     /**
      * Creates a new {@link UriUtils} instance.
      */