felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1680915 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: handler/ registry/ runtime/dto/ service/ whiteboard/
Date Thu, 21 May 2015 15:52:30 GMT
Author: cziegeler
Date: Thu May 21 15:52:29 2015
New Revision: 1680915

URL: http://svn.apache.org/r1680915
Log:
FELIX-4060 : Implement HTTP Whiteboard Service (RFC-189). Clean up code, add some javadocs

Removed:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ResourceServlet.java
Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.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/HttpServiceFilterHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.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/handler/WhiteboardFilterHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ResourceServlet.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
Thu May 21 15:52:29 2015
@@ -23,6 +23,9 @@ import java.util.Map;
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletContext;
 
+/**
+ * Implementation of the filter configuration.
+ */
 public final class FilterConfigImpl implements FilterConfig
 {
     private final String name;
@@ -49,7 +52,7 @@ public final class FilterConfigImpl impl
     }
 
     @Override
-    public String getInitParameter(String name)
+    public String getInitParameter(final String name)
     {
         return this.initParams.get(name);
     }

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=1680915&r1=1680914&r2=1680915&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
Thu May 21 15:52:29 2015
@@ -31,7 +31,8 @@ import org.apache.felix.http.base.intern
 import org.osgi.service.http.runtime.dto.DTOConstants;
 
 /**
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * The filter handler handles the initialization and destruction of filter
+ * objects.
  */
 public class FilterHandler implements Comparable<FilterHandler>
 {
@@ -116,7 +117,7 @@ public class FilterHandler implements Co
         {
             filter.init(new FilterConfigImpl(getName(), getContext(), getFilterInfo().getInitParameters()));
         }
-        catch (final ServletException e)
+        catch (final Exception e)
         {
             SystemLogger.error(this.getFilterInfo().getServiceReference(),
                     "Error during calling init() on filter " + this.filter,

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpServiceFilterHandler.java
Thu May 21 15:52:29 2015
@@ -23,7 +23,7 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.service.HttpServiceFactory;
 
 /**
- * Servlet holder for filters registered through the ext http service.
+ * Servlet handler for filters registered through the ext http service.
  */
 public final class HttpServiceFilterHandler extends FilterHandler
 {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
Thu May 21 15:52:29 2015
@@ -23,6 +23,9 @@ import java.util.Map;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 
+/**
+ * Implementation of the servlet configuration
+ */
 public final class ServletConfigImpl implements ServletConfig
 {
     private final String name;
@@ -51,7 +54,7 @@ public final class ServletConfigImpl imp
     }
 
     @Override
-    public String getInitParameter(String name)
+    public String getInitParameter(final String name)
     {
         return this.initParams.get(name);
     }

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=1680915&r1=1680914&r2=1680915&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
Thu May 21 15:52:29 2015
@@ -29,7 +29,8 @@ import org.apache.felix.http.base.intern
 import org.osgi.service.http.runtime.dto.DTOConstants;
 
 /**
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * The servlet handler handles the initialization and destruction of
+ * a servlet.
  */
 public abstract class ServletHandler implements Comparable<ServletHandler>
 {
@@ -120,7 +121,7 @@ public abstract class ServletHandler imp
         {
             servlet.init(new ServletConfigImpl(getName(), getContext(), getServletInfo().getInitParameters()));
         }
-        catch (final ServletException e)
+        catch (final Exception e)
         {
             SystemLogger.error(this.getServletInfo().getServiceReference(),
                     "Error during calling init() on servlet " + this.servlet,

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardFilterHandler.java
Thu May 21 15:52:29 2015
@@ -57,7 +57,10 @@ public final class WhiteboardFilterHandl
         final int reason = super.init();
         if ( reason != -1 )
         {
-            so.ungetService(this.getFilter());
+            if ( so != null )
+            {
+                so.ungetService(this.getFilter());
+            }
             this.setFilter(null);
         }
         return reason;

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
Thu May 21 15:52:29 2015
@@ -57,7 +57,10 @@ public final class WhiteboardServletHand
         final int reason = super.init();
         if ( reason != -1 )
         {
-            so.ungetService(this.getServlet());
+            if ( so != null )
+            {
+                so.ungetService(this.getServlet());
+            }
             this.setServlet(null);
         }
         return reason;

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
Thu May 21 15:52:29 2015
@@ -43,7 +43,7 @@ import org.osgi.service.http.runtime.dto
  * for a single servlet context.
  *
  * TODO - sort active servlet mappings by pattern length, longest first (avoids looping over
all)
- *
+ * TODO - we could collapse all three maps into a single map (activeServletMappings, inactiveServletMappings
and statusMapping)
  */
 public final class ServletRegistry
 {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
Thu May 21 15:52:29 2015
@@ -19,8 +19,8 @@
 package org.apache.felix.http.base.internal.runtime.dto;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.felix.http.base.internal.logger.SystemLogger;
@@ -41,17 +41,17 @@ import org.osgi.service.http.runtime.dto
 public final class FailedDTOHolder
 {
 
-    public Collection<FailedFilterDTO> failedFilterDTOs = new ArrayList<FailedFilterDTO>();
+    public final List<FailedFilterDTO> failedFilterDTOs = new ArrayList<FailedFilterDTO>();
 
-    public Collection<FailedListenerDTO> failedListenerDTOs = new ArrayList<FailedListenerDTO>();
+    public final List<FailedListenerDTO> failedListenerDTOs = new ArrayList<FailedListenerDTO>();
 
-    public Collection<FailedServletDTO> failedServletDTOs = new ArrayList<FailedServletDTO>();
+    public final List<FailedServletDTO> failedServletDTOs = new ArrayList<FailedServletDTO>();
 
-    public Collection<FailedResourceDTO> failedResourceDTOs = new ArrayList<FailedResourceDTO>();
+    public final List<FailedResourceDTO> failedResourceDTOs = new ArrayList<FailedResourceDTO>();
 
-    public Collection<FailedErrorPageDTO> failedErrorPageDTOs = new ArrayList<FailedErrorPageDTO>();
+    public final List<FailedErrorPageDTO> failedErrorPageDTOs = new ArrayList<FailedErrorPageDTO>();
 
-    public Collection<FailedServletContextDTO> failedServletContextDTO = new ArrayList<FailedServletContextDTO>();
+    public final List<FailedServletContextDTO> failedServletContextDTO = new ArrayList<FailedServletContextDTO>();
 
     public void add(Map<AbstractInfo<?>, Integer> failureInfos)
     {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ResourceServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ResourceServlet.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ResourceServlet.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ResourceServlet.java
Thu May 21 15:52:29 2015
@@ -28,31 +28,29 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+/**
+ * The resource servlet
+ */
 public final class ResourceServlet extends HttpServlet
 {
-    private final String path;
+    private static final long serialVersionUID = 1L;
 
-    public ResourceServlet(String path)
+    /** The path of the resource registration. */
+    private final String prefix;
+
+    public ResourceServlet(final String prefix)
     {
-        this.path = path;
+        this.prefix = prefix;
     }
 
     @Override
-    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException
+    protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
+            throws ServletException, IOException
     {
-        String target = req.getPathInfo();
-        if (target == null)
-        {
-            target = "";
-        }
-
-        if (!target.startsWith("/"))
-        {
-            target += "/" + target;
-        }
+        final String target = req.getPathInfo();
+        final String resName = (target == null ? this.prefix : this.prefix + target);
 
-        String resName = this.path + target;
-        URL url = getServletContext().getResource(resName);
+        final URL url = getServletContext().getResource(resName);
 
         if (url == null)
         {
@@ -64,15 +62,17 @@ public final class ResourceServlet exten
         }
     }
 
-    private void handle(HttpServletRequest req, HttpServletResponse res, URL url, String
resName) throws IOException
+    private void handle(final HttpServletRequest req,
+            final HttpServletResponse res, final URL url, final String resName)
+    throws IOException
     {
-        String contentType = getServletContext().getMimeType(resName);
+        final String contentType = getServletContext().getMimeType(resName);
         if (contentType != null)
         {
             res.setContentType(contentType);
         }
 
-        long lastModified = getLastModified(url);
+        final long lastModified = getLastModified(url);
         if (lastModified != 0)
         {
             res.setDateHeader("Last-Modified", lastModified);
@@ -88,26 +88,26 @@ public final class ResourceServlet exten
         }
     }
 
-    private long getLastModified(URL url)
+    private long getLastModified(final URL url)
     {
         long lastModified = 0;
 
         try
         {
-            URLConnection conn = url.openConnection();
+            final URLConnection conn = url.openConnection();
             lastModified = conn.getLastModified();
         }
-        catch (Exception e)
+        catch (final Exception e)
         {
             // Do nothing
         }
 
         if (lastModified == 0)
         {
-            String filepath = url.getPath();
+            final String filepath = url.getPath();
             if (filepath != null)
             {
-                File f = new File(filepath);
+                final File f = new File(filepath);
                 if (f.exists())
                 {
                     lastModified = f.lastModified();
@@ -126,7 +126,7 @@ public final class ResourceServlet exten
         return resTimestamp == 0 || modSince == -1 || resTimestamp > modSince;
     }
 
-    private void copyResource(URL url, HttpServletResponse res) throws IOException
+    private void copyResource(final URL url, final HttpServletResponse res) throws IOException
     {
         URLConnection conn = null;
         OutputStream os = null;
@@ -138,7 +138,7 @@ public final class ResourceServlet exten
 
             is = conn.getInputStream();
             os = res.getOutputStream();
-            // FELIX-3987 content length should be set *before* any streaming is done 
+            // FELIX-3987 content length should be set *before* any streaming is done
             // as headers should be written before the content is actually written...
             int len = getContentLength(conn);
             if (len >= 0)
@@ -168,20 +168,20 @@ public final class ResourceServlet exten
         }
     }
 
-    private int getContentLength(URLConnection conn)
+    private int getContentLength(final URLConnection conn)
     {
         int length = -1;
 
         length = conn.getContentLength();
         if (length < 0)
         {
-            // Unknown, try whether it is a file, and if so, use the file 
+            // Unknown, try whether it is a file, and if so, use the file
             // API to get the length of the content...
             String path = conn.getURL().getPath();
             if (path != null)
             {
                 File f = new File(path);
-                // In case more than 2GB is streamed 
+                // In case more than 2GB is streamed
                 if (f.length() < Integer.MAX_VALUE)
                 {
                     length = (int) f.length();

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java?rev=1680915&r1=1680914&r2=1680915&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
Thu May 21 15:52:29 2015
@@ -27,6 +27,7 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.runtime.FilterInfo;
 import org.apache.felix.http.base.internal.runtime.ResourceInfo;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
+import org.apache.felix.http.base.internal.service.ResourceServlet;
 import org.osgi.framework.BundleContext;
 
 public final class WhiteboardHttpService



Mime
View raw message