Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-66947

Plugin servlet context initialization is out of order during startup

    Details

      Description

      Description
      The core of the issue is clearly described by LPS-46942:

      Servlet Spec requires that the Web Application Deployment process happens in a specific order, which is listener -> filter -> servlet. See chapter 10.12 for more detail.
      Reference: http://download.oracle.com/otn-pub/jcp/servlet-2.5-mrel2-eval-oth-JSpec/servlet-2_5-mrel2-spec.pdf

      Since the marketplace plugin, we have a thing called "Required Plugins". Normal plugins won't deploy, until after all required plugins are ready. In order to defer normal plugins from being used, we intercept and buffer the ServletContextListener initialization. But we don't do this for filters and servlets.

      As a result, if a plugin is being deployed, while there are missing required plugins, its ServletContextListener initialization call will be deferred. But its filters and servlets initialization will proceed, therefore breaks servlet spec, which requires ServletContextListener initialization to happen before the other two.

      Main Issue
      The issue described above can still occur during startup.

      Steps to Reproduce

      1. Modify Tomcat's server.xml, found in $CATALINA_HOME/conf/server.xml
        • Include the attribute copyXML="true" for the host container
          <Host name="localhost"  appBase="webapps"
              unpackWARs="true" autoDeploy="true"
              copyXML="true">
          
      2. Startup a Liferay 6.2 Instance
      3. Deploy the attached portlet: context-listener-test-portlet-6.2.10.1.war
        • Wait for portlet to be deployed and installed
      4. Restart Liferay
      5. Check logs for portlet log messages

      Actual Result
      Servlet is initialized before the contextlisteners

      21:21:33,126 INFO  [localhost-startStop-1][HotDeployEvent:145] Plugin context-listener-test-portlet requires marketplace-portlet
      21:21:33,127 INFO  [localhost-startStop-1][HotDeployImpl:278] Queueing context-listener-test-portlet for deploy because it is missing marketplace-portlet
      
      
      =============================================
      TestBasicServlet: Initialized
      =============================================
      
      
      21:21:33,176 INFO  [localhost-startStop-1][HotDeployImpl:217] Deploying marketplace-portlet from queue
      21:21:33,178 INFO  [localhost-startStop-1][PluginPackageUtil:1016] Reading plugin package for marketplace-portlet
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portlet.properties
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/service.properties
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portlet.properties
      Jun 30, 2016 9:21:33 PM org.apache.catalina.core.ApplicationContext log
      INFO: Initializing Spring root WebApplicationContext
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/service.properties
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/service.properties
      21:21:34,126 INFO  [localhost-startStop-1][HookHotDeployListener:709] Registering hook for marketplace-portlet
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portal.properties
      21:21:34,285 INFO  [localhost-startStop-1][HookHotDeployListener:851] Hook for marketplace-portlet is available for use
      21:21:34,290 INFO  [localhost-startStop-1][PortletHotDeployListener:344] Registering portlets for marketplace-portlet
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portlet.properties
      21:21:34,469 INFO  [localhost-startStop-1][PortletHotDeployListener:497] 3 portlets for marketplace-portlet are available for use
      21:21:34,471 INFO  [localhost-startStop-1][HotDeployImpl:217] Deploying context-listener-test-portlet from queue
      21:21:34,472 INFO  [localhost-startStop-1][PluginPackageUtil:1016] Reading plugin package for context-listener-test-portlet
      Jun 30, 2016 9:21:34 PM org.apache.catalina.core.ApplicationContext log
      INFO: Initializing Spring root WebApplicationContext
      
      
      =============================================
      TestContextListener: Initialized
      =============================================
      
      
      21:21:34,630 INFO  [localhost-startStop-1][PortletHotDeployListener:344] Registering portlets for context-listener-test-portlet
      21:21:34,669 INFO  [localhost-startStop-1][PortletHotDeployListener:492] 1 portlet for context-listener-test-portlet is available for use
      

      Expected Result
      Contextlisteners are initialized before the servlet

      21:23:37,370 INFO  [localhost-startStop-1][HotDeployEvent:145] Plugin context-listener-test-portlet requires marketplace-portlet
      21:23:37,380 INFO  [localhost-startStop-1][HotDeployImpl:278] Queueing context-listener-test-portlet for deploy because it is missing marketplace-portlet
      21:23:37,380 INFO  [localhost-startStop-1][HotDeployImpl:217] Deploying marketplace-portlet from queue
      21:23:37,380 INFO  [localhost-startStop-1][PluginPackageUtil:1016] Reading plugin package for marketplace-portlet
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portlet.properties
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/service.properties
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portlet.properties
      Jun 30, 2016 9:23:37 PM org.apache.catalina.core.ApplicationContext log
      INFO: Initializing Spring root WebApplicationContext
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/service.properties
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/service.properties
      21:23:38,269 INFO  [localhost-startStop-1][HookHotDeployListener:709] Registering hook for marketplace-portlet
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portal.properties
      21:23:38,382 INFO  [localhost-startStop-1][HookHotDeployListener:851] Hook for marketplace-portlet is available for use
      21:23:38,387 INFO  [localhost-startStop-1][PortletHotDeployListener:344] Registering portlets for marketplace-portlet
      Loading file:/D:/Deploy/ee-62x/tomcat-7.0.42/temp/1-marketplace-portlet/WEB-INF/classes/portlet.properties
      21:23:38,595 INFO  [localhost-startStop-1][PortletHotDeployListener:497] 3 portlets for marketplace-portlet are available for use
      21:23:38,597 INFO  [localhost-startStop-1][HotDeployImpl:217] Deploying context-listener-test-portlet from queue
      21:23:38,599 INFO  [localhost-startStop-1][PluginPackageUtil:1016] Reading plugin package for context-listener-test-portlet
      Jun 30, 2016 9:23:38 PM org.apache.catalina.core.ApplicationContext log
      INFO: Initializing Spring root WebApplicationContext
      
      
      =============================================
      TestContextListener: Initialized
      =============================================
      
      
      21:23:38,784 INFO  [localhost-startStop-1][PortletHotDeployListener:344] Registering portlets for context-listener-test-portlet
      21:23:38,830 INFO  [localhost-startStop-1][PortletHotDeployListener:492] 1 portlet for context-listener-test-portlet is available for use
      
      
      =============================================
      TestBasicServlet: Initialized
      =============================================
      

      Reproduced on ee-6.2.x: 2a22ba3ddd031180aa0ae77a73e89e286ba25017
      Not Reproduced on master: 3c17ebbbd17dba7a93b8114f2e408aee79659e50


      Not Reproduced on Master - Analysis
      Based on our testing in master, it looks like deployed portlets are now handled by osgi.

      The deployed portlets no longer appear as web applications on tomcat (are not deployed in the webapps directory) and appear to be deployed via osgi.

      For additional testing, we also followed the above steps to reproduce in master.
      The attached portlet can also be deployed on master.

      The log messages for the deployed portlet show that the contextlistener is initialized before the servlet.


      Additional Information regarding the attached portlet
      The main goal of the portlet is to create a simple test by creating a contextlistener and servlet that implements the portalLifecycle.
      To accomplish this, we are basically using the SecureServlet as the servlet that implements the portalLifecycle.

      Minor Customization in order to test on Master
      Currently, there is a bug in master that is preventing portlets from working properly when using a servlet that implements the portalLifecycle, due to a NPE.

      The portlet includes a simple modification of the SecureServlet to workaround this bug.

      public class TestSecureServlet extends SecureServlet {
      	@Override
      	public String getServletInfo() {
      		/** Prevent NPE - Workaround **/
      		if(servlet == null) {
      			return StringPool.BLANK;
      		}
      
      		return servlet.getServletInfo();
      	}
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Days since last comment:
                  3 years, 14 weeks, 1 day ago

                  Packages

                  Version Package