portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r774210 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/test/java/org/apache/jetspeed/tools/pamanager/ components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/impl/ jetspeed-commons/src/main/java/org/ap...
Date Wed, 13 May 2009 05:30:27 GMT
Author: rwatler
Date: Wed May 13 05:30:26 2009
New Revision: 774210

URL: http://svn.apache.org/viewvc?rev=774210&view=rev
Log:
JS2-1005: ProfilerContext session serialization/server kill errors
------------------------------------------------------------------
- corrected serialization of ProfilerContext by making inner class static and using an explicit
transient reference to
  profiler and defining a default serial version id.
- prevent access to J2 configuration after server stopped/killed by ensuring guest principal
name is accessed when any
  ProfilerContext is constructed.
- access to PAM stopPortletApplication() in JetspeedContainerServlet and unit tests protected
by check to ensure PAM
  is not already stopped.


Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManagerServer.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
    portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/container/JetspeedContainerServlet.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManagerServer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManagerServer.java?rev=774210&r1=774209&r2=774210&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManagerServer.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManagerServer.java
Wed May 13 05:30:26 2009
@@ -165,9 +165,12 @@
      */
     public void startPortletApplication() throws RegistryException
     {
-        DirectoryHelper portletApplicationDir = new DirectoryHelper(new File(baseDir+"/src/test/testdata/"+TestPortletApplicationManager.CONTEXT_NAME));
-        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-        portletApplicationManager.startPortletApplication(TestPortletApplicationManager.CONTEXT_NAME,
TestPortletApplicationManager.CONTEXT_PATH, portletApplicationDir, contextClassLoader);
+        if (portletApplicationManager.isStarted())
+        {
+            DirectoryHelper portletApplicationDir = new DirectoryHelper(new File(baseDir+"/src/test/testdata/"+TestPortletApplicationManager.CONTEXT_NAME));
+            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+            portletApplicationManager.startPortletApplication(TestPortletApplicationManager.CONTEXT_NAME,
TestPortletApplicationManager.CONTEXT_PATH, portletApplicationDir, contextClassLoader);
+        }
     }
 
     /**
@@ -177,7 +180,10 @@
      */
     public void stopPortletApplication() throws RegistryException
     {
-        portletApplicationManager.stopPortletApplication(TestPortletApplicationManager.CONTEXT_NAME);
+        if (portletApplicationManager.isStarted())
+        {
+            portletApplicationManager.stopPortletApplication(TestPortletApplicationManager.CONTEXT_NAME);
+        }
     }
     
     /**
@@ -187,7 +193,10 @@
      */
     public void unregisterPortletApplication() throws RegistryException
     {
-        portletApplicationManager.unregisterPortletApplication(TestPortletApplicationManager.CONTEXT_NAME);
+        if (portletApplicationManager.isStarted())
+        {
+            portletApplicationManager.unregisterPortletApplication(TestPortletApplicationManager.CONTEXT_NAME);
+        }
     }
     
     /**

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java?rev=774210&r1=774209&r2=774210&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/impl/JetspeedProfilerImpl.java
Wed May 13 05:30:26 2009
@@ -67,6 +67,9 @@
     /** Profiler context session attribute name */
     public final static String PROFILER_CONTEXT_ATTRIBUTE_NAME = "org.apache.jetspeed.profiler.ProfilerContext";
     
+    /** Default guest principal name */
+    public final static String DEFAULT_GUEST_PRINCIPAL_NAME = "guest";
+    
     /** Default rule principal name */
     public final static String DEFAULT_RULE_PRINCIPAL_NAME = "*";
     
@@ -806,7 +809,7 @@
             if ((profilerContext == null) || (profilerContext.getPrincipal() != principal))
             {
                 // setup/reset profiler context
-                context.setSessionAttribute(PROFILER_CONTEXT_ATTRIBUTE_NAME, new ProfilerContext(principal));
+                context.setSessionAttribute(PROFILER_CONTEXT_ATTRIBUTE_NAME, new ProfilerContext(this,
principal));
             }
         }
         catch (Exception e)
@@ -899,20 +902,29 @@
      * 
      * Class used to track session lifetime within profiler implementation
      * so that cached profiler rule information per principal can be evicted
-     * from cache on session end.
+     * from cache on session end. Note that this serializable class must be
+     * static to prevent owning JetspeedProfilerImpl from being persisted
+     * in the session.
      */
-    public class ProfilerContext implements HttpSessionActivationListener, HttpSessionBindingListener,
Serializable
+    public static class ProfilerContext implements HttpSessionActivationListener, HttpSessionBindingListener,
Serializable
     {
+        private static final long serialVersionUID = 1L;
+        
+        private transient JetspeedProfilerImpl profiler;
         private transient Principal principal;
+        private transient boolean guestPrincipal;
         
         /**
          * Construct new profiler context with specified principal.
          * 
+         * @param profiler profiler implementation
          * @param principal profiler context principal
          */
-        private ProfilerContext(Principal principal)
+        private ProfilerContext(JetspeedProfilerImpl profiler, Principal principal)
         {
+            this.profiler = profiler;
             this.principal = principal;
+            this.guestPrincipal = ((principal != null) && principal.getName().equals(profiler.getGuestPrincipalName()));
         }
         
         /**
@@ -960,20 +972,24 @@
          */
         private void evictPrincipal()
         {
-            // evict cached principal rules on session end
-            if (principal != null)
+            // profiler can be null for reactivated sessions
+            if (profiler != null)
             {
-                evictCachedPrincipalRules(principal.getName(), false);
-            }
-            principal = null;
-            
-            // evict default and guest principal rules periodically
-            long now = System.currentTimeMillis();
-            if (now-lastDefaultGuestReapTime > DEFAULT_AND_GUEST_RULE_REAPING_INTERVAL)
-            {
-                lastDefaultGuestReapTime = now;
-                evictCachedPrincipalRules(getGuestPrincipalName(), true);
-                evictCachedPrincipalRules(DEFAULT_RULE_PRINCIPAL_NAME, true);
+                // evict cached principal rules on session end
+                if ((principal != null) && !guestPrincipal)
+                {
+                    profiler.evictCachedPrincipalRules(principal.getName(), false);
+                }
+                principal = null;
+
+                // evict default and guest principal rules periodically
+                long now = System.currentTimeMillis();
+                if (now-profiler.lastDefaultGuestReapTime > DEFAULT_AND_GUEST_RULE_REAPING_INTERVAL)
+                {
+                    profiler.lastDefaultGuestReapTime = now;
+                    profiler.evictCachedPrincipalRules(profiler.getGuestPrincipalName(),
true);
+                    profiler.evictCachedPrincipalRules(DEFAULT_RULE_PRINCIPAL_NAME, true);
+                }
             }
         }
         
@@ -998,11 +1014,15 @@
         // lazily access configured guest principal name 
         if (guestPrincipalName == null)
         {
-            guestPrincipalName = "guest";
+            guestPrincipalName = DEFAULT_GUEST_PRINCIPAL_NAME;
             PortalConfiguration config = Jetspeed.getConfiguration();
             if (config != null)
             {
-                guestPrincipalName = config.getString("default.user.principal");
+                String configGuestPrincipalName = config.getString("default.user.principal");
+                if (configGuestPrincipalName != null)
+                {
+                    guestPrincipalName = configGuestPrincipalName;
+                }
             }
         }
         return guestPrincipalName;

Modified: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/container/JetspeedContainerServlet.java?rev=774210&r1=774209&r2=774210&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
Wed May 13 05:30:26 2009
@@ -404,7 +404,7 @@
                     if (services != null)
                     {
                         PortletApplicationManagement pam = (PortletApplicationManagement)
services.getService("PAM");
-                        if (pam != null)
+                        if ((pam != null) && pam.isStarted())
                         {
                             getServletContext().log(STOP_MSG + contextName);
                             try



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message