You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/08/02 13:12:19 UTC

svn commit: r1754911 - in /felix/trunk/http/sslfilter: pom.xml src/main/java/org/apache/felix/http/sslfilter/internal/HttpServiceTracker.java src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java

Author: cziegeler
Date: Tue Aug  2 13:12:19 2016
New Revision: 1754911

URL: http://svn.apache.org/viewvc?rev=1754911&view=rev
Log:
FELIX-5317 : Use http whiteboard for filter registration

Removed:
    felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/HttpServiceTracker.java
Modified:
    felix/trunk/http/sslfilter/pom.xml
    felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java

Modified: felix/trunk/http/sslfilter/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/http/sslfilter/pom.xml?rev=1754911&r1=1754910&r2=1754911&view=diff
==============================================================================
--- felix/trunk/http/sslfilter/pom.xml (original)
+++ felix/trunk/http/sslfilter/pom.xml Tue Aug  2 13:12:19 2016
@@ -56,6 +56,9 @@
                         <DynamicImport-Package>
                             org.osgi.service.cm;version="[1.2,2)"
                         </DynamicImport-Package>
+                        <Require-Capability>
+                            osgi.implementation;filter:="(&amp;(osgi.implementation=osgi.http)(version=1.0))"
+                        </Require-Capability>
                     </instructions>
                 </configuration>
             </plugin>
@@ -71,6 +74,12 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.http.whiteboard</artifactId>
+            <version>1.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
             <version>4.2.0</version>
             <scope>provided</scope>
@@ -81,12 +90,6 @@
             <version>1.1.0</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.api</artifactId>
-            <version>2.3.2</version>
-            <scope>provided</scope>
-        </dependency>
 
         <!-- Test Dependencies -->
         <dependency>

Modified: felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java?rev=1754911&r1=1754910&r2=1754911&view=diff
==============================================================================
--- felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java (original)
+++ felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java Tue Aug  2 13:12:19 2016
@@ -18,12 +18,31 @@
  */
 package org.apache.felix.http.sslfilter.internal;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.service.log.LogService;
 
 public class SslFilterActivator implements BundleActivator
 {
-    private HttpServiceTracker httpTracker;
+    /** Singleton filter to be registered with all http services. */
+    private final SslFilter filter = new SslFilter();
+
+    private volatile ServiceRegistration configReceiver;
+
+    private volatile ServiceRegistration filterReg;
+
     private LogServiceTracker logTracker;
 
     @Override
@@ -32,17 +51,57 @@ public class SslFilterActivator implemen
         this.logTracker = new LogServiceTracker(context);
         this.logTracker.open();
 
-        this.httpTracker = new HttpServiceTracker(context);
-        this.httpTracker.open();
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(Constants.SERVICE_PID, SslFilter.PID);
+
+        this.configReceiver = context.registerService(ManagedService.class.getName(), new ServiceFactory()
+        {
+            @Override
+            public Object getService(Bundle bundle, ServiceRegistration registration)
+            {
+                return new ManagedService()
+                {
+                    @Override
+                    public void updated(@SuppressWarnings("rawtypes") Dictionary properties) throws ConfigurationException
+                    {
+                        configureFilters(properties);
+                    }
+                };
+            }
+
+            @Override
+            public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+            {
+                // Nop
+            }
+        }, props);
+
+        final Dictionary<String, Object> properties = new Hashtable<String, Object>();
+        properties.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        properties.put(Constants.SERVICE_DESCRIPTION, "Apache Felix HTTP SSL Filter");
+
+        // any context
+        properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)");
+        properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/");
+
+        this.filterReg = context.registerService(Filter.class.getName(), filter, properties);
+
+        SystemLogger.log(LogService.LOG_DEBUG, "SSL filter registered...");
     }
 
     @Override
     public void stop(final BundleContext context)
     {
-        if (this.httpTracker != null)
+        if ( this.filterReg != null )
+        {
+            this.filterReg.unregister();
+            this.filterReg = null;
+            SystemLogger.log(LogService.LOG_DEBUG, "SSL filter unregistered...");
+        }
+        if (this.configReceiver != null)
         {
-            this.httpTracker.close();
-            this.httpTracker = null;
+            this.configReceiver.unregister();
+            this.configReceiver = null;
         }
         if (this.logTracker != null)
         {
@@ -50,4 +109,9 @@ public class SslFilterActivator implemen
             this.logTracker = null;
         }
     }
+
+    void configureFilters(@SuppressWarnings("rawtypes") final Dictionary properties) throws ConfigurationException
+    {
+        this.filter.configure(properties);
+    }
 }