axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabi Julien <gabi.jul...@gmail.com>
Subject wsdl2java generated code failed to parse a response because of a namespaceURI mismatch
Date Thu, 07 Jan 2010 18:45:30 GMT
Hello everyone,

I posted this message on the axis-user mailing list yesterday but maybe it
is better suited here:

I have a encountered problem for which I would need some help. The code
generated for a wsdl we wrote works correctly up to the point were the
server's response needs to be parsed. At this point, the element name
"criteria" cannot be properly parsed by xmlbeans apparently because of a
missing namespaceURI. In other words, the xml element named "criteria" is
found but since the namespaceURI is different, xmlbeans ignores it. I am
using Axis2 1.5.1 and I made sure the server side works as expected by
testing it with php's equivalent of axis2 (although it is a lot more basic).

Here is the wsdl:

========
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="
http://www.broadsign.com/wsdl_ops" xmlns:bstypes="
http://www.broadsign.com/wsdl_types" xmlns:tns="
http://www.broadsign.com/wsdl_ops" xmlns:soap="
http://schemas.xmlsoap.org/wsdl/soap/" >
    <types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="
http://www.broadsign.com/wsdl_ops" xmlns:bstypes="
http://www.broadsign.com/wsdl_types" xmlns:tns="
http://www.broadsign.com/wsdl_ops" >
            <import namespace="http://www.broadsign.com/wsdl_types"
schemaLocation="types.xsd" />
            <complexType mixed="true" name="request_header" >
                <complexContent>
                    <extension base="bstypes:request_base_type" >
                        <attribute use="required" type="unsignedInt"
name="version" fixed="4" />
                        <attribute use="required" type="string" name="name"
fixed="criteria_mgr_list_many" />
                    </extension>
                </complexContent>
            </complexType>
            <complexType mixed="true" name="request_body" >
                <complexContent>
                    <extension base="bstypes:mixed_complex_type" >
                        <attribute use="required" type="string" name="ids"
/>
                        <attribute use="optional" default="null"
type="bstypes:ResourceId" name="domain_id" />
                    </extension>
                </complexContent>
            </complexType>
            <complexType mixed="true" name="response_body" >
                <complexContent>
                    <extension base="bstypes:mixed_complex_type" >
                        <attribute use="required" type="bstypes:ResourceId"
name="id" />
                        <attribute use="required" type="string" name="name"
/>
                        <attribute use="required" type="boolean"
name="active" />
                        <attribute use="required" type="bstypes:ResourceId"
name="container_id" />
                        <attribute use="required" type="bstypes:ResourceId"
name="domain_id" />
                    </extension>
                </complexContent>
            </complexType>
            <complexType mixed="true" name="wsdl_request" >
                <complexContent>
                    <extension base="tns:request_header" >
                        <sequence>
                            <element minOccurs="1" maxOccurs="1"
type="tns:request_body" name="criteria" nillable="true" required="1" />
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>
            <complexType mixed="true" name="wsdl_response" >
                <complexContent>
                    <extension base="bstypes:response_type" >
                        <sequence>
                            <element minOccurs="0" maxOccurs="unbounded"
type="tns:response_body" name="criteria" nillable="true" required="0" />
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>
            <element type="tns:wsdl_request" name="request" nillable="true"
/>
            <element type="tns:wsdl_response" name="response"
nillable="true" />
            <element type="string" name="error" nillable="false" />
        </schema>
    </types>
    <message name="criteria_mgr_list_many_v4_request" >
        <part element="tns:request" name="request" />
    </message>
    <message name="criteria_mgr_list_many_v4_response" >
        <part element="tns:response" name="response" />
    </message>
    <message name="criteria_mgr_list_many_v4_error" >
        <part element="tns:error" name="error" />
    </message>
    <portType name="bsapi_port" >
        <operation name="criteria_mgr_list_many_v4" >
            <input message="tns:criteria_mgr_list_many_v4_request" />
            <output message="tns:criteria_mgr_list_many_v4_response" />
            <fault message="tns:criteria_mgr_list_many_v4_error"
name="error" />
        </operation>
    </portType>
    <binding type="tns:bsapi_port" name="bsapi_binding" >
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
        <operation name="criteria_mgr_list_many_v4" >
            <soap:operation soapAction="
http://www.broadsign.com/criteria_mgr_list_many_v4" style="document" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="error" >
                <soap:body use="literal" />
            </fault>
        </operation>
    </binding>
    <service name="bsapi" >
        <port binding="tns:bsapi_binding" name="bsapi_port" >
            <soap:address location="
https://server-test000.broadsign.com:10803" />
        </port>
    </service>
</definitions>
========

I generated the wsdl using this command: wsdl2java -o gabi_stubs -s -d
xmlbeans -uri criteria_mgr_list_many_v4.wsdl. Here is my code snippet in
main.java:

========
    private static void listCriteria() {
        try {
            RequestBody body = RequestBody.Factory.newInstance();
            WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
            RequestDocument requestDocument =
RequestDocument.Factory.newInstance();
            ResponseBody response;

            body.setIds("12187");
            body.setDomainId("12077");
            wsdlRequest.setName("criteria_mgr_list_many");
            wsdlRequest.setVersion(4);
            wsdlRequest.setCriteria(body);

            requestDocument.setRequest(wsdlRequest);
            requestDocument.documentProperties().setEncoding("utf-16");
            System.out.println(requestDocument.xmlText());

            try {
                ResponseDocument responseDocument;

                responseDocument =
m_stub.criteria_mgr_list_many_v4(requestDocument);
                System.out.println(responseDocument.xmlText());
                // The following line is always 0 even though the response
xml is correct.
                // Internally, the xml parsing fails because a QName is
missing its namespaceURI.

System.out.println(responseDocument.getResponse().sizeOfCriteriaArray());
            } catch (java.rmi.RemoteException e) {
                System.out.println("Got an unkown error while executing the
operation:" + e.toString());
            } catch (Criteria_mgr_list_many_v4_error e) {
                System.out.println("Failed to list criteria: " +
e.getFaultMessage().getError());
            }
        } catch (java.lang.Exception e) {
            System.out.println("Error:" + e.toString());
        }
    }
=======

Now here is the output I get:

=======
<wsdl:request name="criteria_mgr_list_many" version="4" xmlns:wsdl="
http://www.broadsign.com/wsdl_ops"><criteria ids="12187"
domain_id="12077"/></wsdl:request>
<response status="complete" version="4" resource_type="criteria" ns="user"
op_type="list_many" requestid="0" name="criteria_mgr_list_many" xmlns="
http://www.broadsign.com/wsdl_ops" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/">
 <criteria active="1" container_id="12186" id="12187" name="Matin"
domain_id="12077"/>

</response>
0
=======

The last '0' indicates that the <criteria> element was not parsed properly.
However, if I hack the code generated by wsdl2java in WsdlResponseImpl by
changing this line:

=======
    private static final javax.xml.namespace.QName CRITERIA$0 =
        new javax.xml.namespace.QName("", "criteria");
=======

by adding the proper namespaceURI like this:

=======
    private static final javax.xml.namespace.QName CRITERIA$0 =
        new javax.xml.namespace.QName("http://www.broadsign.com/wsdl_ops",
"criteria");
=======

Then sizeOfCriteriaArray() will return 1 as expected. The actual line of
code where it fails can be tracked to Locale.class line 2403:

=======
        Xobj fetch(Xobj parent, QName name, QNameSet set, int n)
        {
 [...]

                loop:
                for (Xobj x = parent._firstChild;
                     x != null; x = x._nextSibling)
                {
                    if (x.isElem() && nameHit(name, set, x._name)) // <---
right here!
                    {
[....]

Now please tell me what I have done wrong? If more information is needed, I
will gladly provide it.

Thank you,
Gabi

Mime
View raw message