11
votes

I created a web service using:

  • Apache Axis 2 CodeGen Wizard v.1.6.2 (Binding: ADB)
  • Eclipse Juno
  • Tomcat 7
  • Java 6

The Service returns a Custom Java Object (DataBean) back to the client, but I stumbled upon an exception in the client code:

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {schemaTargetNs}message

From what I have researched, over n over again ... I think this is a very common problem but haven't yet got a conclusive answer as to what should be done to rectify it.

Some posts on this and other forums state that the WSDL needs to be modified (some name space), or the client stub needs modification. Some even state that there is a bug in the ADB. It was surely a bug in earlier versions of Axis but there are many posts in the mail-archives stating that the bug was fixed. Those mailing-archives were related to earlier versions of Axis2.

Now my questions are:

  1. Is it still a bug ?
  2. What exactly needs to be changed in the WSDL or the Client stub ?

What is worth mentioning is that I created a similar web service which returns a "String" back to the client. It works fine ! So, it fails when a complex data type is involved.

There was some information on Apache's website, under the heading "Known Limitations"...

It reads: "ADB is meant to be a 'Simple' databinding framework and was not meant to compile all types of schemas. The following limitations are the most highlighted.

  1. Complex Type Extensions and Restrictions."

Is that the problem ?

The following is the snippet from the WSDL file which might be of some interest to you...

<wsdl:types>
        <xs:schema xmlns:ax26="http://mywebservice/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="schemaTargetNs">
            <xs:import namespace="http://mywebservice/xsd"/>
            <xs:element name="getMsg">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="reqData" nillable="true" type="ax25:DataBean"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="getMsgResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" nillable="true" type="ax25:DataBean"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://mywebservice/xsd">
            <xs:complexType name="DataBean">
                <xs:sequence>
                    <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>

Now how do I fix the problem ? Should I include some other code snippets here?

8

8 Answers

13
votes

"Unexpected subelement" means the message received by the receiver contained an XML element that the receiver wasn't expecting. "{schemaTargetNs}message" is the name of the unexpected element that it encountered. In other words, the sender sent an invalid message to the receiver.

  • The sender may have included an element which it wasn't supposed to.
  • The sender may have left out a mandatory element.
  • The sender may have put the elements in the wrong order.
  • The sender may have sent a completely incorrect message.

If the server issued the exception that you reported, then the client sent an invalid message to the server. If the client issued the exception, then the error was in the response from the server to the client.

7
votes

if the xsd(wsdl) is correct with xml request o response is because the problem is the order of xml elements. One posible solution is generate your axis2 client with -Eosv option. that work for me.

1
votes

Look into your .xsd file. Sort your xs elements alphabetically below your <xs:extension base=...>. That will fit your needs.

1
votes

The code generated by CodeGen (from WSDL) for the Java Object (bean) that I was using, expected a different namespace for the fields in the bean. Somehow an incorrect namespace was present in the code generated by Axis. I fixed the namespace to reflect what it should have been and everything worked fine. I can see people still answering this question so thought I would re-post my solution here (have already posted this in response to Kenster's solution). As none of the solutions posted before me finding the solution worked, I did not accept any answer.

0
votes

When I checked the axis code, i found the following

if( new javax.xml.namespace.QName("http://someurl","someElementName").equals(reader.getName()) )

this is where error happens, . equals() method of QName checks for localPart & namespaceURI . but reader.getName() has no namespace URI set and hence the error happend

I changed all the if-check from

if( new javax.xml.namespace.QName("http://someurl","someElementName").equals(reader.getName()) )

to

if( new javax.xml.namespace.QName("someElementName").equals(reader.getName()) )

and it worked fine for me

0
votes

This error can be kind of misleading. After I modified the WSDL and added a new mandatory element, I created my client. Than this error appeared. The solution was, that I forgot to fill this element in one method of the my web service. If this error appears, also check if your mandatory elements are filled within the server.

0
votes

in my case the Web Service is sending elements in different order than the sequence that is on the xsd. I am modifying the stub right now so order does not matter, because I have no chance of altering the Web Service.

0
votes

I had the same problem. When the base64binary overcame 16k limit the parser starts giving the error, Substantially it stops reading the content after 16k so obviously the rest of the document seems corrupted.

My problem was that i was using com.sun.xml.stream.XMLReaderImpl.

Removing

<dependency>
<groupId>com.sun.xml.stream</groupId>
<artifactId>sjsxp</artifactId>
</dependency>

and adding

<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
</dependency>

solved my problem (so wstx as suggested before was working)