felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1815882 - in /felix/trunk/http/whiteboard: ./ src/main/appended-resources/ src/main/appended-resources/META-INF/ src/main/java/org/apache/felix/http/whiteboard/ src/main/java/org/apache/felix/http/whiteboard/internal/ src/main/java/org/apa...
Date Tue, 21 Nov 2017 08:18:28 GMT
Author: cziegeler
Date: Tue Nov 21 08:18:28 2017
New Revision: 1815882

URL: http://svn.apache.org/viewvc?rev=1815882&view=rev
Log:
FELIX-5747 : Implement proprietary whiteboard based on R7 whiteboard

Added:
    felix/trunk/http/whiteboard/src/main/appended-resources/
    felix/trunk/http/whiteboard/src/main/appended-resources/META-INF/
    felix/trunk/http/whiteboard/src/main/appended-resources/META-INF/DEPENDENCIES
      - copied, changed from r1815881, felix/trunk/http/whiteboard/DEPENDENCIES
Removed:
    felix/trunk/http/whiteboard/DEPENDENCIES
    felix/trunk/http/whiteboard/LICENSE
    felix/trunk/http/whiteboard/NOTICE
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/DefaultHttpContext.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java
    felix/trunk/http/whiteboard/src/test/java/
Modified:
    felix/trunk/http/whiteboard/pom.xml
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
    felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java

Modified: felix/trunk/http/whiteboard/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/pom.xml?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/pom.xml (original)
+++ felix/trunk/http/whiteboard/pom.xml Tue Nov 21 08:18:28 2017
@@ -37,6 +37,10 @@
         <url>http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/</url>
     </scm>
 
+    <properties>
+        <felix.java.version>7</felix.java.version>
+    </properties>
+
     <build>
         <plugins>
             <plugin>
@@ -68,19 +72,21 @@
             <artifactId>osgi.core</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.cmpn</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.http.api</artifactId>
-            <version>3.0.0</version>
+            <version>3.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.log</artifactId>
+            <version>1.3.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.http.base</artifactId>
-            <version>3.0.0</version>
+            <version>3.0.19-R7-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
 

Copied: felix/trunk/http/whiteboard/src/main/appended-resources/META-INF/DEPENDENCIES (from
r1815881, felix/trunk/http/whiteboard/DEPENDENCIES)
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/appended-resources/META-INF/DEPENDENCIES?p2=felix/trunk/http/whiteboard/src/main/appended-resources/META-INF/DEPENDENCIES&p1=felix/trunk/http/whiteboard/DEPENDENCIES&r1=1815881&r2=1815882&rev=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/DEPENDENCIES (original)
+++ felix/trunk/http/whiteboard/src/main/appended-resources/META-INF/DEPENDENCIES Tue Nov
21 08:18:28 2017
@@ -1,19 +1,8 @@
-Apache Felix HTTP Service Whiteboard
-Copyright 2011 The Apache Software Foundation
-
-This software was developed at the Apache Software Foundation
-(http://www.apache.org) and may have dependencies on other
-Apache software licensed under Apache License 2.0.
-
-I. Included Third-Party Software
-
-N/A
-
 II. Used Third-Party Software
 
 This product uses software developed at
 The OSGi Alliance (http://www.osgi.org).
-Copyright (c) OSGi Alliance (2000, 2009).
+Copyright (c) OSGi Alliance (2000, 2017).
 Licensed under the Apache License 2.0.
 
 III. License Summary

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java
Tue Nov 21 08:18:28 2017
@@ -24,6 +24,7 @@ package org.apache.felix.http.whiteboard
  *
  * @since Http Whiteboard Bundle 2.3.0
  */
+@Deprecated
 public class HttpWhiteboardConstants
 {
 

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
Tue Nov 21 08:18:28 2017
@@ -16,69 +16,49 @@
  */
 package org.apache.felix.http.whiteboard.internal;
 
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.util.tracker.ServiceTracker;
+import java.util.ArrayList;
+
+import org.apache.felix.http.base.internal.AbstractActivator;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
 import org.apache.felix.http.whiteboard.internal.tracker.FilterTracker;
 import org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker;
 import org.apache.felix.http.whiteboard.internal.tracker.ServletTracker;
-import org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker;
-import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
-import org.apache.felix.http.whiteboard.internal.manager.HttpWhiteboardWebConsolePlugin;
-import org.apache.felix.http.base.internal.AbstractActivator;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import java.util.ArrayList;
-import java.util.Hashtable;
+import org.osgi.util.tracker.ServiceTracker;
 
 public final class WhiteboardActivator
     extends AbstractActivator
 {
-    private final ArrayList<ServiceTracker> trackers;
-    private ExtenderManager manager;
-    private ServiceRegistration httpPlugin;
-
-    public WhiteboardActivator()
-    {
-        this.trackers = new ArrayList<ServiceTracker>();
-    }
+    private final ArrayList<ServiceTracker<?, ?>> trackers = new ArrayList<>();
 
+    @Override
     protected void doStart()
         throws Exception
     {
-        this.manager = new ExtenderManager();
-        addTracker(new HttpContextTracker(getBundleContext(), this.manager));
-        addTracker(new FilterTracker(getBundleContext(), this.manager));
-        addTracker(new ServletTracker(getBundleContext(), this.manager));
-        addTracker(new HttpServiceTracker(getBundleContext(), this.manager));
-
-        HttpWhiteboardWebConsolePlugin plugin = new HttpWhiteboardWebConsolePlugin(this.manager);
-        Hashtable<String, Object> props = new Hashtable<String, Object>();
-        props.put("felix.webconsole.label", plugin.getLabel());
-        props.put("felix.webconsole.title", plugin.getTitle());
-        props.put("felix.webconsole.configprinter.modes", new String[]
-            { "txt", "zip" });
-        props.put(Constants.SERVICE_DESCRIPTION, "Felix Http Whiteboard WebConsole Plugin
and Configuration Printer");
-        httpPlugin = getBundleContext().registerService("javax.servlet.Servlet", plugin,
props);
+        final ExtenderManager manager = new ExtenderManager();
+        addTracker(new HttpContextTracker(getBundleContext(), manager));
+        addTracker(new FilterTracker(getBundleContext(), manager));
+        addTracker(new ServletTracker(getBundleContext(), manager));
 
-        SystemLogger.info("Http service whiteboard started");
+        SystemLogger.info("Apachde Felix Http Whiteboard Service started");
     }
 
-    private void addTracker(ServiceTracker tracker)
+    private void addTracker(ServiceTracker<?,?> tracker)
     {
         this.trackers.add(tracker);
         tracker.open();
     }
 
+    @Override
     protected void doStop()
         throws Exception
     {
-        this.httpPlugin.unregister();
-
-        for (ServiceTracker tracker : this.trackers) {
+        for (ServiceTracker<?,?> tracker : this.trackers) {
             tracker.close();
         }
 
         this.trackers.clear();
-        this.manager.unregisterAll();
+
+        SystemLogger.info("Apachde Felix Http Whiteboard Service stopped");
     }
 }

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
Tue Nov 21 08:18:28 2017
@@ -16,51 +16,89 @@
  */
 package org.apache.felix.http.whiteboard.internal.manager;
 
-import java.util.Collection;
-import java.util.HashMap;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
-import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
-import org.apache.felix.http.api.ExtHttpService;
 import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.apache.felix.http.whiteboard.HttpWhiteboardConstants;
-import org.apache.felix.http.whiteboard.internal.manager.HttpContextManager.HttpContextHolder;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.HttpService;
+import org.osgi.service.http.context.ServletContextHelper;
 
 public final class ExtenderManager
 {
-    static final String TYPE_FILTER = "f";
-    static final String TYPE_SERVLET = "s";
+    private static final String MARKER = "org.apache.felix.http.whiteboard";
 
-    private HttpService httpService;
-    private final Map<String, AbstractMapping> mapping;
-    private final HttpContextManager contextManager;
+    public enum Type {
+        CONTEXT,
+        FILTER,
+        SERVLET
+    }
+
+    private final Map<String, ServiceRegistration<?>> registrations = new ConcurrentHashMap<>();
 
-    public ExtenderManager()
+    /**
+     * Remove a service registration (if existing)
+     * @param type The type
+     * @param ref The service reference
+     */
+    private void removeServiceRegistration(final Type type, final ServiceReference<?>
ref)
     {
-        this.mapping = new HashMap<String, AbstractMapping>();
-        this.contextManager = new HttpContextManager();
+        final ServiceRegistration<?> reg = this.registrations.remove(type.name() +
String.valueOf(ref.getProperty(Constants.SERVICE_ID)));
+        if ( reg != null )
+        {
+            try
+            {
+                reg.unregister();
+            }
+            catch ( final IllegalStateException ignore)
+            {
+                // we ignore this
+            }
+        }
     }
 
-    static boolean isEmpty(final String value)
+    /**
+     * Add a service registration
+     * @param type The type of the registration
+     * @param ref The service reference
+     * @param reg The service registration
+     */
+    private void putServiceRegistration(final Type type, final ServiceReference<?>
ref, final ServiceRegistration<?> reg)
     {
-        return value == null || value.length() == 0;
+        this.registrations.put(type.name() + String.valueOf(ref.getProperty(Constants.SERVICE_ID)),
reg);
     }
 
-    private String getStringProperty(ServiceReference ref, String key)
+    /**
+     * Get a string property
+     * @param ref The service reference
+     * @param key The name of the property
+     * @return The value of the property if the type is String, {@code null} otherwise
+     */
+    private String getStringProperty(final ServiceReference<?> ref, final String key)
     {
         Object value = ref.getProperty(key);
         return (value instanceof String) ? (String)value : null;
     }
 
-    private boolean getBooleanProperty(ServiceReference ref, String key)
+    /**
+     * Get the boolean property.
+     * @param ref The service reference
+     * @param key The name of the property
+     * @return The value of the boolean property. Returns {@code false} as default
+     */
+    private boolean getBooleanProperty(final ServiceReference<?> ref, final String
key)
     {
         Object value = ref.getProperty(key);
         if (value instanceof String)
@@ -74,240 +112,245 @@ public final class ExtenderManager
         return false;
     }
 
-    private int getIntProperty(ServiceReference ref, String key, int defValue)
+    /**
+     * Get the boolean property.
+     * @param ref The service reference
+     * @param key The name of the property
+     * @param int default value
+     * @return The value of the int property. Returns the default value as default
+     */
+    private int getIntProperty(final ServiceReference<?> ref, final String key, final
int defValue)
     {
-        Object value = ref.getProperty(key);
+        final Object value = ref.getProperty(key);
         if (value == null) {
             return defValue;
         }
 
         try {
             return Integer.parseInt(value.toString());
-        } catch (Exception e) {
+        } catch (final Exception e) {
             return defValue;
         }
     }
 
-    private void addInitParams(ServiceReference ref, AbstractMapping mapping)
+    /**
+     * Add the init parameters
+     * @param ref The service reference
+     * @param prefix The prefix to use
+     * @param props The properties
+     */
+    private void addInitParams(final ServiceReference<?> ref, final String prefix,
final Dictionary<String, Object> props)
     {
-        for (String key : ref.getPropertyKeys()) {
+        for (final String key : ref.getPropertyKeys()) {
             if (key.startsWith(HttpWhiteboardConstants.INIT_PREFIX)) {
-                String paramKey = key.substring(HttpWhiteboardConstants.INIT_PREFIX.length());
-                String paramValue = getStringProperty(ref, key);
+                final String paramKey = key.substring(HttpWhiteboardConstants.INIT_PREFIX.length());
+                final Object paramValue = ref.getProperty(paramKey);
 
                 if (paramValue != null) {
-                    mapping.getInitParams().put(paramKey, paramValue);
+                    props.put(prefix + paramKey, paramValue);
                 }
             }
         }
     }
 
-    public void add(HttpContext service, ServiceReference ref)
+    /**
+     * Add the service ranking (if available)
+     * @param ref The service reference
+     * @param props The new properties
+     */
+    private void addServiceRanking(final ServiceReference<?> ref, final Dictionary<String,
Object> props)
     {
-        String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
-        if (!isEmpty(contextId))
+        // we don't care about the type and assume it's correct
+        final Object val = ref.getProperty(Constants.SERVICE_RANKING);
+        if ( val != null )
         {
-            boolean shared = getBooleanProperty(ref, HttpWhiteboardConstants.CONTEXT_SHARED);
-            Bundle bundle = shared ? null : ref.getBundle();
-            Collection<AbstractMapping> mappings = this.contextManager.addHttpContext(bundle,
contextId, service);
-            for (AbstractMapping mapping : mappings)
-            {
-                registerMapping(mapping);
-            }
-        }
-        else
-        {
-            SystemLogger.debug("Ignoring HttpContext Service " + ref + ", " + HttpWhiteboardConstants.CONTEXT_ID
-                + " is missing or empty");
+            props.put(Constants.SERVICE_RANKING, val);
         }
     }
 
-    public void remove(HttpContext service)
+    /**
+     * Add the context select property
+     * @param ref The service reference
+     * @param props The properties
+     */
+    private void addHttpContextSelect(final ServiceReference<?> ref, final Dictionary<String,
Object> props)
     {
-        Collection<AbstractMapping> mappings = this.contextManager.removeHttpContext(service);
-        if (mappings != null)
+        final String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
+        // if context id is missing, the default context is used
+        if ( contextId != null )
         {
-            for (AbstractMapping mapping : mappings)
-            {
-                unregisterMapping(mapping);
-            }
+            final StringBuilder select = new StringBuilder();
+            select.append("(!(");
+            select.append(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME);
+            select.append('=');
+            select.append(getHttpContextName(ref, contextId, false));
+            select.append(")(");
+            select.append(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME);
+            select.append('=');
+            select.append(getHttpContextName(ref, contextId, true));
+            select.append("))");
+            props.put(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
select.toString());
         }
     }
 
-    private void getHttpContext(AbstractMapping mapping, ServiceReference ref)
-    {
-        Bundle bundle = ref.getBundle();
-        String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
-        this.contextManager.getHttpContext(bundle, contextId, mapping);
-    }
-
-    private void ungetHttpContext(AbstractMapping mapping, ServiceReference ref)
-    {
-        Bundle bundle = ref.getBundle();
-        String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
-        this.contextManager.ungetHttpContext(bundle, contextId, mapping);
-    }
-
-    public void add(Filter service, ServiceReference ref)
-    {
-        int ranking = getIntProperty(ref, Constants.SERVICE_RANKING, 0);
-        String pattern = getStringProperty(ref, HttpWhiteboardConstants.PATTERN);
-
-        if (isEmpty(pattern)) {
-            SystemLogger.debug("Ignoring Filter Service " + ref + ", " + HttpWhiteboardConstants.PATTERN
-                + " is missing or empty");
-            return;
+    /**
+     * Return the http context name
+     * @param ref The service reference
+     * @return The name or {@code null}
+     */
+    private String getHttpContextName(final ServiceReference<?> ref,
+            final String contextId,
+            final boolean shared)
+    {
+        final StringBuilder name = new StringBuilder();
+        name.append(MARKER);
+        name.append('.');
+        if ( shared )
+        {
+            name.append("shared");
         }
-
-        FilterMapping mapping = new FilterMapping(ref.getBundle(), service, pattern, ranking);
-        getHttpContext(mapping, ref);
-        addInitParams(ref, mapping);
-        addMapping(TYPE_FILTER, ref, mapping);
-    }
-
-    public void add(Servlet service, ServiceReference ref)
-    {
-        String alias = getStringProperty(ref, HttpWhiteboardConstants.ALIAS);
-        if (isEmpty(alias))
+        else
         {
-            SystemLogger.debug("Ignoring Servlet Service " + ref + ", " + HttpWhiteboardConstants.ALIAS
-                + " is missing or empty");
-            return;
+            name.append(ref.getBundle().getBundleId());
         }
+        name.append('.');
+        name.append(contextId);
 
-        ServletMapping mapping = new ServletMapping(ref.getBundle(), service, alias);
-        getHttpContext(mapping, ref);
-        addInitParams(ref, mapping);
-        addMapping(TYPE_SERVLET, ref, mapping);
+        return name.toString();
     }
 
-    public void removeFilter(ServiceReference ref)
-    {
-        removeMapping(TYPE_FILTER, ref);
-    }
-
-    public void removeServlet(ServiceReference ref)
-    {
-        removeMapping(TYPE_SERVLET, ref);
-    }
-
-    public synchronized void setHttpService(HttpService service)
+    /**
+     * Add a HttpContext
+     * @param service The HttpContext
+     * @param ref The service reference
+     */
+    public void add(final HttpContext service, final ServiceReference<HttpContext>
ref)
     {
-        this.httpService = service;
-        if (this.httpService instanceof ExtHttpService) {
-            SystemLogger.info("Detected extended HttpService. Filters enabled.");
-        } else {
-            SystemLogger.info("Detected standard HttpService. Filters disabled.");
+        final String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
+        if (contextId != null && !contextId.isEmpty())
+        {
+            final boolean shared = getBooleanProperty(ref, HttpWhiteboardConstants.CONTEXT_SHARED);
+            final String contextName = getHttpContextName(ref, contextId, shared);
+            final Dictionary<String, Object> props = new Hashtable<>();
+            props.put(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME,
contextName);
+            props.put(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH,
"/");
+            props.put(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_SERVICE_CONTEXT_PROPERTY,
"true");
+            props.put(MARKER + ".id", contextId);
+            props.put(MARKER, "true");
+            this.addServiceRanking(ref, props);
+            final ServiceRegistration<ServletContextHelper> reg = ref.getBundle().getBundleContext().registerService(
+                    ServletContextHelper.class,
+                    new ServletContextHelper() {
+
+                        @Override
+                        public boolean handleSecurity(final HttpServletRequest request, final
HttpServletResponse response)
+                                throws IOException {
+                            return service.handleSecurity(request, response);
+                        }
+
+                        @Override
+                        public URL getResource(final String name) {
+                            return service.getResource(name);
+                        }
+
+                        @Override
+                        public String getMimeType(final String name) {
+                            return service.getMimeType(name);
+                        }
+
+                    },
+                    props);
+            this.putServiceRegistration(Type.CONTEXT, ref, reg);
+        }
+        else
+        {
+            SystemLogger.debug("Ignoring HttpContext Service " + ref + ", " + HttpWhiteboardConstants.CONTEXT_ID
+                + " is missing or empty");
         }
-
-        registerAll();
-    }
-
-    public synchronized void unsetHttpService()
-    {
-        unregisterAll();
-        this.httpService = null;
-    }
-
-    public synchronized void unregisterAll()
-    {
-    	AbstractMapping[] mappings = null;
-    	HttpService service;
-    	synchronized (this) {
-			service = this.httpService;
-			if (service != null) {
-    			Collection<AbstractMapping> values = this.mapping.values();
-    			mappings = values.toArray(new AbstractMapping[values.size()]);
-    		}
-    	}
-    	if (mappings != null) {
-    		for (AbstractMapping mapping : mappings) {
-    			mapping.unregister(service);
-    		}
-    	}
     }
 
-    private synchronized void registerAll()
+    /**
+     * Remove a HttpContext
+     * @param ref The service reference
+     */
+    public void remove(final ServiceReference<HttpContext> ref)
     {
-    	AbstractMapping[] mappings = null;
-    	HttpService service;
-    	synchronized (this) {
-			service = this.httpService;
-			if (service != null) {
-    			Collection<AbstractMapping> values = this.mapping.values();
-    			mappings = values.toArray(new AbstractMapping[values.size()]);
-    		}
-    	}
-    	if (mappings != null) {
-    		for (AbstractMapping mapping : mappings) {
-    			mapping.register(service);
-    		}
-    	}
+        this.removeServiceRegistration(Type.CONTEXT, ref);
     }
 
-    private synchronized void addMapping(final String servType, ServiceReference ref, AbstractMapping
mapping)
+    /**
+     * Add a filter.
+     * @param service The filter
+     * @param ref The filter reference
+     */
+    public void add(final Filter service, final ServiceReference<Filter> ref)
     {
-        this.mapping.put(ref.getProperty(Constants.SERVICE_ID).toString() + servType, mapping);
-        this.registerMapping(mapping);
-    }
+        final String pattern = getStringProperty(ref, HttpWhiteboardConstants.PATTERN);
 
-    private synchronized void removeMapping(final String servType, ServiceReference ref)
-    {
-        AbstractMapping mapping = this.mapping.remove(ref.getProperty(Constants.SERVICE_ID).toString()
+ servType);
-        if (mapping != null)
-        {
-            ungetHttpContext(mapping, ref);
-            unregisterMapping(mapping);
+        if (pattern == null || pattern.isEmpty()) {
+            SystemLogger.debug("Ignoring Filter Service " + ref + ", " + HttpWhiteboardConstants.PATTERN
+                + " is missing or empty");
+            return;
         }
-    }
 
-    private void registerMapping(AbstractMapping mapping)
-    {
-        HttpService httpService = this.httpService;
-        if (httpService != null)
-        {
-            mapping.register(httpService);
-        }
+        final Dictionary<String, Object> props = new Hashtable<>();
+        props.put(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN,
pattern);
+        props.put(MARKER, "true");
+        this.addHttpContextSelect(ref, props);
+        this.addInitParams(ref, org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX,
props);
+        this.addServiceRanking(ref, props);
+
+        final ServiceRegistration<Filter> reg = ref.getBundle().getBundleContext().registerService(
+                Filter.class,
+                service,
+                props);
+        this.putServiceRegistration(Type.FILTER, ref, reg);
     }
 
-    private void unregisterMapping(AbstractMapping mapping)
+    /**
+     * Add a servlet.
+     * @param service The servlet
+     * @param ref The service reference
+     */
+    public void add(final Servlet service, final ServiceReference<Servlet> ref)
     {
-        HttpService httpService = this.httpService;
-        if (httpService != null)
+        final String alias = getStringProperty(ref, HttpWhiteboardConstants.ALIAS);
+        if (alias == null || alias.isEmpty() || !alias.startsWith("/"))
         {
-            mapping.unregister(httpService);
+            SystemLogger.debug("Ignoring Servlet Service " + ref + ", " + HttpWhiteboardConstants.ALIAS
+                + " is missing, empty or invalid");
+            return;
         }
-    }
 
-    /**
-     * Returns
-     * {@link org.apache.felix.http.whiteboard.internal.manager.HttpContextManager.HttpContextHolder}
-     * instances of HttpContext services.
-     *
-     * @return
-     */
-    Map<String, HttpContextHolder> getHttpContexts()
-    {
-        return this.contextManager.getHttpContexts();
+        final Dictionary<String, Object> props = new Hashtable<>();
+        props.put(org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN,
alias);
+        props.put(MARKER, "true");
+        this.addHttpContextSelect(ref, props);
+        this.addInitParams(ref, org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX,
props);
+        this.addServiceRanking(ref, props);
+
+        final ServiceRegistration<Servlet> reg = ref.getBundle().getBundleContext().registerService(
+                Servlet.class,
+                service,
+                props);
+        this.putServiceRegistration(Type.SERVLET, ref, reg);
     }
 
     /**
-     * Returns {@link AbstractMapping} instances for which there is no
-     * registered HttpContext as desired by the context ID.
+     * Remove a filter
+     * @param ref The filter reference
      */
-    Map<String, Set<AbstractMapping>> getOrphanMappings()
+    public void removeFilter(final ServiceReference<Filter> ref)
     {
-        return this.contextManager.getOrphanMappings();
+        this.removeServiceRegistration(Type.FILTER, ref);
     }
 
     /**
-     * Returns mappings indexed by there owning OSGi service.
+     * Remove a servlet
+     * @param ref The service reference
      */
-    Map<String, AbstractMapping> getMappings()
+    public void removeServlet(final ServiceReference<Servlet> ref)
     {
-        synchronized (this)
-        {
-            return new HashMap<String, AbstractMapping>(this.mapping);
-        }
+        this.removeServiceRegistration(Type.SERVLET, ref);
     }
 }

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
Tue Nov 21 08:18:28 2017
@@ -16,51 +16,65 @@
  */
 package org.apache.felix.http.whiteboard.internal.tracker;
 
+import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
 public abstract class AbstractTracker<T>
-    extends ServiceTracker
+    extends ServiceTracker<T, T>
 {
-    public AbstractTracker(BundleContext context, Filter filter)
+    public AbstractTracker(final BundleContext context, final Filter filter)
     {
         super(context, filter, null);
     }
 
-    public AbstractTracker(BundleContext context, Class clazz)
+    public AbstractTracker(final BundleContext context, final Class<T> clazz)
     {
         super(context, clazz.getName(), null);
     }
 
+    protected void logDeprecationWarning(final String id, final T service, final ServiceReference<T>
ref)
+    {
+        SystemLogger.warning("Deprecation warning: " +
+                    id + " registered through Apache Felix whiteboard service: " + getInfo(service,
ref) +
+                    ". Please change your code to use the OSGi Http Whiteboard Service.",
null);
+    }
+
+    private String getInfo(final T service, final ServiceReference<T> ref)
+    {
+        return "Service " + ref.getProperty(Constants.SERVICE_PID) + " from bundle "
+                + ref.getBundle().getBundleId()
+                + (ref.getBundle().getSymbolicName() != null ? ref.getBundle().getSymbolicName()
+ ":" + ref.getBundle().getVersion() : "")
+                + " class " + service.getClass();
+    }
+
     @Override
-    @SuppressWarnings("unchecked")
-    public final Object addingService(ServiceReference ref)
+    public final T addingService(final ServiceReference<T> ref)
     {
-        T service = (T)super.addingService(ref);
+        T service = super.addingService(ref);
         added(service, ref);
         return service;
     }
 
     @Override
-    @SuppressWarnings("unchecked")
-    public final void modifiedService(ServiceReference ref, Object service)
+    public final void modifiedService(final ServiceReference<T> ref, T service)
     {
-        modified( (T)service, ref);
+        modified( service, ref);
     }
 
     @Override
-    @SuppressWarnings("unchecked")
-    public final void removedService(ServiceReference ref, Object service)
+    public final void removedService(final ServiceReference<T> ref, T service)
     {
         super.removedService(ref, service);
-        removed((T) service, ref);
+        removed(service, ref);
     }
 
-    protected abstract void modified(T service, ServiceReference ref);
+    protected abstract void modified(T service, ServiceReference<T> ref);
 
-    protected abstract void added(T service, ServiceReference ref);
+    protected abstract void added(T service, ServiceReference<T> ref);
 
-    protected abstract void removed(T service, ServiceReference ref);
+    protected abstract void removed(T service, ServiceReference<T> ref);
 }

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
Tue Nov 21 08:18:28 2017
@@ -18,7 +18,6 @@ package org.apache.felix.http.whiteboard
 
 import javax.servlet.Filter;
 
-import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.apache.felix.http.whiteboard.HttpWhiteboardConstants;
 import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
 import org.osgi.framework.BundleContext;
@@ -45,31 +44,28 @@ public final class FilterTracker
         return null; // we never get here - and if we get an NPE which is fine
     }
 
-    public FilterTracker(BundleContext context, ExtenderManager manager)
+    public FilterTracker(final BundleContext context, final ExtenderManager manager)
     {
         super(context, createFilter(context));
         this.manager = manager;
     }
 
     @Override
-    protected void added(Filter service, ServiceReference ref)
+    protected void added(final Filter service, final ServiceReference<Filter> ref)
     {
-        SystemLogger.warning("Deprecation warning: " +
-                "Filter registered through Apache Felix whiteboard service: " + ref +
-                ". Please change your code to the OSGi Http Whiteboard Service.", null);
-
+        logDeprecationWarning("Filter", service, ref);
         this.manager.add(service, ref);
     }
 
     @Override
-    protected void modified(Filter service, ServiceReference ref)
+    protected void modified(final Filter service, final ServiceReference<Filter> ref)
     {
         removed(service, ref);
         added(service, ref);
     }
 
     @Override
-    protected void removed(Filter service, ServiceReference ref)
+    protected void removed(final Filter service, final ServiceReference<Filter> ref)
     {
         this.manager.removeFilter(ref);
     }

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
Tue Nov 21 08:18:28 2017
@@ -16,7 +16,6 @@
  */
 package org.apache.felix.http.whiteboard.internal.tracker;
 
-import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -27,32 +26,29 @@ public final class HttpContextTracker
 {
     private final ExtenderManager manager;
 
-    public HttpContextTracker(BundleContext context, ExtenderManager manager)
+    public HttpContextTracker(final BundleContext context, final ExtenderManager manager)
     {
         super(context, HttpContext.class);
         this.manager = manager;
     }
 
     @Override
-    protected void added(HttpContext service, ServiceReference ref)
+    protected void added(final HttpContext service, final ServiceReference<HttpContext>
ref)
     {
-        SystemLogger.warning("Deprecation warning: " +
-                "HttpContext registered through Apache Felix whiteboard service: " + ref
+
-                ". Please change your code to the OSGi Http Whiteboard Service.", null);
-
+        this.logDeprecationWarning("HttpContext", service, ref);
         this.manager.add(service, ref);
     }
 
     @Override
-    protected void modified(HttpContext service, ServiceReference ref)
+    protected void modified(final HttpContext service, final ServiceReference<HttpContext>
ref)
     {
         removed(service, ref);
         added(service, ref);
     }
 
     @Override
-    protected void removed(HttpContext service, ServiceReference ref)
+    protected void removed(final HttpContext service, final ServiceReference<HttpContext>
ref)
     {
-        this.manager.remove(service);
+        this.manager.remove(ref);
     }
 }

Modified: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java?rev=1815882&r1=1815881&r2=1815882&view=diff
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
(original)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
Tue Nov 21 08:18:28 2017
@@ -18,7 +18,6 @@ package org.apache.felix.http.whiteboard
 
 import javax.servlet.Servlet;
 
-import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.apache.felix.http.whiteboard.HttpWhiteboardConstants;
 import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
 import org.osgi.framework.BundleContext;
@@ -45,30 +44,28 @@ public final class ServletTracker
         return null; // we never get here - and if we get an NPE which is fine
     }
 
-    public ServletTracker(BundleContext context, ExtenderManager manager)
+    public ServletTracker(final BundleContext context, final ExtenderManager manager)
     {
         super(context, createFilter(context));
         this.manager = manager;
     }
 
     @Override
-    protected void added(Servlet service, ServiceReference ref)
+    protected void added(final Servlet service, final ServiceReference<Servlet> ref)
     {
-        SystemLogger.warning("Deprecation warning: " +
-                "Servlet registered through Apache Felix whiteboard service: " + ref +
-                ". Please change your code to the OSGi Http Whiteboard Service.", null);
+        logDeprecationWarning("Servlet", service, ref);
         this.manager.add(service, ref);
     }
 
     @Override
-    protected void modified(Servlet service, ServiceReference ref)
+    protected void modified(final Servlet service, final ServiceReference<Servlet>
ref)
     {
         removed(service, ref);
         added(service, ref);
     }
 
     @Override
-    protected void removed(Servlet service, ServiceReference ref)
+    protected void removed(final Servlet service, final ServiceReference<Servlet> ref)
     {
         this.manager.removeServlet(ref);
     }



Mime
View raw message