felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1656936 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: context/ handler/ service/ whiteboard/
Date Tue, 03 Feb 2015 22:24:42 GMT
Author: cziegeler
Date: Tue Feb  3 22:24:42 2015
New Revision: 1656936

URL: http://svn.apache.org/r1656936
Log:
FELIX-4786 : Update to latest DS implementation - code cleanup, javadocs etc

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
    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/ServletConfigImpl.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ResourceServlet.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java?rev=1656936&r1=1656935&r2=1656936&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
Tue Feb  3 22:24:42 2015
@@ -75,150 +75,180 @@ public class ServletContextImpl implemen
         this.attributes = impl.attributes;
     }
 
+    @Override
     public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter>
type)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public FilterRegistration.Dynamic addFilter(String filterName, Filter filter)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public FilterRegistration.Dynamic addFilter(String filterName, String className)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public void addListener(Class<? extends EventListener> type)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public void addListener(String className)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public <T extends EventListener> void addListener(T listener)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends
Servlet> type)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public ServletRegistration.Dynamic addServlet(String servletName, String className)
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public <T extends Filter> T createFilter(Class<T> type) throws ServletException
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public <T extends EventListener> T createListener(Class<T> type) throws ServletException
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public <T extends Servlet> T createServlet(Class<T> type) throws ServletException
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public void declareRoles(String... roleNames)
     {
         this.context.declareRoles(roleNames);
     }
 
+    @Override
     public String getVirtualServerName() {
         return context.getVirtualServerName();
     }
 
+    @Override
     public Object getAttribute(String name)
     {
         return (this.attributes != null) ? this.attributes.get(name) : this.context.getAttribute(name);
     }
 
-    public Enumeration getAttributeNames()
+    @Override
+    public Enumeration<String> getAttributeNames()
     {
         return (this.attributes != null) ? Collections.enumeration(this.attributes.keySet())
: this.context.getAttributeNames();
     }
 
+    @Override
     public ClassLoader getClassLoader()
     {
         return bundle.getClass().getClassLoader();
     }
 
+    @Override
     public ServletContext getContext(String uri)
     {
         return this.context.getContext(uri);
     }
 
+    @Override
     public String getContextPath()
     {
         return this.context.getContextPath();
     }
 
+    @Override
     public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
     {
         return this.context.getDefaultSessionTrackingModes();
     }
 
+    @Override
     public int getEffectiveMajorVersion()
     {
         return this.context.getEffectiveMajorVersion();
     }
 
+    @Override
     public int getEffectiveMinorVersion()
     {
         return this.context.getEffectiveMinorVersion();
     }
 
+    @Override
     public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
     {
         return this.context.getEffectiveSessionTrackingModes();
     }
 
+    @Override
     public FilterRegistration getFilterRegistration(String filterName)
     {
         return this.context.getFilterRegistration(filterName);
     }
 
+    @Override
     public Map<String, ? extends FilterRegistration> getFilterRegistrations()
     {
         return this.context.getFilterRegistrations();
     }
 
+    @Override
     public String getInitParameter(String name)
     {
         return this.context.getInitParameter(name);
     }
 
-    public Enumeration getInitParameterNames()
+    @Override
+    public Enumeration<String> getInitParameterNames()
     {
         return this.context.getInitParameterNames();
     }
 
+    @Override
     public JspConfigDescriptor getJspConfigDescriptor()
     {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public int getMajorVersion()
     {
         return this.context.getMajorVersion();
     }
 
+    @Override
     public String getMimeType(String file)
     {
         String type = this.httpContext.getMimeType(file);
@@ -230,16 +260,19 @@ public class ServletContextImpl implemen
         return MimeTypes.get().getByFile(file);
     }
 
+    @Override
     public int getMinorVersion()
     {
         return this.context.getMinorVersion();
     }
 
+    @Override
     public RequestDispatcher getNamedDispatcher(String name)
     {
         return this.context.getNamedDispatcher(name);
     }
 
+    @Override
     public String getRealPath(String name)
     {
         URL url = getResource(name);
@@ -250,16 +283,19 @@ public class ServletContextImpl implemen
         return url.toExternalForm();
     }
 
+    @Override
     public RequestDispatcher getRequestDispatcher(String uri)
     {
         return this.context.getRequestDispatcher(uri);
     }
 
+    @Override
     public URL getResource(String path)
     {
         return this.httpContext.getResource(normalizeResourcePath(path));
     }
 
+    @Override
     public InputStream getResourceAsStream(String path)
     {
         URL res = getResource(path);
@@ -277,9 +313,10 @@ public class ServletContextImpl implemen
         return null;
     }
 
-    public Set getResourcePaths(String path)
+    @Override
+    public Set<String> getResourcePaths(String path)
     {
-        Enumeration paths = this.bundle.getEntryPaths(normalizePath(path));
+        Enumeration<String> paths = this.bundle.getEntryPaths(normalizePath(path));
         if ((paths == null) || !paths.hasMoreElements())
         {
             return null;
@@ -288,72 +325,85 @@ public class ServletContextImpl implemen
         Set<String> set = new HashSet<String>();
         while (paths.hasMoreElements())
         {
-            set.add((String) paths.nextElement());
+            set.add(paths.nextElement());
         }
 
         return set;
     }
 
+    @Override
     public String getServerInfo()
     {
         return this.context.getServerInfo();
     }
 
+    @Override
     public Servlet getServlet(String name) throws ServletException
     {
         return this.context.getServlet(name);
     }
 
+    @Override
     public String getServletContextName()
     {
         return this.context.getServletContextName();
     }
 
-    public Enumeration getServletNames()
+    @Override
+    public Enumeration<String> getServletNames()
     {
         return this.context.getServletNames();
     }
 
+    @Override
     public ServletRegistration getServletRegistration(String servletName)
     {
         return this.context.getServletRegistration(servletName);
     }
 
+    @Override
     public Map<String, ? extends ServletRegistration> getServletRegistrations()
     {
         return this.context.getServletRegistrations();
     }
 
-    public Enumeration getServlets()
+    @Override
+    public Enumeration<Servlet> getServlets()
     {
         return this.context.getServlets();
     }
 
+    @Override
     public SessionCookieConfig getSessionCookieConfig()
     {
         return this.context.getSessionCookieConfig();
     }
 
+    @Override
     public boolean handleSecurity(HttpServletRequest req, HttpServletResponse res) throws
IOException
     {
         return this.httpContext.handleSecurity(req, res);
     }
 
+    @Override
     public void log(Exception cause, String message)
     {
         SystemLogger.error(message, cause);
     }
 
+    @Override
     public void log(String message)
     {
         SystemLogger.info(message);
     }
 
+    @Override
     public void log(String message, Throwable cause)
     {
         SystemLogger.error(message, cause);
     }
 
+    @Override
     public void removeAttribute(String name)
     {
         Object oldValue;
@@ -373,6 +423,7 @@ public class ServletContextImpl implemen
         }
     }
 
+    @Override
     public void setAttribute(String name, Object value)
     {
         if (value == null)
@@ -403,11 +454,13 @@ public class ServletContextImpl implemen
         }
     }
 
+    @Override
     public boolean setInitParameter(String name, String value)
     {
         return this.context.setInitParameter(name, value);
     }
 
+    @Override
     public void setSessionTrackingModes(Set<SessionTrackingMode> modes)
     {
         this.context.setSessionTrackingModes(modes);

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=1656936&r1=1656935&r2=1656936&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
Tue Feb  3 22:24:42 2015
@@ -16,41 +16,46 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import java.util.Enumeration;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.Map;
 
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+
 public final class FilterConfigImpl implements FilterConfig
 {
     private final String name;
     private final ServletContext context;
     private final Map<String, String> initParams;
 
-    public FilterConfigImpl(String name, ServletContext context, Map<String, String>
initParams)
+    public FilterConfigImpl(final String name, final ServletContext context, final Map<String,
String> initParams)
     {
         this.name = name;
         this.context = context;
         this.initParams = initParams;
     }
 
+    @Override
     public String getFilterName()
     {
         return this.name;
     }
 
+    @Override
     public ServletContext getServletContext()
     {
         return this.context;
     }
 
+    @Override
     public String getInitParameter(String name)
     {
         return this.initParams.get(name);
     }
 
-    public Enumeration getInitParameterNames()
+    @Override
+    public Enumeration<String> getInitParameterNames()
     {
         return Collections.enumeration(this.initParams.keySet());
     }

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=1656936&r1=1656935&r2=1656936&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
Tue Feb  3 22:24:42 2015
@@ -16,41 +16,46 @@
  */
 package org.apache.felix.http.base.internal.handler;
 
-import javax.servlet.ServletContext;
-import javax.servlet.ServletConfig;
-import java.util.Enumeration;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.Map;
 
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
 public final class ServletConfigImpl implements ServletConfig
 {
     private final String name;
     private final ServletContext context;
     private final Map<String, String> initParams;
 
-    public ServletConfigImpl(String name, ServletContext context, Map<String, String>
initParams)
+    public ServletConfigImpl(final String name, final ServletContext context, final Map<String,
String> initParams)
     {
         this.name = name;
         this.context = context;
         this.initParams = initParams;
     }
 
+    @Override
     public String getServletName()
     {
         return this.name;
     }
 
+    @Override
     public ServletContext getServletContext()
     {
         return this.context;
     }
 
+    @Override
     public String getInitParameter(String name)
     {
         return this.initParams.get(name);
     }
 
-    public Enumeration getInitParameterNames()
+    @Override
+    public Enumeration<String> getInitParameterNames()
     {
         return Collections.enumeration(this.initParams.keySet());
     }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java?rev=1656936&r1=1656935&r2=1656936&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
Tue Feb  3 22:24:42 2015
@@ -23,9 +23,10 @@ import org.apache.felix.http.base.intern
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.HttpService;
 
 public final class HttpServiceFactory
-    implements ServiceFactory
+    implements ServiceFactory<HttpService>
 {
     private final ServletContext context;
     private final ServletContextAttributeListener attributeListener;
@@ -42,15 +43,21 @@ public final class HttpServiceFactory
     }
 
     @Override
-    public Object getService(Bundle bundle, ServiceRegistration reg)
+    public HttpService getService(final Bundle bundle, final ServiceRegistration<HttpService>
reg)
     {
-        return new HttpServiceImpl(bundle, this.context, this.handlerRegistry.getRegistry(null),
this.attributeListener,
-            this.sharedContextAttributes);
+        return new HttpServiceImpl(bundle, this.context,
+                this.handlerRegistry.getRegistry(null),
+                this.attributeListener,
+                this.sharedContextAttributes);
     }
 
     @Override
-    public void ungetService(Bundle bundle, ServiceRegistration reg, Object service)
+    public void ungetService(final Bundle bundle, final ServiceRegistration<HttpService>
reg,
+            final HttpService service)
     {
-        ((HttpServiceImpl)service).unregisterAll();
+        if ( service instanceof HttpServiceImpl )
+        {
+            ((HttpServiceImpl)service).unregisterAll();
+        }
     }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java?rev=1656936&r1=1656935&r2=1656936&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
Tue Feb  3 22:24:42 2015
@@ -84,21 +84,18 @@ public class PerBundleServletContextImpl
     @Override
     public URL getResource(final String path)
     {
-        // is implemented by {@link PerBundleServletContextImpl}.
         return this.contextHelper.getResource(path);
     }
 
     @Override
     public String getMimeType(final String name)
     {
-        // is implemented by {@link PerBundleServletContextImpl}.
         return this.contextHelper.getMimeType(name);
     }
 
     @Override
     public String getRealPath(final String path)
     {
-        // is implemented by {@link PerBundleServletContextImpl}.
         return this.contextHelper.getRealPath(path);
     }
 
@@ -162,18 +159,21 @@ public class PerBundleServletContextImpl
         return delegatee.getNamedDispatcher(name);
     }
 
+    @SuppressWarnings("deprecation")
     @Override
     public Servlet getServlet(String name) throws ServletException
     {
         return delegatee.getServlet(name);
     }
 
+    @SuppressWarnings("deprecation")
     @Override
     public Enumeration<Servlet> getServlets()
     {
         return delegatee.getServlets();
     }
 
+    @SuppressWarnings("deprecation")
     @Override
     public Enumeration<String> getServletNames()
     {
@@ -186,6 +186,7 @@ public class PerBundleServletContextImpl
         delegatee.log(msg);
     }
 
+    @SuppressWarnings("deprecation")
     @Override
     public void log(Exception exception, String msg)
     {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ResourceServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ResourceServlet.java?rev=1656936&r1=1656935&r2=1656936&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ResourceServlet.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ResourceServlet.java
Tue Feb  3 22:24:42 2015
@@ -28,29 +28,28 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+/**
+ * The resource servlet used for resource whiteboard registrations.
+ */
 public final class ResourceServlet extends HttpServlet
 {
-    private final String path;
+    private static final long serialVersionUID = 1L;
 
-    public ResourceServlet(final 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(final HttpServletRequest req, final HttpServletResponse res) throws
ServletException, IOException
+    protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
+            throws ServletException, IOException
     {
         final String target = req.getPathInfo();
-        final String resName;
-        if (target == null)
-        {
-            resName = this.path;
-        }
-        else
-        {
-        	resName = this.path + target;
-        }
-        
+        final String resName = (target == null ? this.prefix : this.prefix + target);
+
         final URL url = getServletContext().getResource(resName);
 
         if (url == null)
@@ -63,16 +62,17 @@ public final class ResourceServlet exten
         }
     }
 
-    private void handle(final HttpServletRequest req, final HttpServletResponse res, final
URL url, final String resName)  
+    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/SharedServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java?rev=1656936&r1=1656935&r2=1656936&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
Tue Feb  3 22:24:42 2015
@@ -209,7 +209,7 @@ public class SharedServletContextImpl im
     }
 
     @Override
-    public Enumeration getAttributeNames()
+    public Enumeration<String> getAttributeNames()
     {
         return Collections.enumeration(this.attributes.keySet());
     }
@@ -269,7 +269,7 @@ public class SharedServletContextImpl im
     }
 
     @Override
-    public Enumeration getInitParameterNames()
+    public Enumeration<String> getInitParameterNames()
     {
         return Collections.enumeration(this.initParameters.keySet());
     }
@@ -330,6 +330,7 @@ public class SharedServletContextImpl im
         return this.context.getServerInfo();
     }
 
+    @SuppressWarnings("deprecation")
     @Override
     public Servlet getServlet(final String name) throws ServletException
     {
@@ -342,8 +343,9 @@ public class SharedServletContextImpl im
         return this.name;
     }
 
+    @SuppressWarnings("deprecation")
     @Override
-    public Enumeration getServletNames()
+    public Enumeration<String> getServletNames()
     {
         return this.context.getServletNames();
     }
@@ -360,8 +362,9 @@ public class SharedServletContextImpl im
         return this.context.getServletRegistrations();
     }
 
+    @SuppressWarnings("deprecation")
     @Override
-    public Enumeration getServlets()
+    public Enumeration<Servlet> getServlets()
     {
         return this.context.getServlets();
     }



Mime
View raw message