portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker JetspeedPortletInvoker.java ServletPortletInvoker.java LocalPortletInvoker.java PortletInvokerFactoryImpl.java
Date Wed, 23 Mar 2005 22:48:03 GMT
ate         2005/03/23 14:48:03

  Modified:    portal/src/java/org/apache/jetspeed/container/invoker
                        JetspeedPortletInvoker.java
                        ServletPortletInvoker.java LocalPortletInvoker.java
                        PortletInvokerFactoryImpl.java
  Log:
  Resolving http://issues.apache.org/jira/browse/JS2-210:
  New portlet container access and invokation implementation
  
  Revision  Changes    Path
  1.5       +6 -3      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java
  
  Index: JetspeedPortletInvoker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JetspeedPortletInvoker.java	8 Mar 2004 00:23:31 -0000	1.4
  +++ JetspeedPortletInvoker.java	23 Mar 2005 22:48:03 -0000	1.5
  @@ -17,6 +17,7 @@
   
   import javax.servlet.ServletConfig;
   
  +import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.pluto.invoker.PortletInvoker;
   import org.apache.pluto.om.portlet.PortletDefinition;
   
  @@ -34,23 +35,25 @@
        * Activating an invoker makes it ready to invoke portlets.
        * If an invoker's state is not activated, it can not invoke.
        * 
  +     * @param portletFactory The factory to get access to the portlet being invoked.
        * @param portletDefinition The portlet's definition that is being invoked.
        * @param servletConfig The servlet configuration of the portal. 
        * @param containerServlet
        */
  -    void activate(PortletDefinition portletDefinition, ServletConfig servletConfig);
  +    void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig
servletConfig);
   
       /**
        * Activating an invoker makes it ready to invoke portlets.
        * If an invoker's state is not activated, it can not invoke.
        * This second signature allows for activating with an extra property.
        * 
  +     * @param portletFactory The factory to get access to the portlet being invoked.
        * @param portletDefinition The portlet's definition that is being invoked.
        * @param servletConfig The servlet configuration of the portal. 
        * @param property Implementation specific property
        * @param containerServlet
        */
  -    void activate(PortletDefinition portletDefinition, ServletConfig servletConfig, String
property);
  +    void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig
servletConfig, String property);
       
       /**
        * Passivates an invoker, freeing it back to the invoker pool.
  
  
  
  1.19      +28 -30    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
  
  Index: ServletPortletInvoker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ServletPortletInvoker.java	4 Feb 2005 17:25:20 -0000	1.18
  +++ ServletPortletInvoker.java	23 Mar 2005 22:48:03 -0000	1.19
  @@ -19,8 +19,6 @@
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  -import javax.portlet.PortletConfig;
  -import javax.portlet.PortletContext;
   import javax.portlet.PortletException;
   import javax.portlet.PortletRequest;
   import javax.portlet.PortletResponse;
  @@ -31,16 +29,18 @@
   import javax.servlet.ServletContext;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
  +import javax.servlet.http.HttpServletRequestWrapper;
  +import javax.servlet.http.HttpServletResponseWrapper;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.jetspeed.PortalReservedParameters;
   import org.apache.jetspeed.container.ContainerConstants;
  -import org.apache.jetspeed.container.PortletContextFactory;
  -import org.apache.jetspeed.factory.JetspeedPortletFactoryProxy;
  +import org.apache.jetspeed.factory.PortletFactory;
  +import org.apache.jetspeed.factory.PortletInstance;
   import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  +import org.apache.jetspeed.om.common.portlet.PortletApplication;
   import org.apache.jetspeed.request.RequestContext;
  -import org.apache.pluto.core.impl.PortletConfigImpl;
   import org.apache.pluto.om.portlet.PortletDefinition;
   import org.apache.pluto.om.servlet.WebApplicationDefinition;
   
  @@ -68,6 +68,7 @@
   {
       private final static Log log = LogFactory.getLog(ServletPortletInvoker.class);
   
  +    protected PortletFactory portletFactory;
       protected ServletContext jetspeedContext;
       protected ServletConfig jetspeedConfig;
       protected PortletDefinition portletDefinition;
  @@ -93,10 +94,11 @@
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition,
ServletConfig servletConfig)
       {
  +        this.portletFactory = portletFactory;
           this.jetspeedConfig = servletConfig;
           jetspeedContext = servletConfig.getServletContext();
           this.portletDefinition = portletDefinition;
  @@ -104,16 +106,14 @@
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig, java.lang.String)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig, java.lang.String)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig,
String servletMappingName)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition,
ServletConfig servletConfig, String servletMappingName)
       {
           this.servletMappingName = servletMappingName;
  -        activate(portletDefinition, servletConfig);
  +        activate(portletFactory, portletDefinition, servletConfig);
       }
   
  -
  -
       /**
        *
        * @param request
  @@ -144,7 +144,7 @@
           }
           catch (IOException e)
           {
  -            log.error("PortletInvokerImpl.load() - Error while dispatching portlet.", e);
  +            log.error("ServletPortletInvokerImpl.load() - Error while dispatching portlet.",
e);
               throw new PortletException(e);
           }
       }
  @@ -163,6 +163,8 @@
       protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse,
Integer methodID)
           throws PortletException, IOException
       {
  +        ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader((PortletApplication)portletDefinition.getPortletApplicationDefinition());
  +
           MutablePortletApplication app = (MutablePortletApplication)portletDefinition.getPortletApplicationDefinition();
   
           WebApplicationDefinition webApplicationDefinition = app.getWebApplicationDefinition();
  @@ -173,9 +175,9 @@
           String portletApplicationName = webApplicationDefinition.getContextRoot();
   
           // gather all required data from request and response
  -        ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper)
portletRequest).getRequest();
  +        ServletRequest servletRequest = ((HttpServletRequestWrapper)((HttpServletRequestWrapper)portletRequest).getRequest()).getRequest();
   
  -        ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper)
portletResponse).getResponse();
  +        ServletResponse servletResponse = ((HttpServletResponseWrapper) portletResponse).getResponse();
   
           ServletContext appContext = jetspeedContext.getContext(portletApplicationName);
           if (null == appContext)
  @@ -184,7 +186,7 @@
               log.error(message);
               throw new PortletException(message);
           }
  -
  +        PortletInstance portletInstance = portletFactory.getPortletInstance(appContext,
portletDefinition);
           RequestDispatcher dispatcher = appContext.getRequestDispatcher(servletMappingName);
           if (null == dispatcher)
           {
  @@ -199,19 +201,14 @@
   
           try
           {
  -            PortletContext portletContext = PortletContextFactory.createPortletContext(appContext,
app);            
  -            PortletConfig portletConfig = new PortletConfigImpl(this.jetspeedConfig, portletContext,
portletDefinition);
  -            
  -            servletRequest.setAttribute(ContainerConstants.METHOD_ID, methodID);
  -
  +            servletRequest.setAttribute(ContainerConstants.PORTLET, portletInstance);
  +            servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
               servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
               servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
  -            servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletConfig);
  +            servletRequest.setAttribute(ContainerConstants.METHOD_ID, methodID);
               RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
               servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
   
  -            JetspeedPortletFactoryProxy.setCurrentPortletDefinition(portletDefinition);
                       
  -            
               dispatcher.include(servletRequest, servletResponse);
               
           }
  @@ -224,11 +221,12 @@
           }
           finally
           {
  -            //servletRequest.removeAttribute(ContainerConstants.METHOD_ID);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_ENTITY);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
  +            servletRequest.removeAttribute(ContainerConstants.METHOD_ID);
  +            servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
           }
   
       }
  
  
  
  1.9       +38 -65    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
  
  Index: LocalPortletInvoker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LocalPortletInvoker.java	1 Aug 2004 15:43:45 -0000	1.8
  +++ LocalPortletInvoker.java	23 Mar 2005 22:48:03 -0000	1.9
  @@ -16,10 +16,6 @@
   package org.apache.jetspeed.container.invoker;
   
   import java.io.IOException;
  -import java.net.URL;
  -import java.net.URLClassLoader;
  -import java.util.HashMap;
  -import java.util.Map;
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  @@ -36,10 +32,12 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.PortalReservedParameters;
   import org.apache.jetspeed.container.ContainerConstants;
  -import org.apache.jetspeed.container.JetspeedPortletContext;
  -import org.apache.jetspeed.factory.JetspeedPortletFactoryProxy;
  -import org.apache.pluto.om.portlet.PortletApplicationDefinition;
  +import org.apache.jetspeed.factory.PortletFactory;
  +import org.apache.jetspeed.factory.PortletInstance;
  +import org.apache.jetspeed.om.common.portlet.PortletApplication;
  +import org.apache.jetspeed.request.RequestContext;
   import org.apache.pluto.om.portlet.PortletDefinition;
   
   /**
  @@ -61,23 +59,18 @@
   {
       private final static Log log = LogFactory.getLog(LocalPortletInvoker.class);
   
  +    protected PortletFactory portletFactory;
       protected ServletContext jetspeedContext;
       protected ServletConfig jetspeedConfig;
       protected PortletDefinition portletDefinition;
       protected boolean activated = false;
  -    /**
  -     * One class loader per local portlet application
  -     */
  -    protected static Map classLoaders = new HashMap();
  -
  -    public static final String LOCAL_CLASSES = "/WEB-INF/classes/";    
  -    public static final String LOCAL_JARS = "/WEB-INF/lib/";    
       
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition,
ServletConfig servletConfig)
       {
  +        this.portletFactory = portletFactory;
           this.jetspeedConfig = servletConfig;
           jetspeedContext = servletConfig.getServletContext();
           this.portletDefinition = portletDefinition;
  @@ -135,7 +128,7 @@
           }
           catch (IOException e)
           {
  -            log.error("PortletInvokerImpl.load() - Error while dispatching portlet.", e);
  +            log.error("LocalPortletInvokerImpl.load() - Error while dispatching portlet.",
e);
               throw new PortletException(e);
           }
       }
  @@ -155,63 +148,36 @@
       protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse,
Integer method)
           throws PortletException, IOException
       {
  -        PortletApplicationDefinition app = portletDefinition.getPortletApplicationDefinition();
  -        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();       
    
  +        ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader((PortletApplication)portletDefinition.getPortletApplicationDefinition());
  +        PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext,portletDefinition);
   
  -        String portletApplicationName = app.getWebApplicationDefinition().getContextRoot();
  +        if (method == ContainerConstants.METHOD_NOOP)
  +        {
  +            return;
  +        }
   
           // gather all required data from request and response
           ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper)
portletRequest).getRequest();
   
           ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper)
portletResponse).getResponse();
   
  -        ServletContext appContext = jetspeedContext.getContext(portletApplicationName);
  -        if (null == appContext)
  -        {
  -            String message = "Failed to find Servlet context for Portlet Application: "
+ portletApplicationName;
  -            log.error(message);
  -            throw new PortletException();
  -        }
  -
  -        
  -        Portlet portlet = null;
  -        
  +        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();       
    
           try
           {
  -            ClassLoader loader = (ClassLoader)classLoaders.get(portletApplicationName);
           
  -            if (null == loader)
  -            {
  -                StringBuffer localPath = new StringBuffer("file:");
  -                localPath.append(jetspeedContext.getRealPath(JetspeedPortletContext.LOCAL_PA_ROOT));
  -                localPath.append(portletApplicationName);
  -                String localAppPath = localPath.toString(); 
  -                URL[] urls = {new URL(localAppPath + LOCAL_CLASSES),
  -                              new URL(localAppPath + LOCAL_JARS)};
  -                loader = new URLClassLoader(urls, oldLoader);
  -                classLoaders.put(portletApplicationName, loader);
  -            }
  -            Thread.currentThread().setContextClassLoader(loader);                 
  -            portlet = JetspeedPortletFactoryProxy.getPortlet(jetspeedConfig, portletDefinition);
           
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            return;
  -        }
  -
  -        if (method == ContainerConstants.METHOD_NOOP)
  -        {
  -            return;
  -        }
  +            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());
   
  -        //res.getWriter().print("Rendering: Portlet Class = " + entity.getPortletClass()
+ "<BR/>");
  +            Thread.currentThread().setContextClassLoader(paClassLoader);
   
           if (method == ContainerConstants.METHOD_ACTION)
           {
               ActionRequest actionRequest = (ActionRequest)portletRequest;            
               ActionResponse actionResponse = (ActionResponse)portletResponse;
   
  -            portlet.processAction(actionRequest, actionResponse);
  +                portletInstance.processAction(actionRequest, actionResponse);
           }
           else if (method == ContainerConstants.METHOD_RENDER)
           {
  @@ -219,21 +185,28 @@
               RenderResponse renderResponse = (RenderResponse)portletResponse;
               
               renderResponse.setContentType("text/html");            
  -            renderResponse.getWriter().print(portletDefinition.getName());
  +// TODO: ???    renderResponse.getWriter().print(portletDefinition.getName());
   
  -            portlet.render(renderRequest, renderResponse);
  +                portletInstance.render(renderRequest, renderResponse);
  +        }
           }
  +        finally
  +        {
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
  +            servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
   
           Thread.currentThread().setContextClassLoader(oldLoader);                 
  -
  +        }
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig, java.lang.String)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition,
javax.servlet.ServletConfig, java.lang.String)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig,
String servletMappingName)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition,
ServletConfig servletConfig, String servletMappingName)
       {
  -        activate(portletDefinition, servletConfig);
  +        activate(portletFactory, portletDefinition, servletConfig);
       }
       
   }
  
  
  
  1.12      +6 -4      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java
  
  Index: PortletInvokerFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PortletInvokerFactoryImpl.java	4 Jan 2005 16:11:20 -0000	1.11
  +++ PortletInvokerFactoryImpl.java	23 Mar 2005 22:48:03 -0000	1.12
  @@ -24,6 +24,7 @@
   
   import org.apache.jetspeed.Jetspeed;
   import org.apache.jetspeed.PortalContext;
  +import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
   import org.apache.pluto.factory.PortletInvokerFactory;
   import org.apache.pluto.om.portlet.PortletDefinition;
  @@ -72,7 +73,7 @@
   
       private PortalContext portalContext;
       
  -
  +    private PortletFactory portletFactory;
                  
       /* (non-Javadoc)
        * @see org.apache.pluto.factory.Factory#init(javax.servlet.ServletConfig, java.util.Map)
  @@ -83,6 +84,7 @@
           servletConfig = config;        
           portalContext = Jetspeed.getContext();
           props = properties;                        
  +        portletFactory = (PortletFactory)props.get("PortletFactory");
       }
   
       /* (non-Javadoc)
  @@ -109,14 +111,14 @@
           if (app.getApplicationType() == MutablePortletApplication.LOCAL)
           {
                   invoker =  (JetspeedPortletInvoker) props.get("LocalPortletInvoker"); 
  -                invoker.activate(portletDefinition, servletConfig);
  +                invoker.activate(portletFactory, portletDefinition, servletConfig);
                   return invoker;           
           }
           else
           {
               invoker =  (JetspeedPortletInvoker) props.get("ServletPortletInvoker"); 
               String servletMappingName = portalContext.getConfigurationProperty(INVOKER_SERVLET_MAPPING_NAME,
DEFAULT_MAPPING_NAME);
  -            invoker.activate(portletDefinition, servletConfig, servletMappingName);   
        
  +            invoker.activate(portletFactory, portletDefinition, servletConfig, servletMappingName);
           
               return invoker;
           }
   
  
  
  

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


Mime
View raw message