axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Moss ...@rhiandal.com>
Subject RE: Java2WSDL assigns incorrect namespace for the 'anyType' type
Date Wed, 12 May 2004 03:47:21 GMT
I had this exact problem and the patch corrects the WSDL generation but does not 
correct the problem at runtime when an anyType array is involved. Below is an 
excerpt of a response:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
   <ns1:getChildrenResponse 
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:ns1="urn:mine">
    <getChildrenReturn soapenc:arrayType="ns2:anyType[22]" 
xsi:type="soapenc:Array" xmlns:ns2="http://www.w3.org/1999/XMLSchema" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

<!--Remainder omitted.-->

You'll notice that the arrayType is using prefix `ns2'. And also notice that 
`ns2' is defined using the 1999 XMLSchema namespace.

Thanks,
-Alan


-----Original Message-----
From: Ias [mailto:iasandcb@tmax.co.kr]
Sent: Friday, April 23, 2004 4:03 AM
To: axis-dev@ws.apache.org
Subject: RE: Java2WSDL assigns incorrect namespace for the 'anyType' type

 > For an operation having an 'Object' parameter, the WSDL2Java
 > tool generates a WSDL, with an incorrect namespace
 > 'http://www.w3.org/1999/XMLSchema'
 > assigned to the 'anyType' type. I was hoping that the
 > 'http://www.w3.org/2001/XMLSchema' namespace would be used. I
 > used axis-1_2beta. Is it a bug?

Actually there's no standard mapping from java.lang.Object to a XML type and
xsd:anyType to a Java type in JAX-RPC 1.1 spec. On the other hand, the spec
states that xsd:any (wildcard) can be mapped to javax.xml.soap.SOAPElement.
Therefore, mapping between xsd:anyType and java.lang.Object is
Axis-specific. I made a quick patch for correcting the problem.

--------
Index: DefaultTypeMappingImpl.java
===================================================================
RCS file:
/home/cvspublic/ws-axis/java/src/org/apache/axis/encoding/DefaultTypeMapping
Impl.java,v
retrieving revision 1.76
diff -u -r1.76 DefaultTypeMappingImpl.java
--- DefaultTypeMappingImpl.java	25 Feb 2004 14:02:35 -0000	1.76
+++ DefaultTypeMappingImpl.java	23 Apr 2004 07:49:50 -0000
@@ -632,10 +632,23 @@
          try {
              if (xmlType.getNamespaceURI().equals(
                      Constants.URI_DEFAULT_SCHEMA_XSD)) {
-                for (int i=0; i < Constants.URIS_SCHEMA_XSD.length; i++) {
-                    QName qName = new QName(Constants.URIS_SCHEMA_XSD[i],
-                                            xmlType.getLocalPart());
-                    super.internalRegister(javaType, qName, sf, df);
+                if (sf == null) {
+                    // In this case (e.g. java.lang.Object),
+                    // looping over Constants.URIS_SCHEMA_XSD incrementally
+                    // causes mapping of older schema type to javaType
+                    // because super.internalRegister skips class2Pair.put
+                    // when sf == null and javaType is already put in
class2Pair.
+                    for (int i=Constants.URIS_SCHEMA_XSD.length - 1; i >=0
; i--) {
+                        QName qName = new
QName(Constants.URIS_SCHEMA_XSD[i],
+                                                xmlType.getLocalPart());
+                        super.internalRegister(javaType, qName, sf, df);
+                    }
+                } else {
+                    for (int i=0; i < Constants.URIS_SCHEMA_XSD.length;
i++) {
+                        QName qName = new
QName(Constants.URIS_SCHEMA_XSD[i],
+                                xmlType.getLocalPart());
+                        super.internalRegister(javaType, qName, sf, df);
+                    }
                  }
              }
              else if (xmlType.getNamespaceURI().equals(
--------
I tested your case with the above change and got a right WSDL. Before I
commit this patch, I hope to hear opinions and comments.

Thanks,

Ias


 >
 >
 > The following are the Java class and the generated WSDL:
 >
 > Java class
 > ======
 > package example;
 > public interface Test {
 >     public String helloWorld(Object objectParamter); }
 >
 > Command-line to generate "test.wsdl" in the current working
 > directory ===========================================
 > java
 > org.apache.axis.wsdl.Java2WSDL -o"test.wsdl"
 > -l"http://localhost:8080/axis/s ervices/Test" -n"urn:Example"
 > -p"example" "urn:Example" example.Test
 >
 >
 > The generated WSDL
 > ==================================
 > <?xml version="1.0" encoding="UTF-8"?>
 > <wsdl:definitions targetNamespace="urn:Example"
 > xmlns:impl="urn:Example"
 > xmlns:intf="urn:Example"
 > xmlns:apachesoap="http://xml.apache.org/xml-soap"
 > xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
 > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 > xmlns:tns2="http://www.w3.org/1999/XMLSchema"
 > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
 > <!--WSDL created by Apache Axis version: 1.2beta Built on Mar
 > 31, 2004 (12:47:03 EST)-->
 >
 >    <wsdl:message name="helloWorldResponse">
 >
 >       <wsdl:part name="helloWorldReturn" type="xsd:string"/>
 >
 >    </wsdl:message>
 >
 >    <wsdl:message name="helloWorldRequest">
 >
 >       <wsdl:part name="in0" type="tns2:anyType"/>
 >
 >    </wsdl:message>
 >
 >    <wsdl:portType name="Test">
 >
 >       <wsdl:operation name="helloWorld" parameterOrder="in0">
 >
 >          <wsdl:input name="helloWorldRequest"
 > message="impl:helloWorldRequest"/>
 >
 >          <wsdl:output name="helloWorldResponse"
 > message="impl:helloWorldResponse"/>
 >
 >       </wsdl:operation>
 >
 >    </wsdl:portType>
 >
 >    <wsdl:binding name="WidgetPriceSoapBinding" type="impl:Test">
 >
 >       <wsdlsoap:binding style="rpc"
 > transport="http://schemas.xmlsoap.org/soap/http"/>
 >
 >       <wsdl:operation name="helloWorld">
 >
 >          <wsdlsoap:operation soapAction=""/>
 >
 >          <wsdl:input name="helloWorldRequest">
 >
 >             <wsdlsoap:body use="encoded"
 > encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 > namespace="urn:Example"/>
 >
 >          </wsdl:input>
 >
 >          <wsdl:output name="helloWorldResponse">
 >
 >             <wsdlsoap:body use="encoded"
 > encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 > namespace="urn:Example"/>
 >
 >          </wsdl:output>
 >
 >       </wsdl:operation>
 >
 >    </wsdl:binding>
 >
 >    <wsdl:service name="TestService">
 >
 >       <wsdl:port name="WidgetPrice"
 > binding="impl:WidgetPriceSoapBinding">
 >
 >          <wsdlsoap:address
 > location="http://localhost:8080/axis/services/Test"/>
 >
 >       </wsdl:port>
 >
 >    </wsdl:service>
 >
 > </wsdl:definitions>
 >

Mime
View raw message