FELIX-3956 - JAAS Support bundle should have optional dependency on Servlet API

Using ServiceFactory to register the WebConsolePlugin to avoid direct dependency on Servlet API. Also using DynamicImport-Package (without using wildcards) for the servlet api.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1456909 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/jaas/pom.xml b/jaas/pom.xml
index e6c5fe0..3496aa7 100644
--- a/jaas/pom.xml
+++ b/jaas/pom.xml
@@ -94,10 +94,10 @@
                         <Bundle-Activator>
                             org.apache.felix.jaas.internal.Activator
                         </Bundle-Activator>
-                        <Import-Package>
-                          javax.servlet.*;resolution:=optional,
-                          *
-                        </Import-Package>
+                        <DynamicImport-Package>
+                          javax.servlet,
+                          javax.servlet.http
+                        </DynamicImport-Package>
                         <_removeheaders>
                             Embed-Dependency,Private-Package,Include-Resource
                         </_removeheaders>
diff --git a/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java b/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java
index cca5ff2..c881000 100644
--- a/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java
+++ b/jaas/src/main/java/org/apache/felix/jaas/internal/Activator.java
@@ -19,9 +19,14 @@
 
 package org.apache.felix.jaas.internal;
 
+import java.util.Properties;
+
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
 
 public class Activator implements BundleActivator
 {
@@ -66,11 +71,27 @@
     }
 
     private void registerWebConsolePlugin(BundleContext context){
-        try{
-            webConsolePlugin = new JaasWebConsolePlugin(context, configSpi,loginModuleCreator);
-        }catch(NoClassDefFoundError t){
-            //Servlet API is not present. This is an optional requirement
-            logger.log(LogService.LOG_INFO,"HTTP support not found. JAAS WebConsole Plugin would not be registered");
+        Properties props = new Properties();
+        props.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
+        props.put(Constants.SERVICE_DESCRIPTION, "JAAS Web Console Plugin");
+        props.put("felix.webconsole.label", "jaas");
+        props.put("felix.webconsole.title", "JAAS");
+        props.put("felix.webconsole.configprinter.modes", "always");
+
+        //Registering a ServiceFactory to avoid dependency on Servlet API
+        context.registerService("" +
+                ".Servlet", new PluginServiceFactory(), props);
+    }
+
+    private class PluginServiceFactory implements ServiceFactory {
+
+        @Override
+        public Object getService(Bundle bundle, ServiceRegistration registration) {
+            return new JaasWebConsolePlugin(configSpi,loginModuleCreator);
+        }
+
+        @Override
+        public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
         }
     }
 
diff --git a/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java b/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java
index 03321da..31c391e 100644
--- a/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java
+++ b/jaas/src/main/java/org/apache/felix/jaas/internal/JaasWebConsolePlugin.java
@@ -1,3 +1,4 @@
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -25,17 +26,14 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
 
-import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 
@@ -46,18 +44,10 @@
 
     private final BundleLoginModuleCreator loginModuleCreator;
 
-    public JaasWebConsolePlugin(BundleContext context, ConfigSpiOsgi configSpi, BundleLoginModuleCreator loginModuleCreator)
+    public JaasWebConsolePlugin(ConfigSpiOsgi configSpi, BundleLoginModuleCreator loginModuleCreator)
     {
         this.configSpi = configSpi;
         this.loginModuleCreator = loginModuleCreator;
-
-        Properties props = new Properties();
-        props.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
-        props.put(Constants.SERVICE_DESCRIPTION, "JAAS Web Console Plugin");
-        props.put("felix.webconsole.label", "jaas");
-        props.put("felix.webconsole.title", "JAAS");
-        props.put("felix.webconsole.configprinter.modes", "always");
-        context.registerService(Servlet.class.getName(), this, props);
     }
 
     @Override