portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r331657 - in /portals/jetspeed-2/trunk: commons/src/java/org/apache/jetspeed/container/ components/portal/src/java/org/apache/jetspeed/container/invoker/ components/portlet-factory/src/java/org/apache/jetspeed/factory/
Date Tue, 08 Nov 2005 01:09:11 GMT
Author: ate
Date: Mon Nov  7 17:08:54 2005
New Revision: 331657

URL: http://svn.apache.org/viewcvs?rev=331657&view=rev
Log:
Corrections for portlet UnavailableException handling

Modified:
    portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java
    portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
    portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
    portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java

Modified: portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java?rev=331657&r1=331656&r2=331657&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java
(original)
+++ portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java
Mon Nov  7 17:08:54 2005
@@ -30,6 +30,7 @@
     public final static String PORTAL_CONTEXT = "org.apache.jetspeed.context";
     public final static String METHOD_ID = "org.apache.jetspeed.method";
     public final static String PORTLET = "org.apache.jetspeed.portlet";
+    public final static String PORTLET_NAME = "org.apache.jetspeed.portlet.name";
     public final static Integer METHOD_RENDER = new Integer(1);
     public final static Integer METHOD_ACTION = new Integer(3);
     public final static Integer METHOD_NOOP = new Integer(5);

Modified: portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java?rev=331657&r1=331656&r2=331657&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
(original)
+++ portals/jetspeed-2/trunk/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
Mon Nov  7 17:08:54 2005
@@ -28,6 +28,7 @@
 import javax.portlet.Portlet;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
+import javax.portlet.UnavailableException;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -195,6 +196,9 @@
     {
         String portletName = null;
         Integer method = ContainerConstants.METHOD_NOOP;
+        Portlet portlet = null;
+        boolean destroyPortlet = false;
+        
         try
         {
             method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID);
@@ -203,7 +207,8 @@
                 return;
             }
             
-            Portlet portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
+            portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
+            portletName = (String)request.getAttribute(ContainerConstants.PORTLET_NAME);
             request.removeAttribute(ContainerConstants.PORTLET);
 
             if (method == ContainerConstants.METHOD_ACTION)
@@ -230,6 +235,12 @@
         }
         catch (Throwable t)
         {
+            if ( t instanceof UnavailableException )
+            {
+                // destroy the portlet in the finally clause
+                destroyPortlet = true;
+            }
+            
             if (method != ContainerConstants.METHOD_ACTION)
             {
                 ServletContext context = getServletContext();
@@ -281,6 +292,21 @@
                 else
                 {
                     throw new ServletException(t);
+                }
+            }
+        }
+        finally
+        {
+            if ( destroyPortlet )
+            {
+                // portlet throwed UnavailableException: take it out of service
+                try
+                {
+                    portlet.destroy();
+                }
+                catch (Exception e)
+                {
+                    // never mind, it won't be used anymore.                 
                 }
             }
         }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java?rev=331657&r1=331656&r2=331657&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
Mon Nov  7 17:08:54 2005
@@ -24,6 +24,7 @@
 import javax.portlet.PortletResponse;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
+import javax.portlet.UnavailableException;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
@@ -145,10 +146,12 @@
      * @throws IOException
      */
     protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse,
Integer method)
-        throws PortletException, IOException
+            throws PortletException, IOException
     {
-        ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader((PortletApplication)portletDefinition.getPortletApplicationDefinition());
-        PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext,portletDefinition);
+        ClassLoader paClassLoader = portletFactory
+                .getPortletApplicationClassLoader((PortletApplication) portletDefinition
+                        .getPortletApplicationDefinition());
+        PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext,
portletDefinition);
 
         if (method == ContainerConstants.METHOD_NOOP)
         {
@@ -158,36 +161,67 @@
         // gather all required data from request and response
         ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper) portletRequest).getRequest();
 
-        ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper)
portletResponse).getResponse();
+        ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper)
portletResponse)
+                .getResponse();
 
-        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();         
  
+        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
             servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
             servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
-            RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
-            servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
+            RequestContext requestContext = (RequestContext) servletRequest
+                    .getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+            servletRequest
+                    .setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
 
             Thread.currentThread().setContextClassLoader(paClassLoader);
 
-        if (method == ContainerConstants.METHOD_ACTION)
-        {
-            ActionRequest actionRequest = (ActionRequest)portletRequest;            
-            ActionResponse actionResponse = (ActionResponse)portletResponse;
+            if (method == ContainerConstants.METHOD_ACTION)
+            {
+                ActionRequest actionRequest = (ActionRequest) portletRequest;
+                ActionResponse actionResponse = (ActionResponse) portletResponse;
 
                 portletInstance.processAction(actionRequest, actionResponse);
-        }
-        else if (method == ContainerConstants.METHOD_RENDER)
-        {
-            RenderRequest renderRequest = (RenderRequest)portletRequest;            
-            RenderResponse renderResponse = (RenderResponse)portletResponse;
-            
-            renderResponse.setContentType("text/html");            
-// TODO: ???    renderResponse.getWriter().print(portletDefinition.getName());
+            }
+            else if (method == ContainerConstants.METHOD_RENDER)
+            {
+                RenderRequest renderRequest = (RenderRequest) portletRequest;
+                RenderResponse renderResponse = (RenderResponse) portletResponse;
+
+                renderResponse.setContentType("text/html");
+                // TODO: ???
+                // renderResponse.getWriter().print(portletDefinition.getName());
 
                 portletInstance.render(renderRequest, renderResponse);
+            }
         }
+        catch (Throwable t)
+        {
+            if ( t instanceof UnavailableException )
+            {
+                // take it out of service
+                try
+                {
+                    portletInstance.destroy();
+                }
+                catch (Throwable ignore)
+                {
+                    // never mind, it won't be used anymore
+                }
+            }
+            if ( t instanceof PortletException )
+            {
+                throw (PortletException)t;
+            }
+            if ( t instanceof IOException )
+            {
+                throw (IOException)t;
+            }
+            else
+            {
+                throw new PortletException(t);
+            }
         }
         finally
         {
@@ -196,7 +230,7 @@
             servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
             servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
 
-        Thread.currentThread().setContextClassLoader(oldLoader);                 
+            Thread.currentThread().setContextClassLoader(oldLoader);
         }
     }
 

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java?rev=331657&r1=331656&r2=331657&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
Mon Nov  7 17:08:54 2005
@@ -206,6 +206,7 @@
             servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
             servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
             servletRequest.setAttribute(ContainerConstants.METHOD_ID, methodID);
+            servletRequest.setAttribute(ContainerConstants.PORTLET_NAME, app.getName()+"::"+portletDefinition.getName());
             RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
             servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
 
@@ -226,6 +227,7 @@
             servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
             servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
             servletRequest.removeAttribute(ContainerConstants.METHOD_ID);
+            servletRequest.removeAttribute(ContainerConstants.PORTLET_NAME);
             servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
         }
 

Modified: portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java?rev=331657&r1=331656&r2=331657&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
(original)
+++ portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
Mon Nov  7 17:08:54 2005
@@ -66,36 +66,36 @@
         classLoaderMap.put(pa.getId().toString(), cl);
         }
     }
-
+    
     public void unregisterPortletApplication(PortletApplication pa)
     {
-      synchronized (classLoaderMap)
-        {
-        synchronized (portletCache)
-        {
-          ClassLoader cl = (ClassLoader)classLoaderMap.remove(pa.getId().toString());
-          if ( cl != null )
+        synchronized (classLoaderMap)
         {
-            ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
-
-            Iterator portletDefinitions = pa.getPortletDefinitions().iterator();
-            while (portletDefinitions.hasNext())
-            {                
-              PortletDefinition pd = (PortletDefinition)portletDefinitions.next();
-              Portlet portlet = (Portlet)portletCache.remove(pd.getId().toString());
-              if ( portlet != null )
+            synchronized (portletCache)
+            {
+                ClassLoader cl = (ClassLoader) classLoaderMap.remove(pa.getId().toString());
+                if (cl != null)
                 {
-                    try
-                    {                        
-                  Thread.currentThread().setContextClassLoader(cl);
-                  portlet.destroy();
-                }
-                finally
+                    ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
+
+                    Iterator portletDefinitions = pa.getPortletDefinitions().iterator();
+                    while (portletDefinitions.hasNext())
+                    {
+                        PortletDefinition pd = (PortletDefinition) portletDefinitions.next();
+                        Portlet portlet = (Portlet) portletCache.remove(pd.getId().toString());
+                        if (portlet != null)
                         {
-                  Thread.currentThread().setContextClassLoader(currentContextClassLoader);
+                            try
+                            {
+                                Thread.currentThread().setContextClassLoader(cl);
+                                portlet.destroy();
+                            }
+                            finally
+                            {
+                                Thread.currentThread().setContextClassLoader(currentContextClassLoader);
+                            }
                         }
                     }
-                    }
                 }
             }
         }
@@ -141,7 +141,7 @@
                 // wrap new Portlet inside PortletInstance which ensures the destroy
                 // method will wait for all its invocation threads to complete
                 // and thereby releasing all its ClassLoader locks as needed for local portlets.
-                portlet = new JetspeedPortletInstance((Portlet)clazz.newInstance());
+                portlet = new JetspeedPortletInstance(pd.getName(), (Portlet)clazz.newInstance());
             }
               finally
             {

Modified: portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java?rev=331657&r1=331656&r2=331657&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
(original)
+++ portals/jetspeed-2/trunk/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
Mon Nov  7 17:08:54 2005
@@ -40,17 +40,19 @@
   private Portlet portlet;
   private PortletConfig config;
   private boolean destroyed;
+  private final String portletName;
   
-  public JetspeedPortletInstance(Portlet portlet)
+  public JetspeedPortletInstance(String portletName, Portlet portlet)
   {
-    this.portlet = portlet;
+      this.portletName = portletName;
+      this.portlet = portlet;
   }
   
   private void checkAvailable() throws UnavailableException
   {
       if ( destroyed )
       {
-          throw new UnavailableException("Portlet "+portlet.getClass().getName()+" no longer
available");
+          throw new UnavailableException("Portlet "+portletName+" no longer available");
       }
   }
   
@@ -58,9 +60,13 @@
   {
       if (!destroyed)
       {
-        destroyed = true;
+          destroyed = true;
+          if ( config != null )
+          {
+              // Portlet really has been put into service, now destroy it.
+              portlet.destroy();
+          }
       }
-      portlet.destroy();
   }
   
   public boolean equals(Object obj)



---------------------------------------------------------------------
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