FELIX-4937 : IllegalArgumentException on shutdown if sessions have been created

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1687538 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
index e72c7f8..bc16e10 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
@@ -36,6 +36,7 @@
  */
 public class EventDispatcher implements HttpSessionAttributeListener, HttpSessionListener, HttpSessionIdListener
 {
+    private volatile boolean active = false;
 
     private final HttpServiceController controller;
 
@@ -44,38 +45,61 @@
         this.controller = controller;
     }
 
+    public void setActive(final boolean flag)
+    {
+        this.active = flag;
+    }
+
     @Override
     public void sessionCreated(final HttpSessionEvent se)
     {
-        controller.getSessionListener().sessionCreated(se);
+        if ( this.active )
+        {
+            controller.getSessionListener().sessionCreated(se);
+        }
     }
 
     @Override
     public void sessionDestroyed(final HttpSessionEvent se)
     {
-        controller.getSessionListener().sessionDestroyed(se);
+        if ( this.active )
+        {
+            controller.getSessionListener().sessionDestroyed(se);
+        }
     }
 
     @Override
     public void attributeAdded(final HttpSessionBindingEvent se)
     {
-        controller.getSessionAttributeListener().attributeAdded(se);
+        if ( this.active )
+        {
+            controller.getSessionAttributeListener().attributeAdded(se);
+        }
     }
 
     @Override
     public void attributeRemoved(final HttpSessionBindingEvent se)
     {
-        controller.getSessionAttributeListener().attributeRemoved(se);
+        if ( this.active )
+        {
+            controller.getSessionAttributeListener().attributeRemoved(se);
+        }
     }
 
     @Override
     public void attributeReplaced(final HttpSessionBindingEvent se)
     {
-        controller.getSessionAttributeListener().attributeReplaced(se);
+        if ( this.active )
+        {
+            controller.getSessionAttributeListener().attributeReplaced(se);
+        }
     }
 
     @Override
     public void sessionIdChanged(final HttpSessionEvent event, final String oldSessionId) {
-        controller.getSessionIdListener().sessionIdChanged(event, oldSessionId);
+        if ( this.active )
+        {
+            controller.getSessionIdListener().sessionIdChanged(event, oldSessionId);
+        }
     }
 }
diff --git a/http/itest/pom.xml b/http/itest/pom.xml
index 4cb1985..47e05f9 100644
--- a/http/itest/pom.xml
+++ b/http/itest/pom.xml
@@ -34,8 +34,26 @@
 	    <felix.java.version>7</felix.java.version>
 		<pax.exam.version>4.4.0</pax.exam.version>
 		<pax.url.aether.version>2.4.1</pax.url.aether.version>
+		<http.api.version>3.0.0-SNAPSHOT</http.api.version>
+		<http.servlet.api.version>1.1.1-SNAPSHOT</http.servlet.api.version>
+		<http.jetty.version>3.0.3-SNAPSHOT</http.jetty.version>
 	</properties>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemPropertyVariables>                    
+                 		<http.api.version>${http.api.version}</http.api.version>
+ 		                <http.servlet.api.version>${http.servlet.api.version}</http.servlet.api.version>
+                		<http.jetty.version>${http.jetty.version}</http.jetty.version>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>  
+        </plugins>
+    </build>
 	<dependencies>
 		<dependency>
 			<groupId>org.osgi</groupId>
@@ -67,19 +85,19 @@
 			<scope>provided</scope>
         </dependency>
 		<dependency>
-			<groupId>${project.groupId}</groupId>
+			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.http.api</artifactId>
-			<version>3.0.0-SNAPSHOT</version>
+			<version>${http.api.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>${project.groupId}</groupId>
+			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.http.servlet-api</artifactId>
-			<version>1.1.1-SNAPSHOT</version>
+			<version>${http.servlet.api.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>${project.groupId}</groupId>
+			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.http.jetty</artifactId>
-			<version>3.0.3-SNAPSHOT</version>
+			<version>${http.jetty.version}</version>
 		</dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
diff --git a/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java b/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
index 8426d66..b24b6b2 100644
--- a/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
+++ b/http/itest/src/test/java/org/apache/felix/http/itest/BaseIntegrationTest.java
@@ -322,16 +322,16 @@
             mavenBundle("org.apache.sling", "org.apache.sling.commons.log", "4.0.0"),
             mavenBundle("org.apache.sling", "org.apache.sling.commons.logservice", "1.0.2"),
 
-            mavenBundle("org.apache.felix", "org.apache.felix.http.api").startLevel(START_LEVEL_SYSTEM_BUNDLES),
-            mavenBundle("org.apache.felix", "org.apache.felix.http.servlet-api").startLevel(START_LEVEL_SYSTEM_BUNDLES),
-            mavenBundle("org.apache.felix", ORG_APACHE_FELIX_HTTP_JETTY).startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.felix", "org.apache.felix.http.api", System.getProperty("http.api.version")).startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.felix", "org.apache.felix.http.servlet-api", System.getProperty("http.servlet.api.version")).startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.felix", ORG_APACHE_FELIX_HTTP_JETTY, System.getProperty("http.jetty.version")).startLevel(START_LEVEL_SYSTEM_BUNDLES),
             mavenBundle("org.apache.felix", "org.apache.felix.configadmin").version("1.8.6"),
 
-            mavenBundle("org.apache.httpcomponents", "httpcore-osgi").startLevel(START_LEVEL_SYSTEM_BUNDLES),
-            mavenBundle("org.apache.httpcomponents", "httpclient-osgi").startLevel(START_LEVEL_SYSTEM_BUNDLES),
-            mavenBundle("org.mockito", "mockito-all").startLevel(START_LEVEL_SYSTEM_BUNDLES),
-            mavenBundle("org.objenesis", "objenesis").startLevel(START_LEVEL_SYSTEM_BUNDLES),
-            mavenBundle("com.googlecode.json-simple", "json-simple").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.httpcomponents", "httpcore-osgi", "4.3.2").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.apache.httpcomponents", "httpclient-osgi", "4.3.4").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.mockito", "mockito-all", "1.10.19").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("org.objenesis", "objenesis", "2.1").startLevel(START_LEVEL_SYSTEM_BUNDLES),
+            mavenBundle("com.googlecode.json-simple", "json-simple", "1.1.1").startLevel(START_LEVEL_SYSTEM_BUNDLES),
 
             junitBundles(),
             frameworkStartLevel(START_LEVEL_TEST_BUNDLE));
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index 7273fcb..6520716 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -105,7 +105,10 @@
     private ServiceTracker connectorTracker;
     private EventAdmin eventAdmin;
 
-    public JettyService(BundleContext context, DispatcherServlet dispatcher, EventDispatcher eventDispatcher, HttpServiceController controller)
+    public JettyService(final BundleContext context,
+            final DispatcherServlet dispatcher,
+            final EventDispatcher eventDispatcher,
+            final HttpServiceController controller)
     {
         this.context = context;
         this.config = new JettyConfig(this.context);
@@ -207,6 +210,7 @@
     {
         if (this.server != null)
         {
+            this.eventDispatcher.setActive(false);
             if (this.connectorTracker != null)
             {
                 this.connectorTracker.close();
@@ -246,6 +250,7 @@
             ServletContextHandler context = new ServletContextHandler(this.parent, this.config.getContextPath(), ServletContextHandler.SESSIONS);
 
             configureSessionManager(context);
+            this.eventDispatcher.setActive(true);
             context.addEventListener(eventDispatcher);
             context.getSessionHandler().addEventListener(eventDispatcher);
             final ServletHolder holder = new ServletHolder(this.dispatcher);