bulldog2011/nano

Nano does not handle WSDL attribute elementFormDefault="qualified"

tomaszgrygo opened this issue · 10 comments

Nano does not handle WSDL attribute elementFormDefault="qualified" and generates namespaces in requests incorrectly.

Hi,

Thx for posting issue about nano!

Can you give more details about the issue, or could you give a sample? so I may better understand the issue and may fix it if possbile.

Thx!
-William

Here is a fragment of the WSDL (is it possible to attach the whole file?)

<wsdl:definitions
name="secws"
targetNamespace="secws"
xmlns="secws"
xmlns:impl="secws/schema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="secws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">verid/wsdl:documentation
wsdl:types
<xsd:schema targetNamespace="secws/schema" xmlns="secws/schema">
...
<xsd:element name="SecInitSessionRequestData">
xsd:complexType
xsd:sequence
<xsd:element name="PCName" type="xsd:string"/>
<xsd:element name="ProductName" type="xsd:string"/>


<xsd:any processContents="skip" minOccurs="0" maxOccurs="unbounded" />
/xsd:sequence
/xsd:complexType
/xsd:element
<xsd:element name="SecInitSessionResponseData">
xsd:complexType
xsd:sequence
<xsd:element name="SessionInfo" type="impl:SecSession"/>
<xsd:element name="Domains" type="impl:ArrayOfDomains"/>
<xsd:element name="Sites" type="impl:ArrayOfSites"/>
<xsd:any processContents="skip" minOccurs="0" maxOccurs="unbounded" />
/xsd:sequence
/xsd:complexType
/xsd:element
...

<wsdl:message name="SecInitSessionRequest">
<wsdl:part element="impl:SecInitSessionRequestData" name="request"/>
/wsdl:message
<wsdl:message name="SecInitSessionResponse">
<wsdl:part element="impl:SecInitSessionResponseData" name="response"/>
/wsdl:message

After generating stubs and running NANO webservice following request is generated:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="secws/schema">
soapenv:Header/
soapenv:Body

DV13
SOFTLAB

/soapenv:Body
/soapenv:Envelope

NANO assigns default namespace "secws/schema" and it gets applied to elements that are defined as having no namespace. Namespace defined attribute targetNamspace is applied to sub-elements only if elementFormDefault="qualified". And this is not true here since by default elementFormDefault="unqualified".
Request should look like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="secws/schema">
soapenv:Header/
soapenv:Body
sch:SecInitSessionRequestData
asd
asd
/sch:SecInitSessionRequestData
/soapenv:Body
/soapenv:Envelope

Hi,

Thx for your suggestion, could you help to send the sample wsdl to my mail box at :
51startup@sina.com

Thx!
-William

WSDL sent

Thx, I am working on adding a flag on the nano client, so elementFormDefault and the serialization behaviour can be configured, will let you know when it's done

Hi Tomas:

I understand your problem, and I have tried to support the feature proposed by you, however, current Nano does not support namespace at element level, elements will only inherit namespace from their parent elements. In other word, Nano only supports single target namespace.

Nano is only a light weight library targeting Android platorm, considering the complexity introduced, it will not support the feature(or fix) proposed by you in short term.

You have 2 options:

  1. Consolidate the namespace in your schema into a single target namespace.
  2. Do some hacking to the Nano source, the related class is XmlPullWriter.java and SOAPWriter.java, the serialization logic is not complicated, although this is just a workaround, it may work.

Thx!
-William

Hi William,
I already did the change that solves this problem for me. Please look at it and see if you can use it.
I file SOADWriter.java I changed this fragment

        if (!StringUtil.isEmpty(innerNamespace)) {
            if (serializer.getPrefix(innerNamespace, false) == null) {
                serializer.setPrefix("", innerNamespace);
                            }
                    }

into this

        if (!StringUtil.isEmpty(innerNamespace)) {
            if (serializer.getPrefix(innerNamespace, false) == null) {
                serializer.setPrefix(XmlPullWriter.elementFormDefault_qualified?"":INNER_PREFIX, innerNamespace);
                           }
                    }

where XmlPullWriter.elementFormDefault_qualified is a variable storing value for WSDL attribute that I set before calling NANO, and INNER_PREFIX is constant:
static final String INNER_PREFIX = "inner";
.
Hope this help
Tomasz

Hi Tomasz:

Look like you've done a smart fix, what does the xml message look like after you made the fix?

some thing like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inner="secws/schema"> <soapenv:Header/> <soapenv:Body> <inner:SecInitSessionRequestData> <PCName>asd</PCName> <ProductName>asd</ProductName> </inner:SecInitSessionRequestData> </soapenv:Body> </soapenv:Envelope>

or this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inner="secws/schema"> <soapenv:Header/> <soapenv:Body> <inner:SecInitSessionRequestData> <inner:PCName>asd</inner:PCName> <inner:ProductName>asd</inner:ProductName> </inner:SecInitSessionRequestData> </soapenv:Body> </soapenv:Envelope>

?

It looks like your first example

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:inner="secws/schema">
  <soapenv:Body>
    <inner:SecInitSessionRequestData>
      <PCName>asd</PCName>
      <ProductName>asd</ProductName>
    </inner:SecInitSessionRequestData>
  </soapenv:Body>
</soapenv:Envelope>

Looks like you just used a workaround, let's keep this issue open until we can find a generic way to fix this issue.

Thx!
-William