cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1550468 - in /cxf/trunk: core/src/main/java/org/apache/cxf/common/util/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/ systests/jaxrs/src/test/resources/jaxrs/WEB-INF/
Date Thu, 12 Dec 2013 18:22:35 GMT
Author: sergeyb
Date: Thu Dec 12 18:22:34 2013
New Revision: 1550468

URL: http://svn.apache.org/r1550468
Log:
[CXF-5324] Optimizing schema lookups in case of many schema resources

Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/common/util/ClasspathScanner.java
    cxf/trunk/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/common/util/ClasspathScanner.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/common/util/ClasspathScanner.java?rev=1550468&r1=1550467&r2=1550468&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/common/util/ClasspathScanner.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/common/util/ClasspathScanner.java Thu Dec
12 18:22:34 2013
@@ -31,7 +31,8 @@ public class ClasspathScanner {
     public static final String ALL_FILES = "**/*";
     public static final String ALL_CLASS_FILES = ALL_FILES + ".class";
     public static final String ALL_PACKAGES = "*";
-
+    public static final String CLASSPATH_URL_SCHEME = "classpath:";
+    
     static final ClasspathScanner HELPER;
     static {
         ClasspathScanner theHelper = null;
@@ -52,6 +53,20 @@ public class ClasspathScanner {
 
     /**
      * Scans list of base packages for all classes marked with specific annotations. 
+     * @param basePackage base package 
+     * @param annotations annotations to discover
+     * @return all discovered classes grouped by annotations they belong too 
+     * @throws IOException class metadata is not readable 
+     * @throws ClassNotFoundException class not found
+     */
+    public static Map< Class< ? extends Annotation >, Collection< Class< ?
> > > findClasses(
+        String basePackage, Class< ? extends Annotation > ... annotations) 
+        throws IOException, ClassNotFoundException {
+        return findClasses(Collections.singletonList(basePackage), Arrays.asList(annotations));
+    }
+    
+    /**
+     * Scans list of base packages for all classes marked with specific annotations. 
      * @param basePackages list of base packages 
      * @param annotations annotations to discover
      * @return all discovered classes grouped by annotations they belong too 
@@ -87,6 +102,18 @@ public class ClasspathScanner {
     
     /**
      * Scans list of base packages for all resources with the given extension. 
+     * @param basePackage base package 
+     * @param extension the extension matching resources needs to have
+     * @return list of all discovered resource URLs 
+     * @throws IOException resource is not accessible
+     */
+    public static List<URL> findResources(String basePackage, String extension) 
+        throws IOException {
+        return findResources(Collections.singletonList(basePackage), extension);
+    }
+    
+    /**
+     * Scans list of base packages for all resources with the given extension. 
      * @param basePackages list of base packages 
      * @param extension the extension matching resources needs to have
      * @return list of all discovered resource URLs 

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java?rev=1550468&r1=1550467&r2=1550468&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/common/util/SpringClasspathScanner.java Thu
Dec 12 18:22:34 2013
@@ -94,8 +94,13 @@ class SpringClasspathScanner extends Cla
         for (final String basePackage: basePackages) {
             final boolean scanAllPackages = basePackage.equals(ALL_PACKAGES);
             
+            String theBasePackage = basePackage;
+            if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
+                theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
+            }
+            
             final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX

-                + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(basePackage))

+                + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(theBasePackage))

                 + ALL_FILES + "." + extension;
             
             final Resource[] resources = resolver.getResources(packageSearchPath);      
                 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java?rev=1550468&r1=1550467&r2=1550468&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java
Thu Dec 12 18:22:34 2013
@@ -26,6 +26,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Logger;
 
@@ -41,6 +42,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ClasspathScanner;
 import org.apache.cxf.common.xmlschema.LSInputImpl;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.ws.commons.schema.constants.Constants;
@@ -88,15 +90,26 @@ public class SchemaHandler {
         try {
             List<Source> sources = new ArrayList<Source>();
             for (String loc : locations) {
-                URL url = ResourceUtils.getResourceURL(loc, bus);
-                if (url == null) {
-                    return null;
+                List<URL> schemaURLs = new LinkedList<URL>();
+                
+                if (loc.lastIndexOf(".") == -1) {
+                    schemaURLs = ClasspathScanner.findResources(loc, "xsd");
+                } else {
+                    URL url = ResourceUtils.getResourceURL(loc, bus);
+                    if (url != null) {
+                        schemaURLs.add(url);
+                    }
+                }
+                for (URL schemaURL : schemaURLs) {
+                    Reader r = new BufferedReader(
+                                   new InputStreamReader(schemaURL.openStream(), "UTF-8"));
+                    StreamSource source = new StreamSource(r);
+                    source.setSystemId(schemaURL.toString());
+                    sources.add(source);
                 }
-                Reader r = new BufferedReader(
-                               new InputStreamReader(url.openStream(), "UTF-8"));
-                StreamSource source = new StreamSource(r);
-                source.setSystemId(url.toString());
-                sources.add(source);
+            }
+            if (sources.isEmpty()) {
+                return null;
             }
             final OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
             if (catalogResolver != null) {

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1550468&r1=1550467&r2=1550468&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Thu Dec 12 18:22:34
2013
@@ -214,7 +214,7 @@
         <property name="schemaLocations" ref="theSchemas"/>
     </bean>
     <util:list id="theSchemas">
-        <value>classpath:/org/apache/cxf/systest/jaxrs/resources/book.xsd</value>
+        <value>classpath:/org/apache/cxf/systest/jaxrs/resources/</value>
     </util:list>
     <util:list id="jsonTypes">
         <value>application/json</value>



Mime
View raw message