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

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


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

commit fe905a43bf935cb293db462915a17ad87c303438
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      | 32 +++++++++++++++++-----
 webapps/docs/changelog.xml                         | 11 ++++++++
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/java/org/apache/catalina/startup/WebappServiceLoader.java 
b/java/org/apache/catalina/startup/WebappServiceLoader.java
index 0133d8d..f22e7a8 100644
--- a/java/org/apache/catalina/startup/WebappServiceLoader.java
+++ b/java/org/apache/catalina/startup/WebappServiceLoader.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -58,6 +59,7 @@ import org.apache.tomcat.util.buf.UriUtil;
  * @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/";
     private static final Charset UTF8 = Charset.forName("UTF-8");
@@ -100,10 +102,26 @@ 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
+            if (loader instanceof URLClassLoader) {
+                Enumeration<URL> resources = ((URLClassLoader) 
loader).findResources("/" + configFile);
+                while (resources.hasMoreElements()) {
+                    URL resource = resources.nextElement();
+                    parseConfigFile(applicationServicesFound, resource);
+                }
+            }
+        } else {
+            // Ordered libs so only use services defined in those libs and any
+            // in WEB-INF/classes
+            URL unpacked = servletContext.getResource(CLASSES + configFile);
+            if (unpacked != null) {
+                parseConfigFile(applicationServicesFound, unpacked);
+            }
+
             for (String lib : orderedLibs) {
                 URL jarUrl = servletContext.getResource(LIB + lib);
                 if (jarUrl == null) {
@@ -124,11 +142,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);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a2e88f1..74c7bf5 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -88,6 +88,17 @@
         (michaelo)
       </fix>
       <fix>
+        <bug>64021</bug>: Ensure that container provided SCIs are always loaded
+        before application provided SCIs. Note that where both the container 
and
+        the application provide the same SCI, it is the application provided 
SCI
+        that will be used. (markt)
+      </fix>
+      <fix>
+        SCI definitions from JARs unpacked into <code>WEB-INF/classes</code> 
are
+        now handled consistently and will always be found irrespective of
+        whether the web application defines a JAR ordering or not. (markt)
+      </fix>
+      <fix>
         <bug>64023</bug>: Skip null-valued session attributes when 
deserializing
         sessions. (schultz)
       </fix>


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

Reply via email to