Sunday, May 24, 2009

org.xml.sax.SAXException: Invalid element in

org.xml.sax.SAXException: Invalid element in

Problem :


We come across this common exception when the values in classes generated by the wsdl's are not matching with what the values of web service returns.

Exception I Encountered Was :


#########################################################################################

org.xml.sax.SAXException: Invalid element in org.tempuri.esws.Event -  BMSL_KOL
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:296)
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode: 
faultString: org.xml.sax.SAXException: Invalid element in org.tempuri.esws.Event -  BMSL_KOL
faultActor: 
faultNode: 
faultDetail: 
{http://xml.apache.org/axis/}stackTrace: org.xml.sax.SAXException: Invalid element in org.tempuri.esws.Event -  BMSL_KOL
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.jav a:296)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(Deserializatio nContextImpl.java:845)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:232)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:354 )
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:834)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:526)
at org.apache.axis.client.Call.invoke(Call.java:3856)
at org.apache.axis.client.Call.invoke(Call.java:9238)
at org.apache.axis.client.Call.invoke(Call.java:3245)
at org.tempuri.esws.ServiceSoapStub.fetchEvents(ServiceSoapStub.java:522)
#########################################################################################

Solution :


This exception was caused when the values in classes generated by the wsdl's are not matching with what the values of web service returns. Please look the solution as explained below.



Example :


- Solution 1 : 

WSDL generated file for the WS (Web service) request object, i.e Event, there is an attribute typeDesc and a static body following initialising typeDesc.

For each element added to typeDesc, you will see the following similar code :
elemField.setFieldName("eventFormID");
elemField.setXmlName(new javax.xml.namespace.QName("", "EventFormID"));

make sure the string literals are of the same case, as above they should be "EventFormID"

- Solution 2 :

Say our code is something like this:

elementField = new org.apache.axis.description.ElementDesc();
elementField.setFieldName("bMSL_LOK");
elementField.setXmlName(new javax.xml.namespace.QName("urn:/crmondemand/xml/contact", "bMSL_LOK"));
elementField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
elementField.setMinOccurs(0);
elementField.setNillable(false);
typeDesc.addFieldDesc(elemmentField);

And this is the response coming in:-

<Event object="Contact" name="someName" operation="update">
     <SiebelMessage>
          <ListOfContact xmlns="urn:/crmondemand/xml/contact">
               <Contact>
                    <ContactFirstName>someFirstName</ContactFirstName>
                    <ContactId>someContactId</ContactId>
                    <ContactLastName>someLastName</ContactLastName>
                    <AlternateAddressId>someAddress</AlternateAddressId>
                    <ExternalSystemId/>
                    <IntegrationId>someIntegrationId</IntegrationId>
                    <bMSL_LOK></bMSL_LOK>
                    <ModId>someModId</ModId>
                    <CreatedDate>someCreatedDate</CreatedDate>
                    <ModifiedById>someModifiedById</ModifiedById>
                    <ModifiedDate>someModifiedDate</Mo difiedDate>
                    <CreatedById>someCreatedById</CreatedById>
               </Contact>
          </ListOfContact>
     </SiebelMessage>
</Event>


What really happens in that page is:-
The field name coming in is bMSL_LOK and NOT BMSL_LOK.
Note the case of the first-letter. And what happens next is the word "set" is appended to this and the corresponding setter called ! So when we create setters for bMSL_LOK, this is what we have in the pojo:

public String getBMSL_LOK() {
return bMSL_LOK;
}

public void setBMSL_LOK(String bmsl_lok) {
bMSL_LOK = bmsl_lok;
}
Change this to :-
public String getbMSL_LOK() {
return bMSL_LOK;
}

public void setbMSL_KOL(String bmsl_kol) {
bMSL_KOL = bmsl_kol;
}




Similar Exception :

     

- org.xml.sax.SAXException: Invalid element in



No comments:

Post a Comment