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 di...@apache.org on 2006/11/03 18:57:56 UTC

svn commit: r470928 - in /webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2: deployment/repository/util/ deployment/resolver/ transport/http/

Author: dims
Date: Fri Nov  3 09:57:55 2006
New Revision: 470928

URL: http://svn.apache.org/viewvc?view=rev&rev=470928
Log:
Am really scared doing this at this point before 1.1!! But existing code 
was not doing the right thing. Would appreciate if folks re-tried their 
AAR's with this change. Spent a day going through our code and WSDL4J 
code to get this working. 

Fix for Blocker issue AXIS2-1556 - DeploymentException with segmented wsdl files


Modified:
    webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
    webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java
    webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java
    webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java

Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java?view=diff&rev=470928&r1=470927&r2=470928
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java (original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/repository/util/ArchiveReader.java Fri Nov  3 09:57:55 2006
@@ -16,16 +16,26 @@
 
 
 package org.apache.axis2.deployment.repository.util;
-
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.deployment.*;
+import org.apache.axis2.deployment.DeploymentConstants;
+import org.apache.axis2.deployment.DeploymentErrorMsgs;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.deployment.DescriptionBuilder;
+import org.apache.axis2.deployment.ModuleBuilder;
+import org.apache.axis2.deployment.ServiceBuilder;
+import org.apache.axis2.deployment.ServiceGroupBuilder;
 import org.apache.axis2.deployment.resolver.AARBasedWSDLLocator;
 import org.apache.axis2.deployment.resolver.AARFileBasedURIResolver;
-import org.apache.axis2.description.*;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
+import org.apache.axis2.description.WSDL20ToAxisServiceBuilder;
+import org.apache.axis2.description.WSDLToAxisServiceBuilder;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.namespace.Constants;
@@ -35,12 +45,17 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
-
 public class ArchiveReader implements DeploymentConstants {
     private static final Log log = LogFactory.getLog(ArchiveReader.class);
 
@@ -180,7 +195,7 @@
      * @throws DeploymentException
      */
     private AxisService processWSDLFile(WSDLToAxisServiceBuilder axisServiceBuilder, File serviceArchiveFile,
-                                        boolean isArchive, InputStream in) throws DeploymentException {
+                                        boolean isArchive, InputStream in, String baseURI) throws DeploymentException {
         try {
 
             if (serviceArchiveFile != null && isArchive) {
@@ -189,7 +204,7 @@
                 if (axisServiceBuilder instanceof WSDL11ToAxisServiceBuilder) {
 
                     ((WSDL11ToAxisServiceBuilder) axisServiceBuilder).setCustomWSLD4JResolver(
-                            new AARBasedWSDLLocator(serviceArchiveFile, in));
+                            new AARBasedWSDLLocator(baseURI, serviceArchiveFile, in));
                 }
             } else {
                 if (serviceArchiveFile != null) {
@@ -288,7 +303,7 @@
                             } else {
                                 new DeploymentException(Messages.getMessage("invalidWSDLFound"));
                             }
-                            AxisService service = processWSDLFile(wsdlToAxisServiceBuilder, serviceFile, true, new ByteArrayInputStream(out.toByteArray()));
+                            AxisService service = processWSDLFile(wsdlToAxisServiceBuilder, serviceFile, true, new ByteArrayInputStream(out.toByteArray()), entry.getName());
                             if(service != null) {
                                 servicesMap.put(service.getName(), service);
                             }
@@ -344,7 +359,7 @@
                     }
 
                     FileInputStream in3 = new FileInputStream(file1);
-                    AxisService service = processWSDLFile(wsdlToAxisServiceBuilder, file1, false, in2);
+                    AxisService service = processWSDLFile(wsdlToAxisServiceBuilder, file1, false, in2, file1.toURI().toString());
                     try {
                         if (in2 != null) {
                             in2.close();

Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java?view=diff&rev=470928&r1=470927&r2=470928
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java (original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARBasedWSDLLocator.java Fri Nov  3 09:57:55 2006
@@ -3,12 +3,15 @@
 import org.apache.axis2.deployment.DeploymentConstants;
 import org.apache.axis2.deployment.util.Utils;
 import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 
 import javax.wsdl.xml.WSDLLocator;
 import java.io.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
+import java.net.URI;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -35,11 +38,16 @@
  */
 public class AARBasedWSDLLocator extends DefaultURIResolver implements WSDLLocator {
 
+    protected static final Log log = LogFactory
+            .getLog(AARBasedWSDLLocator.class);
+
     private File aarFile;
     private InputStream baseInputStream;
-    private String lastImportLocation = "";
+    private URI lastImportLocation;
+    private String baseURI;
 
-    public AARBasedWSDLLocator(File zipFile, InputStream baseInputStream) {
+    public AARBasedWSDLLocator(String baseURI, File zipFile, InputStream baseInputStream) {
+        this.baseURI = baseURI;
         this.baseInputStream = baseInputStream;
         this.aarFile = zipFile;
     }
@@ -53,14 +61,8 @@
      * @param importLocation
      */
     public InputSource getImportInputSource(String parentLocation, String importLocation) {
-        //setting current import location.
-        if (importLocation != null && importLocation.length() > 0) {
-            int speindex = importLocation.lastIndexOf("/");
-            if (speindex > 0) {
-                lastImportLocation = importLocation.substring(0, speindex);
-            }
+        lastImportLocation = URI.create(parentLocation).resolve(importLocation);
 
-        }
         if (isAbsolute(importLocation)) {
             return super.resolveEntity(
                     null, importLocation, parentLocation);
@@ -74,14 +76,9 @@
                 byte[] buf = new byte[1024];
                 int read;
                 ByteArrayOutputStream out;
-                String searchingStr;
-                if (parentLocation != null && parentLocation.length() > 0) {
-                    importLocation = Utils.getPath(parentLocation, importLocation);
-                }
-                importLocation = Utils.normalize(importLocation);
+                String searchingStr = lastImportLocation.toString();
                 while ((entry = zin.getNextEntry()) != null) {
                     String entryName = entry.getName().toLowerCase();
-                    searchingStr = (DeploymentConstants.META_INF + "/" + importLocation).toLowerCase();
                     if (entryName.equalsIgnoreCase(searchingStr)) {
                         out = new ByteArrayOutputStream();
                         while ((read = zin.read(buf)) > 0) {
@@ -91,19 +88,18 @@
                         return new InputSource(in);
                     }
                 }
-
-
             } catch (IOException e) {
                 throw new RuntimeException(e);
             } finally {
                 try {
                     if (zin != null) zin.close();
                 } catch (IOException e) {
-                    //log this error
+                    log.debug(e);
                 }
             }
         }
 
+        log.info("AARBasedWSDLLocator: Unable to resolve" + lastImportLocation);
         return null;
     }
 
@@ -113,7 +109,7 @@
      */
     public String getBaseURI() {
         // we don't care
-        return "";
+        return baseURI;
     }
 
     /**
@@ -121,7 +117,7 @@
      */
     public String getLatestImportURI() {
         //we don't care about this either
-        return lastImportLocation;
+        return lastImportLocation.toString();
     }
     
     public void close() {

Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java?view=diff&rev=470928&r1=470927&r2=470928
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java (original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/deployment/resolver/AARFileBasedURIResolver.java Fri Nov  3 09:57:55 2006
@@ -3,11 +3,14 @@
 import org.apache.axis2.deployment.DeploymentConstants;
 import org.apache.axis2.deployment.util.Utils;
 import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 
 import java.io.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
+import java.net.URI;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -29,28 +32,16 @@
  */
 public class AARFileBasedURIResolver extends DefaultURIResolver {
 
-    private String aarFileName;
-    private File aarFile;
+    protected static final Log log = LogFactory
+            .getLog(AARFileBasedURIResolver.class);
 
-    public AARFileBasedURIResolver(String aarFileName) {
-        this.aarFileName = aarFileName;
-    }
+    private File aarFile;
+    private URI lastImportLocation;
 
     public AARFileBasedURIResolver(File aarFile) {
         this.aarFile = aarFile;
     }
 
-    public AARFileBasedURIResolver() {
-    }
-
-    public void setAarFileName(String aarFileName) {
-        this.aarFileName = aarFileName;
-    }
-
-    public void setAarFileName(File aarFile) {
-        this.aarFile = aarFile;
-    }
-
     public InputSource resolveEntity(
             String targetNamespace,
             String schemaLocation,
@@ -66,26 +57,18 @@
                         "Unsupported schema location " + schemaLocation);
             }
 
+            lastImportLocation = URI.create(baseUri).resolve(schemaLocation);
             ZipInputStream zin = null;
             try {
-                if (aarFile != null) {
-                    zin = new ZipInputStream(new FileInputStream(aarFile));
-                } else {
-                    zin = new ZipInputStream(new FileInputStream(aarFileName));
-                }
+                zin = new ZipInputStream(new FileInputStream(aarFile));
 
                 ZipEntry entry;
                 byte[] buf = new byte[1024];
                 int read;
                 ByteArrayOutputStream out;
-                String searchingStr;
-                if (baseUri != null && baseUri.length() > 0) {
-                    schemaLocation = Utils.getPath(baseUri, schemaLocation);
-                }
-                schemaLocation = Utils.normalize(schemaLocation);
+                String searchingStr = lastImportLocation.toString();
                 while ((entry = zin.getNextEntry()) != null) {
                     String entryName = entry.getName().toLowerCase();
-                    searchingStr = (DeploymentConstants.META_INF + "/" + schemaLocation).toLowerCase();
                     if (entryName.equalsIgnoreCase(searchingStr)) {
                         out = new ByteArrayOutputStream();
                         while ((read = zin.read(buf)) > 0) {
@@ -103,12 +86,13 @@
                 try {
                     if (zin != null) zin.close();
                 } catch (IOException e) {
-                    //log this error
+                    log.debug(e);
                 }
             }
 
         }
 
+        log.info("AARFileBasedURIResolver: Unable to resolve" + lastImportLocation);
         return null;
     }
 }

Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java?view=diff&rev=470928&r1=470927&r2=470928
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java (original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java Fri Nov  3 09:57:55 2006
@@ -19,12 +19,14 @@
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.deployment.DeploymentConstants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.transport.TransportListener;
 import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.axiom.attachments.utils.IOUtils;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -32,6 +34,7 @@
 import javax.xml.namespace.QName;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
@@ -189,8 +192,14 @@
                             out.flush();
                             out.close();
                         } else {
-                            //the schema is not found - pump a 404
-                            res.sendError(HttpServletResponse.SC_NOT_FOUND);
+                            InputStream in = axisService.getClassLoader().getResourceAsStream(DeploymentConstants.META_INF + "/" + xsds);
+                            if(in != null) {
+                                out.write(IOUtils.getStreamAsByteArray(in));
+                                out.flush();
+                                out.close();
+                            } else {
+                                res.sendError(HttpServletResponse.SC_NOT_FOUND);
+                            }
                         }
 
                         //multiple schemas are present and the user specified



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