Monday, February 9, 2009

Axis2 - ADBException: Unexpected subelement

This is another common issue that Apache Axis2 users face.

org.apache.axis2.AxisFault: org.apache.axis2.databinding.
ADBException: Unexpected subelement someElementName

Again the solution to this is simple. This exception could occur when a request is been sent (Before the request is sent) or when a response is arrived (Or alternatively it could occur on the server side when a request is received). Therefore it makes life easy to know where things really went wrong. And again TCPMonitor comes to the rescue. Simply send your request through TCPMonitor. This will help you diagnose whether the exception was thrown when sending the request or receiving the response.

Now lets figure out why this exception could occur. When a stub (or Skeleton) is generated using adb as the data binding framework (If no option (-d) is provided for the databinding framework Axis2 uses adb by default) it performs validation on the request it sends and the response it receives. The validation is performed based on the XML Schema for the request or response message. Hence if a response is to have three elements named a,b,c in a sequence and the response contains somethinglike a,d,c Axis2 would complain saying that it received an Unexpected element named d.

So this issue can be solved easily by comparing the request/response messages against the Schema that defines those messages. This could be tricky sometimes especially if you are not familiar with XML Schema.

This error could occur when there are namespace mismatches as well and spoting these could proove to be tricky as as a user found out over here.

2 comments:

neel said...

What if the schema in the response has a,b and c. But in the response if we are getting a,b,c, and d.

Is there anyway to specify somewhere in wsdl2java utility to not to generate the unwanted element exception block.

Subha said...

Hi Keith,

I'm a new bee to axis2 and JSON. I'm trying create a small mobile enterprise app in blackberry using Tomcat,axis2 and JSON( am following this lab work http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/LAB-Create-a-typical-mobile-enterprise-application-using-the/ta-p/774151 )
Can you please tell me how can I install DynamicResponseHandler module for JSON format response. I tried this link http://dist.wso2.org/maven2/org/wso2/dynamicresponse/wso2dynamic-response/1.5/wso2dynamic-.....
but I couldn't find any *.mar file in here. So I copied the module.xml file and DynamicResponseHandler.class file to Tomcat's web-inf/modules directory. Also I added module ref=DynamicResponseHandler in axis2.xml. Is this right???
When I started Tomcat, I'm getting org.apache.axis2.AxisFault: The system is attempting to engage a module that is not available: DynamicResponseHandler. Not sure how to proceed at this point. Please advice.
Thanks for your help.