I am sending a request to webservice and am receiving correct response from web service in xml format with the correct value populated in the response element tage. Now I tried to unmarshal but the response object is being populated with null instead of the value I see in XML response.
Any obvious thing to check?
This is my code:
InputSource outputSource = getWebServiceHelper().send(source,messageIdentifier);
JAXBElement<Envelope> responseEnv = (JAXBElement<Envelope>) getWebServiceHelper().unmarshal(new SAXSource(outputSource));
JAXBElement<ResponseObjectType> result = (JAXBElement<ResponseObjectType>)responseEnv.getValue().getBody().getAny().get(0);
The moment second line executes, the response attribute is becoming null. Despite being correct between xml tags!
Thanks a ton.
Chaitanya
I found the solution myself through intense trial and error. Here is how I got it done.
Running
xjccreates 4 classes namelyObjectFactory.java,package-info.java, class representing webservice request and class representing webservice response.I overlooked to include
package-info.javaalongwith other 3 classes. This is the reason jaxb is unable to unmarshal the repsone.If I dont include
ObjectFactory.java, I get exception at server startup thrown byorg.springframework.oxm.jaxb.Jaxb2Marshallerbean defined in spring context file so I know I have to include it. But not includingpackage-info.javafails silently causing frustration!I have read in Stackoverflow and elsewhere that for unmarshal() method to accept just one argument-
javax.xml.transform.Sourceand unmarshal I need to use@XmlRootElementannotation but that doesn’t seem to be applicable to my case.