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

Scan bundle dependencies for ServletContainerInitializers to allow zero-config for thin wars and wabs

    Details

    • Type: Feature Request
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      When a dependency jar with a META-INF/services/javax.servlet.ServletContainerInitializer is included inside a war's WEB-INF/lib it will be detected and run. However, when that dependency is extracted from WEB-INF/lib and included as an OSGi module instead, the ServletContainerInitializer will not be run. If possible, the dependencies of the bundle should be searched for any META-INF/services/javax.servlet.ServletContainerInitializer files which should then be run at the appropriate time.

      Steps to reproduce:

      I've attached the reproducer as a git bundle but you can also access it on github.

      1. Start Liferay Portal 7.0+.
      2. Declare the location of Liferay Portal's home directory:
         LIFERAY_HOME=/path/to/liferay-portal-7.0
        
      3. Remove any previous versions of the example artifacts:
         rm $LIFERAY_HOME/osgi/war/jsp-war-portlet*.war $LIFERAY_HOME/osgi/modules/ServletContainerInitializer-dependency*.jar
        
      4. Build the project as a fat war:
         cd ServletContainerInitializer-example && mvn clean package
        
      5. Copy the war to Liferay's deploy folder:
         cp jsp-war-portlet/target/jsp-war-portlet-1.0.war $LIFERAY_HOME/deploy/jsp-war-portlet.war
        
      6. Examine the Liferay logs to confirm that the following logs appear indicating that ExampleServletContainerInitializer.onStartup() was executed:
         21:16:03,202 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:37]             -------------------------------------------------------------------------------------
         21:16:03,203 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:38]             The following classes were annotated with com.liferay.example.servlet.container.initializer.dependency.ExampleAnnotation:
         21:16:03,203 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:42]             com.liferay.blade.samples.portlet.ExampleAnnotatedClass
         21:16:03,203 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:46]             -------------------------------------------------------------------------------------
        
      7. Remove any previous versions of the example artifacts:
         rm $LIFERAY_HOME/osgi/war/jsp-war-portlet*.war $LIFERAY_HOME/osgi/modules/ServletContainerInitializer-dependency*.jar
        
      8. Build the project as a thin war:
         mvn clean package -P thin-war
        
      9. Copy the ServletContainerInitializer-dependency.jar to Liferay's osgi/modules folder:
         cp ServletContainerInitializer-dependency/target/ServletContainerInitializer-dependency-1.0.jar $LIFERAY_HOME/osgi/modules/.
        
      10. Wait until that module has started.
      11. Copy the war to Liferay's deploy folder:
        cp jsp-war-portlet/target/jsp-war-portlet-1.0.war $LIFERAY_HOME/deploy/jsp-war-portlet.war
        

      If the feature is complete the logs will appear the same as when the dependency was packaged within the war (indicating that ExampleServletContainerInitializer.onStartup() executed):

      21:16:03,202 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:37]             -------------------------------------------------------------------------------------
      21:16:03,203 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:38]             The following classes were annotated with com.liferay.example.servlet.container.initializer.dependency.ExampleAnnotation:
      21:16:03,203 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:42]             com.liferay.blade.samples.portlet.ExampleAnnotatedClass
      21:16:03,203 FATAL [fileinstall-/home/kylestiemann/Portals/liferay.com/7.0/osgi/war][ExampleServletContainerInitializer:46]             -------------------------------------------------------------------------------------
      

      If the feature is not complete ExampleServletContainerInitializer.onStartup() will not be executed and no logs will appear.

      Notes

      In order to find the appropriate ServletContainerInitializer s, the dependencies of the bundle must be found using the OSGi API. It may or may not be necessary to recursively find the dependencies. The following code would need to appear in WabBundleProcessor.init(Dictionary<String, Object> properties):

      BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
      List<BundleWire> bundleWires = bundleWiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
      
      for (BundleWire bundleWire : bundleWires) {
      
          bundle = bundleWire.getProvider().getBundle();
      
          if (bundle.getBundleId() != 0) {
      
              // See here for more details:
              // https://github.com/liferay/liferay-portal/blob/7.0.4-ga5/modules/apps/static/portal-osgi-web/portal-osgi-web-wab-extender/src/main/java/com/liferay/portal/osgi/web/wab/extender/internal/WabBundleProcessor.java#L590-L634
              /*wabBundleProcessor.*/initServletContainerInitializers(bundle, servletContext);
      
              // Consider searching the dependencies of the current bundle here to ensure that
              // transitive dependencies are searched.
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              raymond.auge Raymond Auge
              Reporter:
              kyle.stiemann Kyle Stiemann (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Packages

                Version Package