felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1756873 - in /felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal: registry/ServletRegistry.java whiteboard/tracker/ServletTracker.java
Date Fri, 19 Aug 2016 07:27:02 GMT
Author: cziegeler
Date: Fri Aug 19 07:27:02 2016
New Revision: 1756873

URL: http://svn.apache.org/viewvc?rev=1756873&view=rev
Log:
FELIX-5299 : [RFC 223] 5.4 Support Servlets without a pattern

Modified:
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
    felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletTracker.java

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java?rev=1756873&r1=1756872&r2=1756873&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
Fri Aug 19 07:27:02 2016
@@ -48,6 +48,8 @@ import org.osgi.service.http.runtime.dto
  */
 public final class ServletRegistry
 {
+    private static final String NAMED_SERVLET_PATTERN = ":::";
+
     private volatile List<PathResolver> activeResolvers = Collections.emptyList();
 
     private final Map<String, List<ServletHandler>> inactiveServletMappings =
new HashMap<String, List<ServletHandler>>();
@@ -104,7 +106,7 @@ public final class ServletRegistry
     public synchronized void addServlet(@Nonnull final ServletHandler handler)
     {
         // we have to check for every pattern in the info
-        // Can be null in case of error-handling servlets...
+        // Can be null in case of error-handling servlets and named servlets
         if ( handler.getServletInfo().getPatterns() != null )
         {
             final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo,
ServletRegistry.RegistrationStatus>(this.mapping);
@@ -173,6 +175,28 @@ public final class ServletRegistry
             this.activeResolvers = resolvers;
             this.mapping = newMap;
         }
+/*
+        else if ( !handler.getServletInfo().isResource() && handler.getServletInfo().getName()
!= null )
+        {
+            final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo,
ServletRegistry.RegistrationStatus>(this.mapping);
+
+            final RegistrationStatus status = new RegistrationStatus();
+            status.handler = handler;
+
+            // if a servlet has only a name we always try to activate
+            // this is not very efficient, but works
+            // add to active
+            final int result = handler.init();
+            if ( result == -1 )
+            {
+                addToNameMapping(handler);
+            }
+            addPattern(status, result, NAMED_SERVLET_PATTERN);
+
+            newMap.put(handler.getServletInfo(), status);
+            this.mapping = newMap;
+        }
+*/
     }
 
     private void addToNameMapping(final ServletHandler handler)
@@ -324,6 +348,23 @@ public final class ServletRegistry
                 cleanupHandler.dispose();
             }
         }
+/*
+        else if ( !info.isResource() && info.getName() != null )
+        {
+            final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo,
ServletRegistry.RegistrationStatus>(this.mapping);
+            final RegistrationStatus status = newMap.remove(info);
+
+            if ( status != null )
+            {
+                removeFromNameMapping(info.getName(), status.handler);
+
+                this.mapping = newMap;
+
+                status.handler.dispose();
+            }
+
+        }
+*/
     }
 
     public synchronized void cleanup()
@@ -435,7 +476,14 @@ public final class ServletRegistry
                 if ( entry.getKey().isResource() )
                 {
                     final ResourceDTO state = ResourceDTOBuilder.build(entry.getValue().handler,
map.getKey());
-                    state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
+                    if ( map.getValue().length == 1 && NAMED_SERVLET_PATTERN == map.getValue()[0]
)
+                    {
+                        state.patterns = null;
+                    }
+                    else
+                    {
+                        state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
+                    }
                     if ( map.getKey() == -1 )
                     {
                         resourceDTOs.put(serviceId, state);
@@ -448,7 +496,14 @@ public final class ServletRegistry
                 else
                 {
                     final ServletDTO state = ServletDTOBuilder.build(entry.getValue().handler,
map.getKey());
-                    state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
+                    if ( map.getValue().length == 1 && NAMED_SERVLET_PATTERN == map.getValue()[0]
)
+                    {
+                        state.patterns = null;
+                    }
+                    else
+                    {
+                        state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
+                    }
                     if ( map.getKey() == -1 )
                     {
                         servletDTOs.put(serviceId, state);

Modified: felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletTracker.java?rev=1756873&r1=1756872&r2=1756873&view=diff
==============================================================================
--- felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletTracker.java
(original)
+++ felix/sandbox/http-base-r7/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletTracker.java
Fri Aug 19 07:27:02 2016
@@ -29,8 +29,9 @@ public final class ServletTracker extend
 {
     public ServletTracker(final BundleContext context, final WhiteboardManager manager)
     {
-        super(manager, context, String.format("(&(objectClass=%s)(|(%s=*)(%s=*)))",
+        super(manager, context, String.format("(&(objectClass=%s)(|(%s=*)(%s=*)(%s=*)))",
                 Servlet.class.getName(),
+                HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME,
                 HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN,
                 HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE));
     }



Mime
View raw message