Reputation: 6784
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
Upvotes: 1
Views: 3176
Reputation: 6784
I found the solution myself through intense trial and error. Here is how I got it done.
Running xjc
creates 4 classes namely ObjectFactory.java
, package-info.java
, class representing webservice request and class representing webservice response.
I overlooked to include package-info.java
alongwith 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 by org.springframework.oxm.jaxb.Jaxb2Marshaller
bean defined in spring context file so I know I have to include it. But not including package-info.java
fails silently causing frustration!
I have read in Stackoverflow and elsewhere that for unmarshal() method to accept just one argument- javax.xml.transform.Source
and unmarshal I need to use @XmlRootElement
annotation but that doesn't seem to be applicable to my case.
Upvotes: 1