You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by sireesh <ki...@gmail.com> on 2012/09/07 14:10:35 UTC
Unable to unmarshal REST response into POJO
Hi,
I've created a webclient and posted a POJO to remote REST service.
I was expecting the response to be unmarshalled as POJO of type .
My code:
WebClient authenticationClient = WebClient.create(AUTH_URL);
AuthenticationResponse authenticationResponse =
authenticationClient.post(authenticationRequest,AuthenticationResponse.class);
I've checked that I'm getting response by putting an interceptor.
The response xml contains lot of elements in it. I'm interested in mapping
few properties into my POJO.
Hence my POJO doesn't contain getters/setters for all the elements in the
response xml. Is this a problem?
I've put debug points for the existing POJO constructor and setters.
JAXBProvider is invoking these, but all are being set as null.
So, after the above call I'm getting authenticationResponse object created
but with all properties as null.
There is no exception being thrown.
Can someone please help, how I can unmarshal properly.
Thanks,
Kiran Sireesh
--
View this message in context: http://cxf.547215.n5.nabble.com/Unable-to-unmarshal-REST-response-into-POJO-tp5713694.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Unable to unmarshal REST response into POJO
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 10/09/12 15:06, sireesh wrote:
> Hi Sergey,
>
> The interceptor I've added earlier to check that the response is being
> received is reading from the stream and hence the JAXB unmarshaller is
> throwing EOF exception.
> I removed the interceptor and then the JAXB is throwing exception indicating
> that my POJOs don't have setters for the xml elements.
>
> I tried unmarshalling the xml in a test class using a custom
> javax.xml.bind.ValidationEventHandler, where I'm ignoring all the
> "unexpected element" found exceptions.
>
> I don't know how I can plug in my custom validation event handler while
> unmarshalling an xml using CXF APIs
>
> WebClient authenticationClient = WebClient.create(AUTH_URL);
> AuthenticationResponse authenticationResponse =
> authenticationClient.post(authenticationRequest,AuthenticationResponse.class);
>
> Can you please let me know, how I can use the custom validation handler.
>
JAXBElementProvider has a 'validationEventHandler' property, set that
and then pass a JAXBElementProvider reference to WebClient.create
Cheers, Sergey
> Regards,
> Kiran
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Unable-to-unmarshal-REST-response-into-POJO-tp5713694p5713756.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Unable to unmarshal REST response into POJO
Posted by sireesh <ki...@gmail.com>.
Hi Sergey,
The interceptor I've added earlier to check that the response is being
received is reading from the stream and hence the JAXB unmarshaller is
throwing EOF exception.
I removed the interceptor and then the JAXB is throwing exception indicating
that my POJOs don't have setters for the xml elements.
I tried unmarshalling the xml in a test class using a custom
javax.xml.bind.ValidationEventHandler, where I'm ignoring all the
"unexpected element" found exceptions.
I don't know how I can plug in my custom validation event handler while
unmarshalling an xml using CXF APIs
WebClient authenticationClient = WebClient.create(AUTH_URL);
AuthenticationResponse authenticationResponse =
authenticationClient.post(authenticationRequest,AuthenticationResponse.class);
Can you please let me know, how I can use the custom validation handler.
Regards,
Kiran
--
View this message in context: http://cxf.547215.n5.nabble.com/Unable-to-unmarshal-REST-response-into-POJO-tp5713694p5713756.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Unable to unmarshal REST response into POJO
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 07/09/12 13:57, sireesh wrote:
> Sorry to mention that I was not getting any exception in my earlier post.
> An exception is thrown while JAXBProvider is trying to unmarshal.
>
> Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
> at [row,col {unknown-source}]: [1,0]
> at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
> at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2104)
> at
> com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2010)
> at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1102)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:160)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
> at
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:332)
> at
> org.apache.cxf.jaxrs.provider.JAXBElementProvider.unmarshalFromInputStream(JAXBElementProvider.java:214)
> at
> org.apache.cxf.jaxrs.provider.JAXBElementProvider.doUnmarshal(JAXBElementProvider.java:180)
> at
> org.apache.cxf.jaxrs.provider.JAXBElementProvider.readFrom(JAXBElementProvider.java:149)
>
>
>
> Did anyone hit this problem earlier? If so, can you please post how you got
> through this issue.
Looks like no response payload is coming back.
Can you add a logging feature on the client side ?
Also check custom stream readers if any
Cheers, Sergey
>
> Thanks,
> Kiran Sireesh
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Unable-to-unmarshal-REST-response-into-POJO-tp5713694p5713695.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: Unable to unmarshal REST response into POJO
Posted by sireesh <ki...@gmail.com>.
Sorry to mention that I was not getting any exception in my earlier post.
An exception is thrown while JAXBProvider is trying to unmarshal.
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
at [row,col {unknown-source}]: [1,0]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2104)
at
com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2010)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1102)
at
com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:160)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:332)
at
org.apache.cxf.jaxrs.provider.JAXBElementProvider.unmarshalFromInputStream(JAXBElementProvider.java:214)
at
org.apache.cxf.jaxrs.provider.JAXBElementProvider.doUnmarshal(JAXBElementProvider.java:180)
at
org.apache.cxf.jaxrs.provider.JAXBElementProvider.readFrom(JAXBElementProvider.java:149)
Did anyone hit this problem earlier? If so, can you please post how you got
through this issue.
Thanks,
Kiran Sireesh
--
View this message in context: http://cxf.547215.n5.nabble.com/Unable-to-unmarshal-REST-response-into-POJO-tp5713694p5713695.html
Sent from the cxf-user mailing list archive at Nabble.com.