This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 82af31d  https://bz.apache.org/bugzilla/show_bug.cgi?id=64021 SCI 
ordering
82af31d is described below

commit 82af31d38d8f84eebe3284fcbf2bde33745cdf4e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jan 16 11:10:13 2020 +0000

    https://bz.apache.org/bugzilla/show_bug.cgi?id=64021 SCI ordering
    
    Ensure that container provided SCIs are always loaded before application
    provided SCIs. Where both container and application provide the same
    SCI, the application takes priority.
    SCI definitions from JARS unpacked into WEB-INF/classes are now handled
    consistently and will always be found irrespective of whether the web
    application defines a JAR ordering or not.
---
 .../catalina/startup/WebappServiceLoader.java      | 29 ++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/catalina/startup/WebappServiceLoader.java 
b/java/org/apache/catalina/startup/WebappServiceLoader.java
index f0d2465..11c4b43 100644
--- a/java/org/apache/catalina/startup/WebappServiceLoader.java
+++ b/java/org/apache/catalina/startup/WebappServiceLoader.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 import jakarta.servlet.ServletContext;
 
 import org.apache.catalina.Context;
+import org.apache.catalina.WebResource;
 import org.apache.tomcat.util.scan.JarFactory;
 
 /**
@@ -58,6 +59,7 @@ import org.apache.tomcat.util.scan.JarFactory;
  * @see java.util.ServiceLoader
  */
 public class WebappServiceLoader<T> {
+    private static final String CLASSES = "/WEB-INF/classes/";
     private static final String LIB = "/WEB-INF/lib/";
     private static final String SERVICES = "META-INF/services/";
 
@@ -99,10 +101,23 @@ public class WebappServiceLoader<T> {
         // if the ServletContext has ORDERED_LIBS, then use that to specify the
         // set of JARs from WEB-INF/lib that should be used for loading 
services
         @SuppressWarnings("unchecked")
-        List<String> orderedLibs =
-                (List<String>) 
servletContext.getAttribute(ServletContext.ORDERED_LIBS);
-        if (orderedLibs != null) {
-            // handle ordered libs directly, ...
+        List<String> orderedLibs = (List<String>) 
servletContext.getAttribute(ServletContext.ORDERED_LIBS);
+
+        // Handle application SCIs directly...
+        if (orderedLibs == null) {
+            // No ordered libs, so use every service definition we can find
+            WebResource[] resources = 
context.getResources().getClassLoaderResources("/" + configFile);
+            for (WebResource resource : resources) {
+                if (resource.isFile()) {
+                    parseConfigFile(applicationServicesFound, 
resource.getURL());
+                }
+            }
+        } else {
+            // Ordered libs so only use services defined in those libs and any
+            // in WEB-INF/classes
+            URL unpacked = servletContext.getResource(CLASSES + configFile);
+            parseConfigFile(applicationServicesFound, unpacked);
+
             for (String lib : orderedLibs) {
                 URL jarUrl = servletContext.getResource(LIB + lib);
                 if (jarUrl == null) {
@@ -123,11 +138,11 @@ public class WebappServiceLoader<T> {
                     // no provider file found, this is OK
                 }
             }
-
-            // and the parent ClassLoader for all others
-            loader = context.getParentClassLoader();
         }
 
+        // and use the parent ClassLoader for all other SCIs
+        loader = context.getParentClassLoader();
+
         Enumeration<URL> resources;
         if (loader == null) {
             resources = ClassLoader.getSystemResources(configFile);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to