axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ami...@apache.org
Subject svn commit: r552837 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: description/AxisService.java transport/http/HTTPWorker.java transport/http/ListingAgent.java
Date Tue, 03 Jul 2007 13:30:33 GMT
Author: amilas
Date: Tue Jul  3 06:30:32 2007
New Revision: 552837

URL: http://svn.apache.org/viewvc?view=rev&rev=552837
Log:
adjust the import and inclued schma locations correctly

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=552837&r1=552836&r2=552837
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
Tue Jul  3 06:30:32 2007
@@ -62,14 +62,14 @@
 import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.apache.ws.commons.schema.utils.NamespacePrefixList;
 import org.codehaus.jam.JMethod;
-import org.w3c.dom.Document;
+import org.w3c.dom.*;
 import org.xml.sax.SAXException;
 
-import javax.wsdl.Definition;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
-import javax.wsdl.WSDLException;
+import javax.wsdl.*;
 import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaReference;
+import javax.wsdl.extensions.schema.SchemaImport;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.wsdl.xml.WSDLWriter;
@@ -81,23 +81,17 @@
 import java.net.SocketException;
 import java.net.URL;
 import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Class AxisService
  */
 public class AxisService extends AxisDescription {
 
+    public static final String IMPORT_TAG = "import";
+    public static final String INCLUDE_TAG = "include";
+    public static final String SCHEMA_LOCATION = "schemaLocation";
+
     private Map endpointMap = new HashMap();
 
     /*This is a map between the QName of the element of a message
@@ -178,6 +172,8 @@
      */
     private boolean schemaLocationsAdjusted = false;
 
+    private boolean wsdlImportLocationAdjusted = false;
+
     /**
      * A table that keeps a mapping of unique xsd names (Strings)
      * against the schema objects. This is populated in the first
@@ -899,11 +895,7 @@
         if (wsld4jdefinition != null) {
             try {
                 Definition definition = (Definition) wsld4jdefinition.getValue();
-                if (isModifyUserWSDLPortAddress()) {
-                    setPortAddress(definition);
-                }
-                WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
-                writer.writeWSDL(definition, out);
+                printDefinitionObject(definition, out);
             } catch (WSDLException e) {
                 throw AxisFault.makeFault(e);
             }
@@ -912,6 +904,133 @@
         }
     }
 
+    private void printDefinitionObject(Definition definition, OutputStream out)
+            throws AxisFault, WSDLException {
+        if (isModifyUserWSDLPortAddress()) {
+            setPortAddress(definition);
+        }
+        if (!wsdlImportLocationAdjusted){
+           changeImportAndIncludeLocations(definition);
+           wsdlImportLocationAdjusted = true;
+        }
+        WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
+        writer.writeWSDL(definition, out);
+    }
+
+    public void printUserWSDL(OutputStream out,
+                              String wsdlName) throws AxisFault {
+        // first find the correct wsdl definition
+        Parameter wsld4jdefinition = getParameter(WSDLConstants.WSDL_4_J_DEFINITION);
+        if (wsld4jdefinition != null) {
+            try {
+                Definition definition = (Definition) wsld4jdefinition.getValue();
+                printDefinitionObject(getWSDLDefinition(definition,wsdlName), out);
+            } catch (WSDLException e) {
+                throw AxisFault.makeFault(e);
+            }
+        } else {
+            printWSDLError(out);
+        }
+
+    }
+
+    /**
+     * find the defintion object for given name
+     * @param parentDefinition
+     * @param name
+     * @return wsdl definition
+     */
+    private Definition getWSDLDefinition(Definition parentDefinition, String name) {
+
+        Definition importedDefinition = null;
+        Iterator iter = parentDefinition.getImports().values().iterator();
+        Vector values = null;
+        Import wsdlImport = null;
+        for (; iter.hasNext();) {
+            values = (Vector) iter.next();
+            for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) {
+                wsdlImport = (Import) valuesIter.next();
+                if (wsdlImport.getLocationURI().endsWith(name)) {
+                    importedDefinition = wsdlImport.getDefinition();
+                    break;
+                } else {
+                    importedDefinition = getWSDLDefinition(wsdlImport.getDefinition(), name);
+                }
+                if (importedDefinition != null) {
+                    break;
+                }
+            }
+            if (importedDefinition != null) {
+                break;
+            }
+        }
+        return importedDefinition;
+    }
+
+    /**
+     * this procesdue recursively adjust the wsdl imports locations
+     * and the schmea import and include locations.
+     * @param definition
+     */
+    private void changeImportAndIncludeLocations(Definition definition){
+
+        //adjust the schema locations in types section
+        Types types = definition.getTypes();
+        List extensibilityElements = types.getExtensibilityElements();
+        Object extensibilityElement = null;
+        Schema schema = null;
+        for (Iterator iter = extensibilityElements.iterator(); iter.hasNext();) {
+            extensibilityElement = iter.next();
+            if (extensibilityElement instanceof Schema) {
+                schema = (Schema) extensibilityElement;
+                changeLocations(schema.getElement());
+            }
+        }
+
+        Iterator iter = definition.getImports().values().iterator();
+        Vector values = null;
+        Import wsdlImport = null;
+        String originalImprotString = null;
+        for (; iter.hasNext();) {
+            values = (Vector) iter.next();
+            for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) {
+                wsdlImport = (Import) valuesIter.next();
+                originalImprotString = wsdlImport.getLocationURI();
+                wsdlImport.setLocationURI(this.name + "?wsdl=" + originalImprotString);
+                changeImportAndIncludeLocations(wsdlImport.getDefinition());
+            }
+        }
+    }
+
+    /**
+     * change the schema Location in the elemment
+     * @param element
+     */
+
+    private void changeLocations(Element element) {
+        NodeList nodeList = element.getChildNodes();
+        String tagName;
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            tagName = nodeList.item(i).getLocalName();
+            if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) {
+                processImport(nodeList.item(i));
+            }
+        }
+    }
+
+    private void processImport(Node importNode) {
+        NamedNodeMap nodeMap = importNode.getAttributes();
+        Node attribute;
+        String attributeValue;
+        for (int i = 0; i < nodeMap.getLength(); i++) {
+            attribute = nodeMap.item(i);
+            if (attribute.getNodeName().equals("schemaLocation")) {
+                attributeValue = attribute.getNodeValue();
+                attribute.setNodeValue(this.name + "?xsd=" + attributeValue);
+            }
+        }
+    }
+
     /**
      * @param out
      * @param requestIP
@@ -962,6 +1081,7 @@
                         } else {
                             ((SOAPAddress) extensibilityEle).setLocationURI(calculateEPRs(requestIP)[0]);
                         }
+                        //TODO : change the Endpoint refrence addess as well.
                     }
                 }
             }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java?view=diff&rev=552837&r1=552836&r2=552837
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPWorker.java
Tue Jul  3 06:30:32 2007
@@ -313,34 +313,20 @@
 
         HashMap services = configurationContext.getAxisConfiguration().getServices();
         AxisService service = (AxisService) services.get(serviceName);
-        //TODO : Amila pls fix this correctly
-        if (service != null) {
 
-            InputStream instream = service.getClassLoader()
-                    .getResourceAsStream(DeploymentConstants.META_INF + "/" + wsdlName);
+        if (service != null) {
+            response.setStatus(HttpStatus.SC_OK);
+            response.setContentType("text/xml");
+            service.printUserWSDL(response.getOutputStream(), wsdlName);
+            response.getOutputStream().flush();
+            return true;
 
-            if (instream != null) {
-                response.setStatus(HttpStatus.SC_OK);
-                response.setContentType("text/xml");
-                OutputStream outstream = response.getOutputStream();
-                boolean checkLength = true;
-                int length = Integer.MAX_VALUE;
-                int nextValue = instream.read();
-                if (checkLength) length--;
-                while (-1 != nextValue && length >= 0) {
-                    outstream.write(nextValue);
-                    nextValue = instream.read();
-                    if (checkLength) length--;
-                }
-                outstream.flush();
-                return true;
-            } else {
-                // no schema available by that name  - send 404
-                response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!");
-                return true;
-            }
+        } else {
+            // no schema available by that name  - send 404
+            response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!");
+            return true;
         }
-        return false;
+
     }
 
     public String getHostAddress(AxisHttpRequest request) throws java.net.SocketException
{

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java?view=diff&rev=552837&r1=552836&r2=552837
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ListingAgent.java
Tue Jul  3 06:30:32 2007
@@ -234,17 +234,12 @@
                     res.setContentType("text/xml");
                     String ip = extractHostAndPort(filePart, isHttp);
                     String wsdlName = req.getParameter("wsdl");
-                    //TODO , Amila pls fix this in right way
+
                     if (!"".equals(wsdlName)) {
-                        InputStream in = ((AxisService) serviceObj).getClassLoader()
-                                .getResourceAsStream(DeploymentConstants.META_INF + "/" +
wsdlName);
-                        if (in != null) {
-                            out.write(IOUtils.getStreamAsByteArray(in));
-                            out.flush();
-                            out.close();
-                        } else {
-                            res.sendError(HttpServletResponse.SC_NOT_FOUND);
-                        }
+                        AxisService axisServce = (AxisService) serviceObj;
+                        axisServce.printUserWSDL(out, wsdlName);
+                        out.flush();
+                        out.close();
                     } else {
                         ((AxisService) serviceObj).printWSDL(out, ip);
                         out.flush();



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


Mime
View raw message