incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1057098 - in /sling/trunk/launchpad/base: ./ src/main/java/org/apache/sling/launchpad/base/shared/ src/main/java/org/apache/sling/launchpad/base/webapp/ src/main/java/org/apache/sling/launchpad/webapp/ src/main/webapp/WEB-INF/
Date Mon, 10 Jan 2011 07:37:13 GMT
Author: fmeschbe
Date: Mon Jan 10 07:37:12 2011
New Revision: 1057098

URL: http://svn.apache.org/viewvc?rev=1057098&view=rev
Log:
SLING-1924 Upgrade to Apache Felix HTTP Bundles 2.0.5-SNAPSHOT and add support for Http Session
event forwarding to the ProxyListener.

Added:
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java
  (with props)
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java
  (with props)
Modified:
    sling/trunk/launchpad/base/pom.xml
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
    sling/trunk/launchpad/base/src/main/webapp/WEB-INF/web.xml

Modified: sling/trunk/launchpad/base/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/pom.xml?rev=1057098&r1=1057097&r2=1057098&view=diff
==============================================================================
--- sling/trunk/launchpad/base/pom.xml (original)
+++ sling/trunk/launchpad/base/pom.xml Mon Jan 10 07:37:12 2011
@@ -38,7 +38,7 @@
     </description>
 
     <properties>
-        <felix.httpservice.version>2.0.4</felix.httpservice.version>
+        <felix.httpservice.version>2.0.5-SNAPSHOT</felix.httpservice.version>
     </properties>
 
     <scm>

Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java?rev=1057098&r1=1057097&r2=1057098&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
(original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
Mon Jan 10 07:37:12 2011
@@ -54,6 +54,14 @@ public interface SharedConstants {
     public static final String DEFAULT_SLING_SERVLET = "org.apache.sling.launchpad.base.webapp.SlingServletDelegate";
 
     /**
+     * The fully qualified name of the implementation of the Servlet API
+     * ServletContextListener, HttpSessionListener, and
+     * HttpSessionAttributeListener interfaces to which the respective events
+     * are forwarded.
+     */
+    public static final String DEFAULT_SLING_LISTENER = "org.apache.sling.launchpad.base.webapp.SlingHttpSessionListenerDelegate";
+
+    /**
      * The name of the file providing the Launcher JAR. On the one hand this is
      * the name used to place the JAR file sling.home to use for startup. On the
      * other hand, this is the name of the file in the archive (see

Added: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java?rev=1057098&view=auto
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java
(added)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java
Mon Jan 10 07:37:12 2011
@@ -0,0 +1,70 @@
+/*
+ * 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.sling.launchpad.base.webapp;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.felix.http.proxy.ProxyListener;
+
+public class SlingHttpSessionListenerDelegate implements
+        HttpSessionAttributeListener, HttpSessionListener,
+        ServletContextListener {
+
+    private final ProxyListener proxyListener = new ProxyListener();
+
+    // ---------- ServletContextListener
+
+    public void contextInitialized(final ServletContextEvent sce) {
+        this.proxyListener.contextInitialized(sce);
+    }
+
+    public void contextDestroyed(final ServletContextEvent sce) {
+        this.proxyListener.contextDestroyed(sce);
+    }
+
+    // ---------- HttpSessionListener
+
+    public void sessionCreated(HttpSessionEvent se) {
+        proxyListener.sessionCreated(se);
+    }
+
+    public void sessionDestroyed(HttpSessionEvent se) {
+        proxyListener.sessionDestroyed(se);
+    }
+
+    // ---------- HttpSessionAttributeListener
+
+    public void attributeAdded(HttpSessionBindingEvent se) {
+        proxyListener.attributeAdded(se);
+    }
+
+    public void attributeRemoved(HttpSessionBindingEvent se) {
+        proxyListener.attributeRemoved(se);
+    }
+
+    public void attributeReplaced(HttpSessionBindingEvent se) {
+        proxyListener.attributeReplaced(se);
+    }
+
+}

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/webapp/SlingHttpSessionListenerDelegate.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java?rev=1057098&r1=1057097&r2=1057098&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
(original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
Mon Jan 10 07:37:12 2011
@@ -167,6 +167,8 @@ public class SlingServlet extends Generi
      */
     @Override
     public void destroy() {
+        SlingSessionListener.stopDelegatee();
+
         if (sling != null) {
             sling.destroy();
         }
@@ -200,6 +202,7 @@ public class SlingServlet extends Generi
 
         // clear the reference to the framework
         sling = null;
+        SlingSessionListener.stopDelegatee();
     }
 
     /**
@@ -220,6 +223,7 @@ public class SlingServlet extends Generi
         synchronized (this) {
             if (startingSling == null) {
                 sling = null;
+                SlingSessionListener.stopDelegatee();
             }
         }
 
@@ -347,6 +351,8 @@ public class SlingServlet extends Generi
                 slingLauncher.setSlingHome(slingHome);
             }
 
+            SlingSessionListener.startDelegate(sling.getClass().getClassLoader());
+
             try {
                 log("Starting launcher ...");
                 sling.init(getServletConfig());

Added: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java?rev=1057098&view=auto
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java
(added)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java
Mon Jan 10 07:37:12 2011
@@ -0,0 +1,120 @@
+/*
+ * 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.sling.launchpad.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.sling.launchpad.base.shared.SharedConstants;
+
+public class SlingSessionListener implements HttpSessionAttributeListener,
+        HttpSessionListener, ServletContextListener {
+
+    private static ServletContext servletContext;
+
+    private static ServletContextListener delegateeContextListener;
+
+    private static HttpSessionListener delegateeSessionListener;
+
+    private static HttpSessionAttributeListener delegateeSessionAttributeListener;
+
+    static void startDelegate(final ClassLoader classLoader) {
+        Object delegatee = null;
+        try {
+            Class<?> delegateeClass = classLoader.loadClass(SharedConstants.DEFAULT_SLING_LISTENER);
+            delegatee = delegateeClass.newInstance();
+        } catch (Exception e) {
+            servletContext.log(
+                "Delegatee Event Listener class "
+                    + SharedConstants.DEFAULT_SLING_LISTENER
+                    + " cannot be loaded or instantiated; Http Session Event forwarding is
disabled",
+                e);
+        }
+
+        if (delegatee instanceof ServletContextListener) {
+            delegateeContextListener = (ServletContextListener) delegatee;
+            delegateeContextListener.contextInitialized(new ServletContextEvent(
+                servletContext));
+
+            delegateeSessionListener = (HttpSessionListener) delegatee;
+            delegateeSessionAttributeListener = (HttpSessionAttributeListener) delegatee;
+        }
+    }
+
+    static void stopDelegatee() {
+        if (delegateeContextListener != null) {
+            delegateeContextListener.contextDestroyed(new ServletContextEvent(
+                servletContext));
+        }
+
+        delegateeContextListener = null;
+        delegateeSessionListener = null;
+        delegateeSessionAttributeListener = null;
+    }
+
+    public void contextInitialized(ServletContextEvent sce) {
+        SlingSessionListener.servletContext = sce.getServletContext();
+    }
+
+    public void contextDestroyed(ServletContextEvent sce) {
+        stopDelegatee();
+        SlingSessionListener.servletContext = null;
+    }
+
+    public void sessionCreated(HttpSessionEvent se) {
+        final HttpSessionListener delegateeSessionListener = SlingSessionListener.delegateeSessionListener;
+        if (delegateeSessionListener != null) {
+            delegateeSessionListener.sessionCreated(se);
+        }
+    }
+
+    public void sessionDestroyed(HttpSessionEvent se) {
+        final HttpSessionListener delegateeSessionListener = SlingSessionListener.delegateeSessionListener;
+        if (delegateeSessionListener != null) {
+            delegateeSessionListener.sessionDestroyed(se);
+        }
+    }
+
+    public void attributeAdded(HttpSessionBindingEvent se) {
+        final HttpSessionAttributeListener delegateeSessionAttributeListener = SlingSessionListener.delegateeSessionAttributeListener;
+        if (delegateeSessionAttributeListener != null) {
+            delegateeSessionAttributeListener.attributeAdded(se);
+        }
+    }
+
+    public void attributeRemoved(HttpSessionBindingEvent se) {
+        final HttpSessionAttributeListener delegateeSessionAttributeListener = SlingSessionListener.delegateeSessionAttributeListener;
+        if (delegateeSessionAttributeListener != null) {
+            delegateeSessionAttributeListener.attributeRemoved(se);
+        }
+    }
+
+    public void attributeReplaced(HttpSessionBindingEvent se) {
+        final HttpSessionAttributeListener delegateeSessionAttributeListener = SlingSessionListener.delegateeSessionAttributeListener;
+        if (delegateeSessionAttributeListener != null) {
+            delegateeSessionAttributeListener.attributeReplaced(se);
+        }
+    }
+
+}

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingSessionListener.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Modified: sling/trunk/launchpad/base/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/webapp/WEB-INF/web.xml?rev=1057098&r1=1057097&r2=1057098&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/webapp/WEB-INF/web.xml (original)
+++ sling/trunk/launchpad/base/src/main/webapp/WEB-INF/web.xml Mon Jan 10 07:37:12 2011
@@ -23,6 +23,13 @@
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <display-name>Sling Launchpad Web Application</display-name>
 
+    <!-- The Felix Http Service Listener Proxy for HTTP Session events -->
+    <listener>
+        <listener-class>
+            org.apache.sling.launchpad.webapp.SlingSessionListener
+        </listener-class>
+    </listener>
+
     <servlet>
         <display-name>Sling Servlet</display-name>
         <servlet-name>sling</servlet-name>



Mime
View raw message