You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by ilab <il...@freemail.hu> on 2011/10/07 22:31:03 UTC

Bad parser code is generated from wsdl in certain cases

Hello,
I don't know whether someone has a workaround for the following problem, 
without modifying the wsdl, which is unfortunately not an option.
Thanks,
ilab
----
For the wsdl example you can find below, axis2 v1.6.1 (v.1.5.1 and 
possibly older versions also) generates bad parse code as the resulted 
service doesn't accept a valid message (also see below).

If you send the message with empty Data1 tag, it is parsed successfully. 
With content, which is also valid, the parser results 
"org.apache.axis2.databinding.ADBException: Unexpected subelement Data1".

The actual problem is that the generated parse code does not deal with 
the content of Data1 tag, therefore, if it is not empty, after parsing 
Data1, the parse pointer will be at the end element of Data1, instead of 
being after it. I have also copy-pasted the buggy code below, 
ElementType$Factory.parse().


Rejected message
==============

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:test="http://test <http://test/>">
<soapenv:Header/>
<soapenv:Body>
<test:QueryTestEBM>
<test:Data1>x</test:Data1>
<test:Data2></test:Data2>
</test:QueryTestEBM>
</soapenv:Body>
</soapenv:Envelope>

Accepted message
==============
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:test="http://test <http://test/>">
<soapenv:Header/>
<soapenv:Body>
<test:QueryTestEBM>
<test:Data1></test:Data1>
<test:Data2></test:Data2>
</test:QueryTestEBM>
</soapenv:Body>
</soapenv:Envelope>

WSDL example
============

<?xml version="1.0" encoding="UTF-8"?>

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://test <http://test/>"
xmlns:ns="http://test <http://test/>">

<types>
<xsd:schema targetNamespace="http://test <http://test/>" 
elementFormDefault="qualified">

<xsd:complexType name="CodeType">
<xsd:simpleContent>
<xsd:extension base="xsd:normalizedString"/>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="ElementType">
<xsd:simpleContent>
<xsd:extension base="ns:CodeType"/>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="QueryTestEBMType">
<xsd:sequence>
<xsd:element name="Data1" type="ns:ElementType" maxOccurs="1"/>
<xsd:element name="Data2" type="ns:ElementType" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="QueryTestEBM" type="ns:QueryTestEBMType"/>
</xsd:schema>
</types>

<message name="QueryTestReqMsg">
<part name="QueryTestEBM" element="ns:QueryTestEBM"/>
</message>

<message name="QueryTestRespMsg">
</message>

<portType name="TestBindingPort">
<operation name="QueryTest">
<input message="ns:QueryTestReqMsg"/>
<output message="ns:QueryTestRespMsg"/>
</operation>
</portType>

<binding name="TestBinding" type="ns:TestBindingPort">
<soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="QueryTest">
<soap:operation soapAction="QueryTest" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>

<service name="TestService">
<port name="TestService" binding="ns:TestBinding">
<soap:address
location="http://localhost:8080/WebServiceTest2/services/TestService" />
</port>
</service>

</definitions>

Buggy code: ElementType$Factory.parse()
===============================

         public static ElementType 
parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
             ElementType object =
                 new ElementType();

             int event;
             java.lang.String nillableValue = null;
             java.lang.String prefix ="";
             java.lang.String namespaceuri ="";
             try {

                 while (!reader.isStartElement() && !reader.isEndElement())
                     reader.next();


                 if 
(reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance","type")!=null){ 

                   java.lang.String fullTypeName = 
reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
                         "type");
                   if (fullTypeName!=null){
                     java.lang.String nsPrefix = null;
                     if (fullTypeName.indexOf(":") > -1){
                         nsPrefix = 
fullTypeName.substring(0,fullTypeName.indexOf(":"));
                     }
                     nsPrefix = nsPrefix==null?"":nsPrefix;

                     java.lang.String type = 
fullTypeName.substring(fullTypeName.indexOf(":")+1);

                             if (!"ElementType".equals(type)){
                                 //find namespace for the prefix
                                 java.lang.String nsUri = 
reader.getNamespaceContext().getNamespaceURI(nsPrefix);
                                 return 
(ElementType)test.ExtensionMapper.getTypeObject(
                                      nsUri,type,reader);
                               }


                   }


                 }




                 // Note all attributes that were handled. Used to 
differ normal attributes
                 // from anyAttributes.
                 java.util.Vector handledAttributes = new 
java.util.Vector();




                     reader.next();




             } catch (javax.xml.stream.XMLStreamException e) {
                 throw new java.lang.Exception(e);
             }

             return object;
         }

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