[portal-commits] JBoss Portal SVN: r12943 - branches/JBoss_Portal_Branch_2_7/server/src/main/org/jboss/portal/server/listener.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Wed Mar 4 11:38:25 EST 2009


Author: chris.laprun at jboss.com
Date: 2009-03-04 11:38:25 -0500 (Wed, 04 Mar 2009)
New Revision: 12943

Modified:
   branches/JBoss_Portal_Branch_2_7/server/src/main/org/jboss/portal/server/listener/SessionListener.java
Log:
- Fix potential NPE when session is destroyed.

Modified: branches/JBoss_Portal_Branch_2_7/server/src/main/org/jboss/portal/server/listener/SessionListener.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/server/src/main/org/jboss/portal/server/listener/SessionListener.java	2009-03-04 16:37:26 UTC (rev 12942)
+++ branches/JBoss_Portal_Branch_2_7/server/src/main/org/jboss/portal/server/listener/SessionListener.java	2009-03-04 16:38:25 UTC (rev 12943)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2008, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual                    *
  * contributors as indicated by the @authors tag. See the                     *
  * copyright.txt in the distribution for a full listing of                    *
  * individual contributors.                                                   *
@@ -22,18 +22,10 @@
  ******************************************************************************/
 package org.jboss.portal.server.listener;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.portal.server.aspects.server.SignOutInterceptor.Invalidation;
+import org.jboss.portal.web.ServletContainer;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -47,16 +39,22 @@
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
 
-import org.jboss.logging.Logger;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.portal.server.aspects.server.SignOutInterceptor.Invalidation;
-import org.jboss.portal.web.ServletContainer;
-
 /**
- * This listener listens to the main portal session events.
- * When the portal session timesout, all web applications' sessions referenced
- * by org.jboss.portal.server.aspects.server.SignOutInterceptor are destroyed
+ * This listener listens to the main portal session events. When the portal session timesout, all web applications'
+ * sessions referenced by org.jboss.portal.server.aspects.server.SignOutInterceptor are destroyed
+ *
  * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  * @version $Revision$
  */
@@ -67,10 +65,10 @@
 
    /** . */
    private Logger log = Logger.getLogger(SessionListener.class);
-   
+
    /** . */
    private static final String KEY = "org.jboss.portal.session.contexts";
-   
+
    public void sessionCreated(HttpSessionEvent arg0)
    {
       // Nothing to do
@@ -79,50 +77,51 @@
    public void sessionDestroyed(HttpSessionEvent arg0)
    {
       Set<String> contexts = (Set<String>)arg0.getSession().getAttribute(KEY);
-      
-      MBeanServer server = MBeanServerLocator.locateJBoss();
-      ObjectName objectName = null;
-      ServletContainer servletContainer = null;
 
-      try
+      if (contexts != null)
       {
-         objectName = new ObjectName("portal:service=ServletContainerFactory");
-         servletContainer = (ServletContainer)server.getAttribute(objectName, "ServletContainer");
-      }
-      catch (Exception e1)
-      {
-         log.error("Error while destroying portlet webapp sessions");
-      }
-      
-      // Iterate over all the context that have been used
-      for (Iterator<String> i = contexts.iterator(); i.hasNext();)
-      {
-         String dispatchContextName = (String)i.next();
+         MBeanServer server = MBeanServerLocator.locateJBoss();
+         ObjectName objectName = null;
+         ServletContainer servletContainer = null;
 
-         // Get the context
-         ServletContext dispatchContext = arg0.getSession().getServletContext().getContext(dispatchContextName);
-         
-         // The context could be null if the web app has been removed after the web app has been tracked
-         if (dispatchContext != null)
+         try
          {
-            try
+            objectName = new ObjectName("portal:service=ServletContainerFactory");
+            servletContainer = (ServletContainer)server.getAttribute(objectName, "ServletContainer");
+         }
+         catch (Exception e1)
+         {
+            log.error("Error while destroying portlet webapp sessions");
+         }
+
+         // Iterate over all the context that have been used
+         for (String dispatchContextName : contexts)
+         {
+            // Get the context
+            ServletContext dispatchContext = arg0.getSession().getServletContext().getContext(dispatchContextName);
+
+            // The context could be null if the web app has been removed after the web app has been tracked
+            if (dispatchContext != null)
             {
-               // Execute the command that invalidates the session
-               servletContainer.include(dispatchContext, new TestHttpServletRequest(arg0.getSession()), new TestHttpServletResponse(), invalidator, null);
+               try
+               {
+                  // Execute the command that invalidates the session
+                  servletContainer.include(dispatchContext, new TestHttpServletRequest(arg0.getSession()), new TestHttpServletResponse(), invalidator, null);
+               }
+               catch (Exception e)
+               {
+                  log.error("An error occured when trying to invalidate the sessions");
+               }
             }
-            catch (Exception e)
-            {
-               log.error("An error occured when trying to invalidate the sessions");
-            }
          }
       }
    }
-   
+
    // request
    private static class TestHttpServletRequest implements HttpServletRequest
    {
       private Map attributes;
-      
+
       private HttpSession session;
 
       public TestHttpServletRequest(HttpSession session)




More information about the portal-commits mailing list