FELIX-5317 : Use http whiteboard for filter registration
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1754911 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/sslfilter/pom.xml b/http/sslfilter/pom.xml
index 2c48b38..e9eb9dd 100644
--- a/http/sslfilter/pom.xml
+++ b/http/sslfilter/pom.xml
@@ -56,6 +56,9 @@
<DynamicImport-Package>
org.osgi.service.cm;version="[1.2,2)"
</DynamicImport-Package>
+ <Require-Capability>
+ osgi.implementation;filter:="(&(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>
diff --git a/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/HttpServiceTracker.java b/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/HttpServiceTracker.java
deleted file mode 100644
index f8fb312..0000000
--- a/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/HttpServiceTracker.java
+++ /dev/null
@@ -1,132 +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.sslfilter.internal;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import javax.servlet.ServletException;
-
-import org.apache.felix.http.api.ExtHttpService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class HttpServiceTracker extends ServiceTracker
-{
- /** Singleton filter to be registered with all http services. */
- private final SslFilter filter = new SslFilter();
-
- private volatile ServiceRegistration configReceiver;
-
- @SuppressWarnings("serial")
- public HttpServiceTracker(final BundleContext context)
- {
- super(context, ExtHttpService.class.getName(), null);
- }
-
- @Override
- public void open(final boolean trackAllServices)
- {
- final Dictionary<String, Object> props = new Hashtable<String, Object>();
- props.put(Constants.SERVICE_PID, SslFilter.PID);
-
- this.configReceiver = super.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);
-
- super.open(trackAllServices);
- }
-
- @Override
- public void close()
- {
- super.close();
-
- if (this.configReceiver != null)
- {
- this.configReceiver.unregister();
- this.configReceiver = null;
- }
- }
-
- @Override
- public Object addingService(final ServiceReference reference)
- {
- final ExtHttpService service = (ExtHttpService) super.addingService(reference);
- if (service != null)
- {
- try
- {
- service.registerFilter(filter, ".*", new Hashtable(), 0, null);
-
- SystemLogger.log(LogService.LOG_DEBUG, "SSL filter registered...");
- }
- catch (ServletException e)
- {
- SystemLogger.log(LogService.LOG_WARNING, "Failed to register SSL filter!", e);
- }
- }
-
- return service;
- }
-
- @Override
- public void removedService(final ServiceReference reference, final Object service)
- {
- ((ExtHttpService) service).unregisterFilter(filter);
-
- SystemLogger.log(LogService.LOG_DEBUG, "SSL filter unregistered...");
-
- super.removedService(reference, service);
- }
-
- void configureFilters(@SuppressWarnings("rawtypes") final Dictionary properties) throws ConfigurationException
- {
- this.filter.configure(properties);
- }
-}
diff --git a/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java b/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java
index db72c3b..09b890d 100644
--- a/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java
+++ b/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/SslFilterActivator.java
@@ -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 @@
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.httpTracker.close();
- this.httpTracker = null;
+ this.filterReg.unregister();
+ this.filterReg = null;
+ SystemLogger.log(LogService.LOG_DEBUG, "SSL filter unregistered...");
+ }
+ if (this.configReceiver != null)
+ {
+ this.configReceiver.unregister();
+ this.configReceiver = null;
}
if (this.logTracker != null)
{
@@ -50,4 +109,9 @@
this.logTracker = null;
}
}
+
+ void configureFilters(@SuppressWarnings("rawtypes") final Dictionary properties) throws ConfigurationException
+ {
+ this.filter.configure(properties);
+ }
}