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/commons/src/java/org/apache/jetspeed/container JetspeedPortletContext.java JetspeedContainerServlet.java ContainerConstants.java JetspeedPortletConfig.java InternalPortletConfig.java PortalAccessor.java PortletConfigFactory.java
Date Wed, 02 Mar 2005 02:33:18 GMT
ate         2005/03/01 18:33:18

  Modified:    commons/src/java/org/apache/jetspeed/container Tag:
                        deployment-refactoring JetspeedPortletContext.java
                        JetspeedContainerServlet.java
                        ContainerConstants.java JetspeedPortletConfig.java
                        InternalPortletConfig.java PortalAccessor.java
                        PortletConfigFactory.java
  Log:
  Commons portlet container changes
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.1   +5 -1      jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletContext.java
  
  Index: JetspeedPortletContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletContext.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- JetspeedPortletContext.java	6 Jul 2004 23:30:48 -0000	1.7
  +++ JetspeedPortletContext.java	2 Mar 2005 02:33:18 -0000	1.7.2.1
  @@ -232,6 +232,9 @@
           {
               return "/";
           }
  +        return path;
  +        // TODO: local PA with own/extra resource paths support
  +/*        
           if (app.getApplicationType() == MutablePortletApplication.WEBAPP)
           {
               return path;
  @@ -246,5 +249,6 @@
           pathBuffer.append(path);
           String result = pathBuffer.toString();
           return result;
  +*/        
       }
   }
  
  
  
  1.21.2.1  +91 -119   jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
  
  Index: JetspeedContainerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java,v
  retrieving revision 1.21
  retrieving revision 1.21.2.1
  diff -u -r1.21 -r1.21.2.1
  --- JetspeedContainerServlet.java	2 Feb 2005 03:20:14 -0000	1.21
  +++ JetspeedContainerServlet.java	2 Mar 2005 02:33:18 -0000	1.21.2.1
  @@ -35,13 +35,10 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  -import org.apache.jetspeed.factory.JetspeedPortletFactoryProxy;
   import org.apache.jetspeed.services.JetspeedPortletServices;
   import org.apache.jetspeed.services.PortletServices;
  -import org.apache.jetspeed.tools.pamanager.DeploymentRegistration;
  +import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
   import org.apache.jetspeed.util.DirectoryHelper;
  -import org.apache.jetspeed.util.FileSystemHelper;
  -import org.apache.pluto.om.portlet.PortletDefinition;
   
   /**
    * Jetspeed Container entry point.
  @@ -51,98 +48,93 @@
    */
   public class JetspeedContainerServlet extends HttpServlet 
   {
  - //   private final static Log log = LogFactory.getLog(JetspeedContainerServlet.class);
  -   // private final static Log console = LogFactory.getLog(CONSOLE_LOGGER);
  -
  -    /**
  -     * Whether init succeeded or not.
  -     */
  -    private static Throwable initFailure = null;
  -
  -
  -    private static String webappRoot;
  +    private String  contextName;
  +    private boolean started = false;
  +    private Timer   startTimer = null;
   
       // -------------------------------------------------------------------
       // I N I T I A L I Z A T I O N
       // -------------------------------------------------------------------
       private static final String JCS = "JetspeedContainerServlet: ";
  -    private static final String INIT_START_MSG = JCS + "starting initialization of context
";
  -    private static final String INIT_DONE_MSG = JCS + "Initialization complete for context
";
  +    private static final String INIT_START_MSG = JCS + "starting initialization of Portlet
Application at: ";
  +    private static final String TRY_START_MSG = JCS + "attemping to start Portlet Application
at: ";
  +    private static final String STARTED_MSG = JCS + "started Portlet Application at: ";
  +    private static final String INIT_FAILED_MSG = JCS + "initialization failed for Portlet
Application at: ";
  +    private static final String INIT_DONE_MSG = JCS + "initialization done for Portlet
Application at: ";
  +    private static final String STOP_MSG = JCS + "shutting down portlet application at:
";
  +    private static final String STOP_FAILED_MSG = JCS + "shutting down error for portlet
application at: ";
       
  -    /**
  -     * Intialize Servlet.
  -     */
       public synchronized final void init(ServletConfig config) throws ServletException
       {
           synchronized (this.getClass())
           {            
               super.init(config);
  +            
               ServletContext context = getServletContext();
  -            String name = context.getServletContextName();
  -            if (name == null || name.length() == 0)
  -            {
  -                name = context.getRealPath("/");
  -                if (name == null)
  +
  +            started = false;
  +            startTimer = null;            
  +            contextName = config.getInitParameter("contextName");
  +
  +            if (null == contextName || contextName.length() == 0)
  +            {
  +                contextName = null; // just to make sure for the destroy method
  +                
  +                throw new ServletException(JCS + "Portlet Application contextName not supplied
in Init Parameters.");
  +            }            
  +            String paDir = context.getRealPath("/");
  +            if ( paDir == null )
                   {
  -                    name = "Jetspeed";
  +              throw new ServletException(JCS + " Initialization of PortletApplication at
"+contextName+" without access to its real path not supported");
                   }
  -            }
  -            context.log(INIT_START_MSG + name);            
  -            System.out.println(INIT_START_MSG + name);            
  +
  +            context.log(INIT_START_MSG + contextName);            
  +            System.out.println(INIT_START_MSG + contextName);            
   
               try
               {                
  -                String registerAtInit = config.getInitParameter("registerAtInit");
  -                if (null != registerAtInit)
  -                {
  -                    context.log(JCS + "Considering PA for registration during servlet init:
" + name);
  -                    String portletApplication = config.getInitParameter("portletApplication");
  -                    if (null == portletApplication)
  -                    {
  -                        throw new ServletException(JCS + "Portlet Application Name not
supplied in Init Parameters.");
  -                    }
  -                    
  -                    registerPortletApplication(context, portletApplication);
  -                    
  -                }                
  +              startPortletApplication(context, paDir, Thread.currentThread().getContextClassLoader());
               }
               catch (Exception e)
               {
  -                initFailure = e;
  -                String message = JCS + "Initialization of servlet " + name + " failed.";
  +                String message = INIT_FAILED_MSG + contextName;
                   context.log(message, e);
                   System.err.println(message);
  -                e.printStackTrace(System.err);                
                   throw new ServletException(message, e);
               }
   
  -            context.log(INIT_DONE_MSG + name);
  -            System.out.println(INIT_DONE_MSG + name);
  +            context.log(INIT_DONE_MSG + contextName);
  +            System.out.println(INIT_DONE_MSG + contextName);
           }
       }
   
  -    private void registerPortletApplication(final ServletContext context, final String
portletApplicationName)
  +    private void startPortletApplication(final ServletContext context, final String paDir,
final ClassLoader paClassLoader)
       throws ServletException
       {
   
  -        context.log(JCS + "Attempting to register portlet application: name=" + portletApplicationName);
  -        if (attemptRegistration(context, portletApplicationName)) 
  +        if (attemptStart(context, contextName, paDir, paClassLoader)) 
           {
  -            context.log(JCS + "Registered portlet application: name=" + portletApplicationName);
  +          started = true;
               return;
           }
   
  -        context.log(JCS + "Could not registered portlet application; starting back ground
thread to register when jetspeed comes online: name=" + portletApplicationName);
  -        final Timer timer = new Timer(true);
  -        timer.schedule(
  +        final String START_DELAYED_MSG = JCS + "Could not yet start portlet application
at: "+contextName+". Starting back ground thread to start when the portal comes online.";
  +        context.log(START_DELAYED_MSG);
  +        startTimer = new Timer(true);
  +        startTimer.schedule(
                   new TimerTask() {
                       public void run() {
  -                        context.log(JCS + "Attempting to register portlet application:
name=" + portletApplicationName);
  -                        if (attemptRegistration(context, portletApplicationName)) {
  -                            context.log(JCS + "Registered portlet application: name=" +
portletApplicationName);
  -                            timer.cancel();
  +                      synchronized(contextName)
  +                      {
  +                        if (startTimer != null)
  +                        {
  +                          if (attemptStart(context, contextName, paDir, paClassLoader))
{
  +                            startTimer.cancel();
  +                            startTimer = null;
                           } else {
  -                            context.log(JCS + "Could not register portlet application;
will try again later: name=" + portletApplicationName);
  +                            context.log(START_DELAYED_MSG);
  +                          }
  +                        }
                           }
                       }
                   },
  @@ -150,34 +142,31 @@
                   10000);
       }
   
  -    private static boolean attemptRegistration(ServletContext context, String portletApplicationName)

  +    private boolean attemptStart(ServletContext context, String contextPath, String paDir,
ClassLoader paClassLoader) 
       {
           try
           {
  +            context.log(TRY_START_MSG + contextPath);
               PortletServices services = JetspeedPortletServices.getSingleton();
               if (services != null)
               {
  -                DeploymentRegistration registrar =
  -                    (DeploymentRegistration)services.getService("PAM");
  +                PortletApplicationManagement pam =
  +                    (PortletApplicationManagement)services.getService("PAM");
   
  -                if (registrar != null)
  +                if (pam != null)
                   {
  -                    FileSystemHelper webapp = new DirectoryHelper(new File(context.getRealPath("/")));
  -                    if (registrar.registerPortletApplication(webapp, portletApplicationName))
  -                    {
  -                        context.log(JCS + "Portlet Application Registered at Servlet Init:
" + portletApplicationName);
  -                    }
  -                    else
  -                    {
  -                        context.log(JCS + "Portlet Application did not change. Not Registered
at Servlet Init: " + portletApplicationName);
  -                    }
  +                    DirectoryHelper paDirHelper = new DirectoryHelper(new File(paDir));
  +                    pam.startPortletApplication(contextPath, paDirHelper, paClassLoader);
  +                    started = true;
  +                    context.log(STARTED_MSG + contextPath);
                       return true;
                   }
               }
           }
           catch (Exception e)
           {
  -            context.log(JCS + "Failed to register PA: " + portletApplicationName, e);
  +            context.log(INIT_FAILED_MSG + contextPath, e);
  +            return true; // don't try again
           }
           return false;
       }    
  @@ -200,23 +189,14 @@
           Integer method = ContainerConstants.METHOD_NOOP;
           try
           {
  -            // Check to make sure that we started up properly.
  -            if (initFailure != null)
  -            {
  -                throw initFailure;
  -            }
  -
  -            // infuseClasspath();
  -            
               method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID);
               if (method == ContainerConstants.METHOD_NOOP)
               {
                   return;
               }
               
  -            PortletDefinition portletDefinition = JetspeedPortletFactoryProxy.getCurrentPortletDefinition();
                       
  -            portletName = portletDefinition.getName();
  -            Portlet portlet = JetspeedPortletFactoryProxy.getPortlet(this.getServletConfig(),
portletDefinition);
  +            Portlet portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
  +            request.removeAttribute(ContainerConstants.PORTLET);
   
               if (method == ContainerConstants.METHOD_ACTION)
               {
  @@ -302,50 +282,42 @@
       // S E R V L E T  S H U T D O W N
       // -------------------------------------------------------------------
   
  -    /**
  -     * The <code>Servlet</code> destroy method. Invokes <code>ServiceBroker</code>
  -     * tear down method.
  -     */
       public final void destroy()
       {
  -        getServletContext().log(JCS + "Shutting down portlet app context: " + getServletContext().getServletContextName());
  +      if ( contextName != null )
  +      {
  +        synchronized (contextName)
  +        {
  +          if ( startTimer != null )
  +          {
  +            startTimer.cancel();
  +            startTimer = null;
       }
  +          else if ( started )
  +          {
  +            started = false;
  +            PortletServices services = JetspeedPortletServices.getSingleton();
  +            if (services != null)
  +            {
  +                PortletApplicationManagement pam =
  +                    (PortletApplicationManagement)services.getService("PAM");
   
  -    public static final String LOCAL_CLASSES = "/WEB-INF/classes/";
  -    public static final String LOCAL_JARS = "/WEB-INF/lib/";
  -
  -    private void infuseClasspath()
  +                if (pam != null)
       {
  +                    getServletContext().log(STOP_MSG + contextName);
           try
           {
  -            ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
  -            ClassLoader defaultLoader = Class.class.getClassLoader();
  -            
  -            System.out.println("thread Loader is " + oldLoader);
  -            System.out.println("defaultLoader is " + defaultLoader);
  -            /*
  -            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 = "file://c:/bluesunrise/apache/catalina/webapps/jetspeed";
  -                //localPath.toString(); 
  -                URL[] urls = { new URL(localAppPath + LOCAL_CLASSES), new URL(localAppPath
+ LOCAL_JARS)};
  -                loader = new URLClassLoader(urls, oldLoader);
  -                // classLoaders.put(portletApplicationName, loader);
  +                      pam.stopPortletApplication(contextName);
  +                    }
  +                    catch (Exception e)
  +            {
  +                      getServletContext().log(STOP_FAILED_MSG + contextName, e);
  +                    }
  +                }
  +            }
  +            contextName = null;
               }
  -            Thread.currentThread().setContextClassLoader(loader);
  -            */
           }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            return;
           }
  -
       }
  -    
  - 
   }
  
  
  
  1.5.2.1   +2 -1      jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java
  
  Index: ContainerConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/ContainerConstants.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- ContainerConstants.java	19 Aug 2004 23:54:06 -0000	1.5
  +++ ContainerConstants.java	2 Mar 2005 02:33:18 -0000	1.5.2.1
  @@ -29,6 +29,7 @@
       public final static String PORTLET_CONFIG = "javax.portlet.config";
       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 Integer METHOD_RENDER = new Integer(1);
       public final static Integer METHOD_ACTION = new Integer(3);
       public final static Integer METHOD_NOOP = new Integer(5);
  
  
  
  1.6.2.1   +2 -11     jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletConfig.java
  
  Index: JetspeedPortletConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedPortletConfig.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- JetspeedPortletConfig.java	6 Oct 2004 01:51:20 -0000	1.6
  +++ JetspeedPortletConfig.java	2 Mar 2005 02:33:18 -0000	1.6.2.1
  @@ -20,7 +20,6 @@
   import java.util.Locale;
   import java.util.ResourceBundle;
   
  -import javax.servlet.ServletConfig;
   import javax.portlet.PortletConfig;
   import javax.portlet.PortletContext;
   
  @@ -41,13 +40,11 @@
   {
       // private static final Log log = LogFactory.getLog(JetspeedPortletConfig.class);
       
  -    private ServletConfig servletConfig;
       private PortletContext portletContext;
       private PortletDefinition portletDefinition;
   
  -    public JetspeedPortletConfig(ServletConfig servletConfig, PortletContext portletContext,
PortletDefinition portletEntity)
  +    public JetspeedPortletConfig(PortletContext portletContext, PortletDefinition portletEntity)
       {
  -        this.servletConfig = servletConfig;
           this.portletContext = portletContext;
           this.portletDefinition = portletEntity;
       }
  @@ -116,12 +113,6 @@
       }
   
       //  internal portlet config implementation
  -
  -    public javax.servlet.ServletConfig getServletConfig()
  -    {
  -        return servletConfig;
  -    }
  -
       public PortletDefinition getPortletDefinition()
       {
           return portletDefinition;
  
  
  
  1.2.4.1   +1 -5      jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/InternalPortletConfig.java
  
  Index: InternalPortletConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/InternalPortletConfig.java,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- InternalPortletConfig.java	8 Mar 2004 00:41:26 -0000	1.2
  +++ InternalPortletConfig.java	2 Mar 2005 02:33:18 -0000	1.2.4.1
  @@ -17,8 +17,6 @@
   
   import org.apache.pluto.om.portlet.PortletDefinition;
   
  -import javax.servlet.ServletConfig;
  -
   /**
    * This interface defines the internal methods used on the Portlet Config.
    * 
  @@ -28,8 +26,6 @@
    */
   public interface InternalPortletConfig
   {
  -     public ServletConfig getServletConfig();
  -
        public PortletDefinition getPortletDefinition();
       
   }
  
  
  
  1.2.4.1   +3 -5      jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortalAccessor.java
  
  Index: PortalAccessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortalAccessor.java,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- PortalAccessor.java	8 Mar 2004 00:41:26 -0000	1.2
  +++ PortalAccessor.java	2 Mar 2005 02:33:18 -0000	1.2.4.1
  @@ -16,7 +16,6 @@
   package org.apache.jetspeed.container;
   
   import javax.servlet.ServletContext;
  -import javax.servlet.ServletConfig;
   import javax.portlet.PortletContext;
   import javax.portlet.PortletConfig;
   
  @@ -33,11 +32,10 @@
   public class PortalAccessor
   {
   
  -    public static PortletConfig createPortletConfig(ServletConfig servletConfig,
  -                                                 PortletContext portletContext,
  +    public static PortletConfig createPortletConfig(PortletContext portletContext,
                                                    PortletDefinition portletDefinition)
       {
  -        return PortletConfigFactory.createPortletConfig(servletConfig, portletContext,
portletDefinition);         
  +        return PortletConfigFactory.createPortletConfig(portletContext, portletDefinition);
        
       }
   
       public static PortletContext createPortletContext(ServletContext servletContext,
  
  
  
  1.2.4.1   +3 -7      jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortletConfigFactory.java
  
  Index: PortletConfigFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/PortletConfigFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.2.4.1
  diff -u -r1.2 -r1.2.4.1
  --- PortletConfigFactory.java	8 Mar 2004 00:41:26 -0000	1.2
  +++ PortletConfigFactory.java	2 Mar 2005 02:33:18 -0000	1.2.4.1
  @@ -15,7 +15,6 @@
    */
   package org.apache.jetspeed.container;
   
  -import javax.servlet.ServletConfig;
   import javax.portlet.PortletConfig;
   import javax.portlet.PortletContext;
   
  @@ -29,12 +28,9 @@
    */
   public class PortletConfigFactory
   {
  -    public static PortletConfig createPortletConfig(
  -        ServletConfig servletConfig,
  -        PortletContext portletContext,
  -        PortletDefinition portletDefinition)
  +    public static PortletConfig createPortletConfig(PortletContext portletContext,PortletDefinition
portletDefinition)
       {
  -        return new JetspeedPortletConfig(servletConfig, portletContext, portletDefinition);
  +        return new JetspeedPortletConfig(portletContext, portletDefinition);
       }
   
   }
  
  
  

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