servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r721996 - /servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
Date Mon, 01 Dec 2008 08:31:02 GMT
Author: gnodet
Date: Mon Dec  1 00:31:02 2008
New Revision: 721996

URL: http://svn.apache.org/viewvc?rev=721996&view=rev
Log:
SM-1036: SoapEndpoint loadWsdl() does not support importing from relative paths

Modified:
    servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java

Modified: servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java?rev=721996&r1=721995&r2=721996&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
(original)
+++ servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
Mon Dec  1 00:31:02 2008
@@ -35,6 +35,7 @@
 import javax.wsdl.extensions.ExtensionRegistry;
 import javax.wsdl.extensions.schema.Schema;
 import javax.wsdl.extensions.schema.SchemaImport;
+import javax.wsdl.extensions.schema.SchemaReference;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.wsdl.xml.WSDLWriter;
@@ -420,10 +421,10 @@
     
     protected void mapDefinition(Definition def) throws WSDLException {
         wsdls.put("main.wsdl", createWsdlWriter().getDocument(def));
-        mapImports(def);
+        mapImports(def, "");
     }
 
-    protected void mapImports(Definition def) throws WSDLException {
+    protected void mapImports(Definition def, String contextPath) throws WSDLException {
         // Add other imports to mapping
         Map imports = def.getImports();
         for (Iterator iter = imports.values().iterator(); iter.hasNext();) {
@@ -433,8 +434,9 @@
                 Definition impDef = imp.getDefinition();
                 String impLoc = imp.getLocationURI();
                 if (impDef != null && impLoc != null && !URI.create(impLoc).isAbsolute())
{
+                    impLoc = resolveRelativeURI(contextPath, impLoc);
                     wsdls.put(impLoc, createWsdlWriter().getDocument(impDef));
-                    mapImports(impDef);
+                    mapImports(impDef, getURIParent(impLoc));
                 }
             }
         }
@@ -445,13 +447,13 @@
                 ExtensibilityElement ee = (ExtensibilityElement) it.next();
                 if (ee instanceof Schema) {
                     Schema schema = (Schema) ee;
-                    mapSchemaImport(schema);                
+                    mapSchema(schema, "");
                 }
             }
         }
     }
 
-    private void mapSchemaImport(Schema schema) {
+    private void mapSchema(Schema schema, String contextPath) {
         Map schemaImports = schema.getImports();
         for (Iterator iter = schemaImports.values().iterator(); iter.hasNext();) {
             List imps = (List) iter.next();
@@ -460,14 +462,60 @@
                 Schema schemaImp = schemaImport.getReferencedSchema();
                 String schemaLoc = schemaImport.getSchemaLocationURI();
                 if (schemaLoc != null && schemaImp != null && schemaImp.getElement()
!= null && !URI.create(schemaLoc).isAbsolute()) {
+                    schemaLoc = resolveRelativeURI(contextPath, schemaLoc);
                     wsdls.put(schemaLoc, schemaImp.getElement());
-                    mapSchemaImport(schemaImp);
+                    // recursively map imported schemas
+                    mapSchema(schemaImp, getURIParent(schemaLoc));
                 }
             }
         }
+        List schemaIncludes = schema.getIncludes();
+        for (Iterator iter = schemaIncludes.iterator(); iter.hasNext();) {
+            SchemaReference schemaInclude = (SchemaReference) iter.next();
+            Schema schemaImp = schemaInclude.getReferencedSchema();
+            String schemaLoc = schemaInclude.getSchemaLocationURI();
+            if (schemaLoc != null && schemaImp != null && schemaImp.getElement()
!= null && !URI.create(schemaLoc).isAbsolute()) {
+                schemaLoc = resolveRelativeURI(contextPath, schemaLoc);
+                wsdls.put(schemaLoc, schemaImp.getElement());
+                // recursively map included schemas
+                mapSchema(schemaImp, getURIParent(schemaLoc));
+            }
+        }
     }
     
     /**
+     * Combines a relative path with a current directory, normalising any
+     * relative pathnames like "." and "..".
+     * <p>
+     * Example:
+     * <table>
+     * <tr><th>context</th><th>path</th><th>resolveRelativeURI(context,
path)</th></tr>
+     * <tr><td>addressModification</td><td>../common/DataType.xsd</td><td>common/DataType.xsd</td></tr>
+     * </table>
+     *
+     * @param context The current directory.
+     * @param path The relative path to resolve against the current directory.
+     * @return the normalised path.
+     */
+    private static String resolveRelativeURI(String context, String path) {
+        if (context.length() > 0) {
+            return URI.create(context + "/" + path).normalize().getPath();
+        } else {
+            return path;
+        }
+    }
+
+    /**
+     * Removes the filename part of a URI path.
+     *
+     * @param path A URI path part.
+     * @return The URI path part with the filename part removed.
+     */
+    private static String getURIParent(String path) {
+        return URI.create(path + "/..").normalize().getPath();
+    }
+
+    /**
      * @return Returns the wsdls.
      */
     public Map getWsdls() {



Mime
View raw message