You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2006/04/24 17:29:10 UTC

svn commit: r396578 - in /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: deployment/DeploymentEngine.java deployment/repository/util/ArchiveReader.java deployment/resolver/AARBasedWSDLLocator.java description/WSDL2AxisServiceBuilder.java

Author: ajith
Date: Mon Apr 24 08:28:44 2006
New Revision: 396578

URL: http://svn.apache.org/viewcvs?rev=396578&view=rev
Log:
Added a WSDL locator that allows WSDL4J to load <imports> and <includes> from zip archives

Added:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java?rev=396578&r1=396577&r2=396578&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/DeploymentEngine.java Mon Apr 24 08:28:44 2006
@@ -613,6 +613,9 @@
                                         de);
                                 PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
                                 de.printStackTrace(error_ptintWriter);
+                                ////////////////////
+                               de.printStackTrace();
+                                //////////////////////////
                                 serviceStatus = "Error:\n" + errorWriter.toString();
                             } catch (AxisFault axisFault) {
                                 log.error(Messages.getMessage(DeploymentErrorMsgs.INVALID_SERVICE,

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?rev=396578&r1=396577&r2=396578&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Mon Apr 24 08:28:44 2006
@@ -21,6 +21,7 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.deployment.*;
 import org.apache.axis2.deployment.resolver.AARFileBasedURIResolver;
+import org.apache.axis2.deployment.resolver.AARBasedWSDLLocator;
 import org.apache.axis2.description.AxisModule;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
@@ -181,6 +182,9 @@
             if (serviceArchiveFile!=null){
                 wsdl2AxisServiceBuilder.setCustomResolver(
                     new AARFileBasedURIResolver(serviceArchiveFile));
+                wsdl2AxisServiceBuilder.setCustomWSLD4JResolver(
+                        new AARBasedWSDLLocator(serviceArchiveFile,in)
+                );
             }
 
             return wsdl2AxisServiceBuilder.populateService();

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java?rev=396578&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java Mon Apr 24 08:28:44 2006
@@ -0,0 +1,121 @@
+package org.apache.axis2.deployment.resolver;
+
+import org.xml.sax.InputSource;
+import org.apache.axis2.deployment.DeploymentConstants;
+
+import javax.wsdl.xml.WSDLLocator;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipEntry;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Custom WSDL locator to load schemas from zip archives
+ * Need to provide the aarFile and the baseInputStream for
+ * the base WSDL file
+ *
+ * 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 implements WSDLLocator {
+
+    private File aarFile;
+    private InputStream baseInputStream;
+
+    public AARBasedWSDLLocator(File zipFile,InputStream baseInputStream) {
+        this.baseInputStream = baseInputStream;
+        this.aarFile = zipFile;
+    }
+
+    /**
+     *
+     * @return
+     */
+    public InputSource getBaseInputSource() {
+        return new InputSource(baseInputStream);
+    }
+
+    /**
+     *
+     * @param parentLocation
+     * @param importLocation
+     * @return
+     */
+    public InputSource getImportInputSource(String parentLocation, String importLocation) {
+        //we don't care about the parent location
+        ZipInputStream zin = null;
+        try {
+
+            zin = new ZipInputStream(new FileInputStream(aarFile));
+            ZipEntry entry;
+            byte[] buf = new byte[1024];
+            int read;
+            ByteArrayOutputStream out;
+            while ((entry = zin.getNextEntry()) != null) {
+                String entryName = entry.getName().toLowerCase();
+                if (entryName.startsWith(DeploymentConstants.META_INF.toLowerCase())
+                        && entryName.endsWith(importLocation)) {
+                    //read the item into a byte array to allow the
+                    //stream to be closed
+                    out = new ByteArrayOutputStream();
+                    while ((read = zin.read(buf)) > 0) {
+                        out.write(buf, 0, read);
+                    }
+                    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+                    return new InputSource(in);
+                }
+            }
+
+
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally{
+            try {
+                if (zin!=null) zin.close();
+            } catch (IOException e) {
+                //log this error
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * As for the zip there is no point in returning
+     * a base URI
+     * @return
+     */
+    public String getBaseURI() {
+        // we don't care
+        return "";
+    }
+
+    /**
+     * returns the latest import
+     * @return
+     */
+    public String getLatestImportURI() {
+        //we don't care about this either
+        return "";
+    }
+}

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java?rev=396578&r1=396577&r2=396578&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/WSDL2AxisServiceBuilder.java Mon Apr 24 08:28:44 2006
@@ -31,6 +31,7 @@
 import javax.wsdl.extensions.soap.SOAPOperation;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.xml.WSDLLocator;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -135,6 +136,9 @@
 
     private URIResolver customResolver;
 
+    private WSDLLocator customWSLD4JResolver;
+
+
     public WSDL2AxisServiceBuilder(InputStream in, QName serviceName,
                                    String portName) {
         this.in = in;
@@ -164,11 +168,22 @@
         this(in, null, null);
     }
 
-
+    /**
+     * Sets a custom xmlschema resolver
+     * @param customResolver
+     */
     public void setCustomResolver(URIResolver customResolver) {
         this.customResolver = customResolver;
     }
 
+    /**
+     * sets a custem WSDL4J locator
+     * @param customWSLD4JResolver
+     */
+    public void setCustomWSLD4JResolver(WSDLLocator customWSLD4JResolver) {
+        this.customWSLD4JResolver = customWSLD4JResolver;
+    }
+
     public boolean isServerSide() {
         return isServerSide;
     }
@@ -927,7 +942,7 @@
         if (baseUri != null) schemaCollection.setBaseUri(baseUri);
 
         if (customResolver!=null){
-          schemaCollection.setSchemaResolver(customResolver);  
+            schemaCollection.setSchemaResolver(customResolver);
         }
 
         return schemaCollection.read(element);
@@ -936,22 +951,27 @@
     private Definition readInTheWSDLFile(InputStream in) throws WSDLException {
 
         WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
-        reader.setFeature("javax.wsdl.importDocuments", true);
-        Document doc;
-        try {
-            doc = XMLUtils.newDocument(in);
-        } catch (ParserConfigurationException e) {
-            throw new WSDLException(WSDLException.PARSER_ERROR,
-                    "Parser Configuration Error", e);
-        } catch (SAXException e) {
-            throw new WSDLException(WSDLException.PARSER_ERROR,
-                    "Parser SAX Error", e);
+        if (customWSLD4JResolver!=null){
+            return  reader.readWSDL(customWSLD4JResolver);
+        }else{
+
+            reader.setFeature("javax.wsdl.importDocuments", false);
+            Document doc;
+            try {
+                doc = XMLUtils.newDocument(in);
+            } catch (ParserConfigurationException e) {
+                throw new WSDLException(WSDLException.PARSER_ERROR,
+                        "Parser Configuration Error", e);
+            } catch (SAXException e) {
+                throw new WSDLException(WSDLException.PARSER_ERROR,
+                        "Parser SAX Error", e);
 
-        } catch (IOException e) {
-            throw new WSDLException(WSDLException.INVALID_WSDL, "IO Error", e);
-        }
+            } catch (IOException e) {
+                throw new WSDLException(WSDLException.INVALID_WSDL, "IO Error", e);
+            }
 
-        return reader.readWSDL(null, doc);
+            return reader.readWSDL(null, doc);
+        }
     }
 
     /**