bulldog2011 / nano

A light Android web serivce client framework
Apache License 2.0
33 stars 30 forks source link

Nano does not handle WSDL attribute elementFormDefault="qualified" #4

Open tomaszgrygo opened 11 years ago

tomaszgrygo commented 11 years ago

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

bulldog2011 commented 11 years ago

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

tomaszgrygo commented 11 years ago

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

<?xml version="1.0" encoding="UTF-8"?> <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/">

verid/wsdl:documentation wsdl:types ... xsd:complexType xsd:sequence /xsd:sequence /xsd:complexType /xsd:element xsd:complexType xsd:sequence /xsd:sequence /xsd:complexType /xsd:element ... /wsdl:message /wsdl:message After generating stubs and running NANO webservice following request is generated: 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:Header/ soapenv:Body sch:SecInitSessionRequestData asd asd /sch:SecInitSessionRequestData /soapenv:Body /soapenv:Envelope
bulldog2011 commented 11 years ago

Hi,

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

Thx! -William

tomaszgrygo commented 11 years ago

WSDL sent

bulldog2011 commented 11 years ago

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

bulldog2011 commented 11 years ago

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

tomaszgrygo commented 11 years ago

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

bulldog2011 commented 11 years ago

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:

`

asd asd ` or this: ` asd asd ` ?
tomaszgrygo commented 11 years ago

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>
bulldog2011 commented 11 years ago

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