Author: cziegeler
Date: Mon Aug  1 14:17:58 2016
New Revision: 1754755

URL: http://svn.apache.org/viewvc?rev=1754755&view=rev
Log:
SLING-5782 : Register Sling using the Http Whiteboard

Modified:
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpContext.java
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpContext.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpContext.java?rev=1754755&r1=1754754&r2=1754755&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpContext.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpContext.java
 Mon Aug  1 14:17:58 2016
@@ -29,7 +29,7 @@ import org.apache.sling.auth.core.Authen
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.engine.impl.parameters.ParameterSupport;
 import org.apache.sling.engine.impl.request.SlingRequestProgressTracker;
-import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.context.ServletContextHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,10 +37,10 @@ import org.slf4j.LoggerFactory;
  * The <code>SlingHttpContext</code> implements the OSGi HttpContext used to
  * register the {@link SlingMainServlet} with the OSGi HttpService.
  */
-class SlingHttpContext implements HttpContext {
+class SlingHttpContext extends ServletContextHelper {
 
-    /** default log */
-    private static final Logger log = 
LoggerFactory.getLogger(SlingHttpContext.class);
+    /** Logger */
+    private final Logger log = LoggerFactory.getLogger(SlingHttpContext.class);
 
     /**
      * Resolves MIME types
@@ -84,6 +84,7 @@ class SlingHttpContext implements HttpCo
      * Returns the MIME type as resolved by the <code>MimeTypeService</code> or
      * <code>null</code> if the service is not available.
      */
+    @Override
     public String getMimeType(String name) {
         MimeTypeService mtservice = mimeTypeService;
         if (mtservice != null) {
@@ -100,6 +101,7 @@ class SlingHttpContext implements HttpCo
      * Always returns <code>null</code> because resources are all provided
      * through the {@link SlingMainServlet}.
      */
+    @Override
     public URL getResource(String name) {
         return null;
     }
@@ -110,6 +112,7 @@ class SlingHttpContext implements HttpCo
      * is missing this method returns <code>false</code> and sends a 
503/SERVICE
      * UNAVAILABLE status back to the client.
      */
+    @Override
     public boolean handleSecurity(HttpServletRequest request,
             HttpServletResponse response) throws IOException {
 
@@ -117,7 +120,7 @@ class SlingHttpContext implements HttpCo
         request.setAttribute(RequestProgressTracker.class.getName(), t);
         final String timerName = "handleSecurity";
         t.startTimer(timerName);
-        
+
         final AuthenticationSupport authenticator = this.authenticationSupport;
         if (authenticator != null) {
 

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=1754755&r1=1754754&r2=1754755&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
 Mon Aug  1 14:17:58 2016
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.regex.Pattern;
 
 import javax.servlet.GenericServlet;
+import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
@@ -63,7 +64,8 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
-import org.osgi.service.http.HttpService;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -118,9 +120,6 @@ public class SlingMainServlet extends Ge
             unbounded = PropertyUnbounded.ARRAY)
     private static final String PROP_ADDITIONAL_RESPONSE_HEADERS = 
"sling.additional.response.headers";
 
-    @Reference
-    private HttpService httpService;
-
     @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = 
ReferencePolicy.DYNAMIC)
     private volatile AdapterManager adapterManager;
 
@@ -134,6 +133,11 @@ public class SlingMainServlet extends Ge
     private static final String SLING_ROOT = "/";
 
     /**
+     * The name of the servlet context for Sling
+     */
+    private static final String SERVLET_CONTEXT_NAME = "org.apache.sling";
+
+    /**
      * The name of the product to report in the {@link #getServerInfo()} method
      * (value is "ApacheSling").
      */
@@ -175,9 +179,13 @@ public class SlingMainServlet extends Ge
 
     private final SlingRequestProcessorImpl requestProcessor = new 
SlingRequestProcessorImpl();
 
-    private ServiceRegistration requestProcessorRegistration;
+    private ServiceRegistration<SlingRequestProcessor> 
requestProcessorRegistration;
+
+    private ServiceRegistration<RequestProcessorMBean> 
requestProcessorMBeanRegistration;
+
+    private ServiceRegistration<ServletContextHelper> contextRegistration;
 
-    private ServiceRegistration requestProcessorMBeanRegistration;
+    private ServiceRegistration<Servlet> servletRegistration;
 
     private String configuredServerInfo;
 
@@ -389,18 +397,25 @@ public class SlingMainServlet extends Ge
                 + " is obsolete and ignored");
         }
 
-        // register the servlet and resources
-        try {
-            Dictionary<String, String> servletConfig = 
toStringConfig(configuration);
-
-            this.httpService.registerServlet(SLING_ROOT, this, servletConfig,
-                slingHttpContext);
-
-            log.info("{} ready to serve requests", this.getServerInfo());
+        // register the servlet context
+        final Dictionary<String, String> contextProperties = new Hashtable<>();
+        
contextProperties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, 
SERVLET_CONTEXT_NAME);
+        
contextProperties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, 
SLING_ROOT);
+        contextProperties.put(Constants.SERVICE_DESCRIPTION, "Apache Sling 
Engine Servlet Context Helper");
+        contextProperties.put(Constants.SERVICE_VENDOR, "The Apache Software 
Foundation");
+
+        this.contextRegistration = 
bundleContext.registerService(ServletContextHelper.class, 
this.slingHttpContext, contextProperties);
+
+        // register the servlet
+        final Dictionary<String, String> servletConfig = 
toStringConfig(configuration);
+        
servletConfig.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
+                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + 
"=" + SERVLET_CONTEXT_NAME + ")");
+        
servletConfig.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, 
SLING_ROOT);
+        servletConfig.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Engine 
Main Servlet");
+        servletConfig.put(Constants.SERVICE_VENDOR, "The Apache Software 
Foundation");
+        this.servletRegistration = 
bundleContext.registerService(Servlet.class, this, servletConfig);
 
-        } catch (Exception e) {
-            log.error("Cannot register " + this.getServerInfo(), e);
-        }
+        log.info("{} ready to serve requests", this.getServerInfo());
 
         // now that the sling main servlet is registered with the HttpService
         // and initialized we can register the servlet context
@@ -444,7 +459,7 @@ public class SlingMainServlet extends Ge
             mbeanProps.put("jmx.objectname", 
"org.apache.sling:type=engine,service=RequestProcessor");
 
             RequestProcessorMBeanImpl mbean = new RequestProcessorMBeanImpl();
-            requestProcessorMBeanRegistration = 
bundleContext.registerService(RequestProcessorMBean.class.getName(), mbean, 
mbeanProps);
+            requestProcessorMBeanRegistration = 
bundleContext.registerService(RequestProcessorMBean.class, mbean, mbeanProps);
             requestProcessor.setMBean(mbean);
         } catch (Throwable t) {
             log.debug("Unable to register mbean");
@@ -455,7 +470,7 @@ public class SlingMainServlet extends Ge
         srpProps.put(Constants.SERVICE_VENDOR, "The Apache Software 
Foundation");
         srpProps.put(Constants.SERVICE_DESCRIPTION, "Sling Request Processor");
         requestProcessorRegistration = bundleContext.registerService(
-            SlingRequestProcessor.NAME, requestProcessor, srpProps);
+            SlingRequestProcessor.class, requestProcessor, srpProps);
     }
 
     @Override
@@ -498,13 +513,21 @@ public class SlingMainServlet extends Ge
 
         // second unregister the servlet context *before* unregistering
         // and destroying the the sling main servlet
+        if ( this.contextRegistration != null ) {
+            this.contextRegistration.unregister();
+            this.contextRegistration = null;
+        }
         if (slingServletContext != null) {
             slingServletContext.dispose();
             slingServletContext = null;
         }
 
         // third unregister and destroy the sling main servlet
-        httpService.unregister(SLING_ROOT);
+        // unregister servlet
+        if ( this.servletRegistration != null ) {
+            this.servletRegistration.unregister();
+            this.servletRegistration = null;
+        }
 
         // dispose of request listener manager after unregistering the servlet
         // to prevent a potential NPE in the service method

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java?rev=1754755&r1=1754754&r2=1754755&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/ServletFilterManager.java
 Mon Aug  1 14:17:58 2016
@@ -35,12 +35,12 @@ import org.apache.sling.engine.jmx.Filte
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.osgi.framework.ServiceRegistration;
 
-public class ServletFilterManager extends ServiceTracker {
+public class ServletFilterManager extends ServiceTracker<Filter, Filter> {
 
     public static enum FilterChainType {
         /**
@@ -96,9 +96,6 @@ public class ServletFilterManager extend
      */
     private static String FELIX_WHITEBOARD_PATTERN_PROPERTY = "pattern";
 
-    // TODO: use filter (&(objectclass=javax.servlet.Filter)(filter.scope=*))
-    private static final String FILTER_SERVICE_NAME = Filter.class.getName();
-
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -107,13 +104,13 @@ public class ServletFilterManager extend
     private final SlingFilterChainHelper[] filterChains;
 
     private final boolean compatMode;
-    
-    private Map <Long, ServiceRegistration> mbeanMap;
+
+    private Map <Long, ServiceRegistration<FilterProcessorMBean>> mbeanMap;
 
     public ServletFilterManager(final BundleContext context,
             final SlingServletContext servletContext,
             final boolean compatMode) {
-        super(context, FILTER_SERVICE_NAME, null);
+        super(context, Filter.class, null);
         this.servletContext = servletContext;
         this.filterChains = new 
SlingFilterChainHelper[FilterChainType.values().length];
         this.filterChains[FilterChainType.REQUEST.ordinal()] = new 
SlingFilterChainHelper();
@@ -122,7 +119,7 @@ public class ServletFilterManager extend
         this.filterChains[FilterChainType.FORWARD.ordinal()] = new 
SlingFilterChainHelper();
         this.filterChains[FilterChainType.COMPONENT.ordinal()] = new 
SlingFilterChainHelper();
         this.compatMode = compatMode;
-        this.mbeanMap = new HashMap<Long, ServiceRegistration>();
+        this.mbeanMap = new HashMap<Long, 
ServiceRegistration<FilterProcessorMBean>>();
     }
 
     public SlingFilterChainHelper getFilterChain(final FilterChainType chain) {
@@ -134,161 +131,164 @@ public class ServletFilterManager extend
     }
 
     @Override
-    public Object addingService(ServiceReference reference) {
-        Object service = super.addingService(reference);
-        if (service instanceof Filter) {
-            initFilter(reference, (Filter) service);
+    public Filter addingService(ServiceReference<Filter> reference) {
+        if ( this.excludeFilter(reference) ) {
+            return null;
+        }
+        Filter service = super.addingService(reference);
+        if (service != null) {
+            initFilter(reference, service);
         }
         return service;
     }
 
     @Override
-    public void modifiedService(ServiceReference reference, Object service) {
-        if (service instanceof Filter) {
-            destroyFilter(reference, (Filter) service);
-            initFilter(reference, (Filter) service);
+    public void modifiedService(ServiceReference<Filter> reference, Filter 
service) {
+        destroyFilter(reference, service);
+        if ( !this.excludeFilter(reference) ) {
+            initFilter(reference, service);
         }
-
-        super.modifiedService(reference, service);
     }
 
     @Override
-    public void removedService(ServiceReference reference, Object service) {
-        if (service instanceof Filter) {
-            destroyFilter(reference, (Filter) service);
+    public void removedService(ServiceReference<Filter> reference, Filter 
service) {
+        if ( service != null ) {
+            destroyFilter(reference, service);
+            super.removedService(reference, service);
         }
-        super.removedService(reference, service);
     }
 
     /**
      * Check if the filter should be excluded.
      */
-    private boolean excludeFilter(final ServiceReference reference) {
+    private boolean excludeFilter(final ServiceReference<Filter> reference) {
+        boolean exclude = true;
         // if the service has a filter scope property, we include it
         if ( reference.getProperty(EngineConstants.SLING_FILTER_SCOPE) != null
              || reference.getProperty(EngineConstants.FILTER_SCOPE) != null ) {
-            return false;
+            exclude = false;
+        } else {
+            // in compat mode we allow all filters not having the felix 
pattern prop!
+            if ( this.compatMode ) {
+                // Check if filter will be registered by Felix HttpService 
Whiteboard
+                if (reference.getProperty(FELIX_WHITEBOARD_PATTERN_PROPERTY) 
== null) {
+                    exclude = false;
+                }
+            }
         }
-        // in compat mode we allow all filters not having the felix pattern 
prop!
-        if ( this.compatMode ) {
-            // Check if filter will be registered by Felix HttpService 
Whiteboard
-            if (reference.getProperty(FELIX_WHITEBOARD_PATTERN_PROPERTY) != 
null) {
-                return true;
+        if ( !exclude ) {
+            final String filterName = SlingFilterConfig.getName(reference);
+            if (filterName == null) {
+                log.error("initFilter: Missing name for filter {}", reference);
+                exclude = true;
             }
-            return false;
         }
-        return true;
+        return exclude;
     }
 
-    private void initFilter(final ServiceReference reference,
+    private void initFilter(final ServiceReference<Filter> reference,
             final Filter filter) {
-        if ( this.excludeFilter(reference) ) {
-            return;
-        }
+        // we already checked name in excludeFilter()
         final String filterName = SlingFilterConfig.getName(reference);
-        if (filterName == null) {
-            log.error("initFilter: Missing name for filter {}", reference);
-        } else {
 
-            // initialize the filter first
+        // initialize the filter first
+        try {
+            // service id
+            final Long serviceId = (Long) 
reference.getProperty(Constants.SERVICE_ID);
+
+            FilterProcessorMBeanImpl mbean;
             try {
-                // service id
-                final Long serviceId = (Long) 
reference.getProperty(Constants.SERVICE_ID);                
-                
-                FilterProcessorMBeanImpl mbean;
-                try {
-                    Dictionary<String, String> mbeanProps = new 
Hashtable<String, String>();
-                    mbeanProps.put("jmx.objectname", 
"org.apache.sling:type=engine-filter,service="+filterName);
-                    mbean = new FilterProcessorMBeanImpl();
-                    ServiceRegistration filterProcessorMBeanRegistration = 
context.registerService(FilterProcessorMBean.class.getName(), mbean, 
mbeanProps);
-                    mbeanMap.put(serviceId,filterProcessorMBeanRegistration);  
                  
-                } catch (Throwable t) {
-                    log.debug("Unable to register mbean", t);
-                    mbean = null;
-                }
-                
-                final FilterConfig config = new SlingFilterConfig(
-                    servletContext, reference, filterName);
-                filter.init(config);
-
-                // get the order, Integer.MAX_VALUE by default
-                final String orderSource;
-                Object orderObj = 
reference.getProperty(Constants.SERVICE_RANKING);
-                if (orderObj == null) {
-                    // filter order is defined as lower value has higher
-                    // priority while service ranking is the opposite In
-                    // addition we allow different types than Integer
-                    orderObj = 
reference.getProperty(EngineConstants.FILTER_ORDER);
-                    if (orderObj != null) {
-                        // we can use 0 as the default as this will be applied
-                        // in the next step anyway if this props contains an
-                        // invalid value
-                        orderSource = EngineConstants.FILTER_ORDER + "=" + 
orderObj;
-                        orderObj = Integer.valueOf(-1 * 
OsgiUtil.toInteger(orderObj, 0));
-                    } else {
-                        orderSource = "none";
-                    }
+                final Dictionary<String, String> mbeanProps = new 
Hashtable<String, String>();
+                mbeanProps.put("jmx.objectname", 
"org.apache.sling:type=engine-filter,service="+filterName);
+                mbean = new FilterProcessorMBeanImpl();
+                ServiceRegistration<FilterProcessorMBean> 
filterProcessorMBeanRegistration = 
context.registerService(FilterProcessorMBean.class, mbean, mbeanProps);
+                mbeanMap.put(serviceId,filterProcessorMBeanRegistration);
+            } catch (Throwable t) {
+                log.debug("Unable to register mbean", t);
+                mbean = null;
+            }
+
+            final FilterConfig config = new SlingFilterConfig(
+                servletContext, reference, filterName);
+            filter.init(config);
+
+            // get the order, Integer.MAX_VALUE by default
+            final String orderSource;
+            Object orderObj = reference.getProperty(Constants.SERVICE_RANKING);
+            if (orderObj == null) {
+                // filter order is defined as lower value has higher
+                // priority while service ranking is the opposite In
+                // addition we allow different types than Integer
+                orderObj = reference.getProperty(EngineConstants.FILTER_ORDER);
+                if (orderObj != null) {
+                    // we can use 0 as the default as this will be applied
+                    // in the next step anyway if this props contains an
+                    // invalid value
+                    orderSource = EngineConstants.FILTER_ORDER + "=" + 
orderObj;
+                    orderObj = Integer.valueOf(-1 * 
OsgiUtil.toInteger(orderObj, 0));
                 } else {
-                    orderSource = Constants.SERVICE_RANKING + "=" + orderObj;
+                    orderSource = "none";
                 }
-                final int order = (orderObj instanceof Integer) ? ((Integer) 
orderObj).intValue() : 0;
+            } else {
+                orderSource = Constants.SERVICE_RANKING + "=" + orderObj;
+            }
+            final int order = (orderObj instanceof Integer) ? ((Integer) 
orderObj).intValue() : 0;
 
-                // register by scope
-                String[] scopes = OsgiUtil.toStringArray(
-                        
reference.getProperty(EngineConstants.SLING_FILTER_SCOPE), null);
-                
-                String pattern = 
OsgiUtil.toString(reference.getProperty(EngineConstants.SLING_FILTER_PATTERN), 
"");
-                
-                if ( scopes == null ) {
-                    scopes = OsgiUtil.toStringArray(
-                        reference.getProperty(EngineConstants.FILTER_SCOPE), 
null);
-                }
-                if (scopes != null && scopes.length > 0) {
-                    for (String scope : scopes) {
-                        scope = scope.toUpperCase();
-                        try {
-                            FilterChainType type = 
FilterChainType.valueOf(scope.toString());
-                            getFilterChain(type).addFilter(filter, pattern, 
serviceId,
-                                order, orderSource, mbean);
-
-                            if (type == FilterChainType.COMPONENT) {
-                                
getFilterChain(FilterChainType.INCLUDE).addFilter(
-                                    filter, pattern, serviceId, order, 
orderSource, mbean);
-                                
getFilterChain(FilterChainType.FORWARD).addFilter(
-                                    filter, pattern, serviceId, order, 
orderSource, mbean);
-                            }
+            // register by scope
+            String[] scopes = OsgiUtil.toStringArray(
+                    reference.getProperty(EngineConstants.SLING_FILTER_SCOPE), 
null);
 
-                        } catch (IllegalArgumentException iae) {
-                            // TODO: log ...
+            String pattern = 
OsgiUtil.toString(reference.getProperty(EngineConstants.SLING_FILTER_PATTERN), 
"");
+
+            if ( scopes == null ) {
+                scopes = OsgiUtil.toStringArray(
+                    reference.getProperty(EngineConstants.FILTER_SCOPE), null);
+            }
+            if (scopes != null && scopes.length > 0) {
+                for (String scope : scopes) {
+                    scope = scope.toUpperCase();
+                    try {
+                        FilterChainType type = 
FilterChainType.valueOf(scope.toString());
+                        getFilterChain(type).addFilter(filter, pattern, 
serviceId,
+                            order, orderSource, mbean);
+
+                        if (type == FilterChainType.COMPONENT) {
+                            getFilterChain(FilterChainType.INCLUDE).addFilter(
+                                filter, pattern, serviceId, order, 
orderSource, mbean);
+                            getFilterChain(FilterChainType.FORWARD).addFilter(
+                                filter, pattern, serviceId, order, 
orderSource, mbean);
                         }
+
+                    } catch (IllegalArgumentException iae) {
+                        // TODO: log ...
                     }
-                } else {
-                    log.warn(String.format(
-                        "A Filter (Service ID %s) has been registered without 
a filter.scope property.",
-                        reference.getProperty(Constants.SERVICE_ID)));
-                    getFilterChain(FilterChainType.REQUEST).addFilter(filter, 
pattern,
-                        serviceId, order, orderSource,mbean);
                 }
-
-            } catch (ServletException ce) {
-                log.error("Filter " + filterName + " failed to initialize", 
ce);
-            } catch (Throwable t) {
-                log.error("Unexpected Problem initializing ComponentFilter "
-                    + "", t);
+            } else {
+                log.warn(String.format(
+                    "A Filter (Service ID %s) has been registered without a 
filter.scope property.",
+                    reference.getProperty(Constants.SERVICE_ID)));
+                getFilterChain(FilterChainType.REQUEST).addFilter(filter, 
pattern,
+                    serviceId, order, orderSource,mbean);
             }
+
+        } catch (ServletException ce) {
+            log.error("Filter " + filterName + " failed to initialize", ce);
+        } catch (Throwable t) {
+            log.error("Unexpected Problem initializing ComponentFilter "
+                + "", t);
         }
     }
 
-    private void destroyFilter(final ServiceReference reference,
+    private void destroyFilter(final ServiceReference<Filter> reference,
             final Filter filter) {
         // service id
         Object serviceId = reference.getProperty(Constants.SERVICE_ID);
-        
-        ServiceRegistration mbean = mbeanMap.remove((Long) serviceId);
+
+        ServiceRegistration<FilterProcessorMBean> mbean = 
mbeanMap.remove(serviceId);
         if (mbean != null) {
             mbean.unregister();
         }
-        
+
         boolean removed = false;
         for (SlingFilterChainHelper filterChain : filterChains) {
             removed |= filterChain.removeFilterById(serviceId);

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java?rev=1754755&r1=1754754&r2=1754755&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingServletContext.java
 Mon Aug  1 14:17:58 2016
@@ -90,7 +90,7 @@ public class SlingServletContext impleme
      * @see #SlingServletContext(SlingMainServlet)
      * @see #dispose()
      */
-    private final ServiceRegistration registration;
+    private final ServiceRegistration<ServletContext> registration;
 
     /**
      * Creates an instance of this class delegating some methods to the given
@@ -107,12 +107,11 @@ public class SlingServletContext impleme
         this.slingMainServlet = slingMainServlet;
 
         Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put(Constants.SERVICE_PID, getClass().getName());
         props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling 
ServletContext");
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         props.put("name", "org.apache.sling"); // property to identify this 
context
         registration = bundleContext.registerService(
-            ServletContext.class.getName(), this, props);
+            ServletContext.class, this, props);
     }
 
     /**


Reply via email to