You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ke...@apache.org on 2008/01/03 14:28:41 UTC

svn commit: r608478 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: deployment/repository/util/ deployment/resolver/ description/

Author: keithc
Date: Thu Jan  3 05:28:40 2008
New Revision: 608478

URL: http://svn.apache.org/viewvc?rev=608478&view=rev
Log:
Fixing the customResolvers that axis2 has to work with WSDL 2.0 so that importing schemas and wsdls from inside an aar would work.


Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/WarBasedWSDLLocator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?rev=608478&r1=608477&r2=608478&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Thu Jan  3 05:28:40 2008
@@ -226,6 +226,8 @@
                             serviceArchiveFile.getCanonicalFile().toURI().toString());
 
                 } else if (axisServiceBuilder instanceof WSDL20ToAllAxisServicesBuilder) {
+                    ((WSDL20ToAllAxisServicesBuilder) axisServiceBuilder).setCustomWSDLResolver(
+                            new AARBasedWSDLLocator(baseURI, serviceArchiveFile, in));
                     // trying to use the jar scheme as the base URI. I think this can be used to handle
                     // wsdl 1.1 as well without using a custom URI resolver. Need to look at it later.
                     axisServiceBuilder.setBaseUri(
@@ -399,21 +401,33 @@
         OMElement element = (OMElement) XMLUtils.toOM(in);
         OMNamespace documentElementNS = element.getNamespace();
         if (documentElementNS != null) {
-            WSDL11ToAllAxisServicesBuilder wsdlToAxisServiceBuilder;
+            WSDLToAxisServiceBuilder wsdlToAxisServiceBuilder;
             ByteArrayOutputStream out = new ByteArrayOutputStream();
             element.serialize(out);
             if (Constants.NS_URI_WSDL11.
                     equals(documentElementNS.getNamespaceURI())) {
                 wsdlToAxisServiceBuilder = new WSDL11ToAllAxisServicesBuilder(
                         new ByteArrayInputStream(out.toByteArray()));
-                wsdlToAxisServiceBuilder.setCustomWSDLResolver(new WarBasedWSDLLocator(wsdlUrl,
+                ((WSDL11ToAllAxisServicesBuilder)wsdlToAxisServiceBuilder).setCustomWSDLResolver(new WarBasedWSDLLocator(wsdlUrl,
                                                                                          loader,
                                                                                          new ByteArrayInputStream(
                                                                                                  out.toByteArray())));
                 wsdlToAxisServiceBuilder.setCustomResolver(
                         new WarFileBasedURIResolver(loader));
-                return wsdlToAxisServiceBuilder.populateAllServices();
-            } else {
+                return ((WSDL11ToAllAxisServicesBuilder)wsdlToAxisServiceBuilder).populateAllServices();
+            } else if (WSDL2Constants.WSDL_NAMESPACE.
+                    equals(documentElementNS.getNamespaceURI())){
+                wsdlToAxisServiceBuilder = new WSDL20ToAllAxisServicesBuilder(
+                        new ByteArrayInputStream(out.toByteArray()));
+                ((WSDL20ToAllAxisServicesBuilder)wsdlToAxisServiceBuilder).setCustomWSDLResolver(new WarBasedWSDLLocator(wsdlUrl,
+                                                                                         loader,
+                                                                                         new ByteArrayInputStream(
+                                                                                                 out.toByteArray())));
+                wsdlToAxisServiceBuilder.setCustomResolver(
+                        new WarFileBasedURIResolver(loader));
+                return ((WSDL20ToAllAxisServicesBuilder)wsdlToAxisServiceBuilder).populateAllServices();
+            }
+            else {
                 throw new DeploymentException(Messages.getMessage("invalidWSDLFound"));
             }
         }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java?rev=608478&r1=608477&r2=608478&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java Thu Jan  3 05:28:40 2008
@@ -20,6 +20,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.woden.resolver.URIResolver;
+import org.apache.woden.WSDLException;
 import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
 import org.xml.sax.InputSource;
 
@@ -31,6 +33,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
@@ -42,7 +45,7 @@
  * The logic here is that we only care about the import location
  * all imports must be relative to the META-INF folder
  */
-public class AARBasedWSDLLocator extends DefaultURIResolver implements WSDLLocator {
+public class AARBasedWSDLLocator extends DefaultURIResolver implements WSDLLocator, URIResolver {
 
     protected static final Log log = LogFactory
             .getLog(AARBasedWSDLLocator.class);
@@ -131,4 +134,21 @@
     public void close() {
         //TODO: FIXME:    
     }
-}
+
+    public URI resolveURI(URI uri) throws WSDLException, IOException {
+        lastImportLocation = URI.create(baseURI).resolve(uri);
+
+        if (isAbsolute(uri.toString())) {
+            return uri;
+        } else {
+            String absolutePath = aarFile.getAbsolutePath();
+            try {
+                return new URI("jar:file://" + absolutePath + "!/" + lastImportLocation);
+            } catch (URISyntaxException e) {
+                log.debug(e);
+            }
+        }
+        log.info("AARBasedWSDLLocator: Unable to resolve " + lastImportLocation);
+        return null;
+    }
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/WarBasedWSDLLocator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/WarBasedWSDLLocator.java?rev=608478&r1=608477&r2=608478&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/WarBasedWSDLLocator.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/resolver/WarBasedWSDLLocator.java Thu Jan  3 05:28:40 2008
@@ -21,13 +21,18 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
+import org.apache.woden.resolver.URIResolver;
+import org.apache.woden.WSDLException;
 import org.xml.sax.InputSource;
 
 import javax.wsdl.xml.WSDLLocator;
 import java.io.InputStream;
+import java.io.IOException;
 import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
 
-public class WarBasedWSDLLocator extends DefaultURIResolver implements WSDLLocator {
+public class WarBasedWSDLLocator extends DefaultURIResolver implements WSDLLocator, URIResolver {
     protected static final Log log = LogFactory
             .getLog(WarBasedWSDLLocator.class);
 
@@ -82,5 +87,25 @@
 
     public void close() {
         //TODO: FIXME:
+    }
+
+    public URI resolveURI(URI uri) throws WSDLException, IOException {
+
+        if (isAbsolute(uri.toString())) {
+            return uri;
+        } else {
+            lastImportLocation = URI.create(baseURI).resolve(uri.toString());
+            String searchingStr = lastImportLocation.toString();
+            URL resource = classLoader.getResource(searchingStr);
+            if (resource != null) {
+                try {
+                    return resource.toURI();
+                } catch (URISyntaxException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            log.info("AARBasedWSDLLocator: Unable to resolve " + lastImportLocation);
+            return null;
+        }
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java?rev=608478&r1=608477&r2=608478&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java Thu Jan  3 05:28:40 2008
@@ -242,7 +242,7 @@
     /**
      * sets a custom WSDL locator
      *
-     * @param customWSDLResolver
+     * @param customResolver
      */
     public void setCustomWSDLResolver(WSDLLocator customResolver) {
         this.customWSDLResolver = customResolver;

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java?rev=608478&r1=608477&r2=608478&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/WSDL20ToAxisServiceBuilder.java Thu Jan  3 05:28:40 2008
@@ -36,6 +36,7 @@
 import org.apache.woden.WSDLReader;
 import org.apache.woden.WSDLSource;
 import org.apache.woden.XMLElement;
+import org.apache.woden.resolver.URIResolver;
 import org.apache.woden.internal.DOMWSDLFactory;
 import org.apache.woden.internal.wsdl20.BindingFaultImpl;
 import org.apache.woden.internal.wsdl20.BindingOperationImpl;
@@ -120,6 +121,8 @@
 
     private boolean isAllPorts;
 
+    private URIResolver customWSDLResolver;
+
 //    As bindings are processed add it to this array so that we dont process the same binding twice
     private Map processedBindings;
 
@@ -180,6 +183,15 @@
         isAllPorts = allPorts;
     }
 
+    /**
+     * sets a custom WSDL locator
+     *
+     * @param customResolver
+     */
+    public void setCustomWSDLResolver(URIResolver customResolver) {
+        this.customWSDLResolver = customResolver;
+    }
+
     public AxisService populateService() throws AxisFault {
 
         try {
@@ -431,6 +443,9 @@
                     Document document = documentBuilder.parse(in);
 
                     WSDLReader reader = DOMWSDLFactory.newInstance().newWSDLReader();
+                    if (customWSDLResolver != null) {
+                        reader.setURIResolver(customWSDLResolver);
+                    }
                     // This turns on WSDL validation which is set off by default.
                     reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
                     WSDLSource wsdlSource = reader.createWSDLSource();
@@ -1095,8 +1110,11 @@
     private Description readInTheWSDLFile(String wsdlURI) throws WSDLException {
 
         WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+        if (customWSDLResolver != null) {
+            reader.setURIResolver(customWSDLResolver);
+        }
         // This turns on WSDL validation which is set off by default.
-//        reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+        reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
         
 //      Log when and from where the WSDL is loaded.
         if (log.isDebugEnabled()) {



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org