You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ndsurendra <nd...@gmail.com> on 2016/05/24 09:17:37 UTC

ProducerTemplate not able to unmarshal response to Java object.

I used the ProducerTemplate to send a http request and get the response like
this.

Contact contact = producerTemplate.requestBodyAndHeaders(
                                "http://localhost:8080/api/contact/2345",
                                null, headers, Contact.class);

logger.info("Contact is: " + new
ObjectMapper().writeValueAsString(contact));

I get the contact as null.


When I try to get it as Object like this:

Object contact = producerTemplate.requestBodyAndHeaders(
                                "http://localhost:8080/api/contact/2345",
                                null, headers);


logger.info("Contact is: " + new
ObjectMapper().writeValueAsString(contact));

com.fasterxml.jackson.databind.JsonMappingException: No serializer found for
class
org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream and
no properties discovered to create BeanSerializer (to avoid exception,
disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )


Why is ProducerTemplate not able to unmarshall the response to the specified
object?
How can this be achieved?

Thanks,
Surendra.



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-not-able-to-unmarshal-response-to-Java-object-tp5783011.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate not able to unmarshal response to Java object.

Posted by ndsurendra <nd...@gmail.com>.
Hi Sashika,

I am producing the request to an existing rest service (Contact service in
this case) and the service is returning the response as well.

The only problem is, I am not able to unmarshal/deserialize the response
into a Java object.
The response is of type
org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream

I was wondering if there is anyway the ProducerTemplate handles this data
format conversions automatically.

Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-not-able-to-unmarshal-response-to-Java-object-tp5783011p5783025.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate not able to unmarshal response to Java object.

Posted by Sashika <sa...@gmail.com>.
Producer template can produce to camel end points. Setup a camel route with http
component and configure the given url in it. Now produce to that endpoint and
convert the response to the required object type. Hope this helps





On Tue, May 24, 2016 2:47 PM, ndsurendra ndsurendra@gmail.com wrote:
I used the ProducerTemplate to send a http request and get the response like

this.




Contact contact = producerTemplate.requestBodyAndHeaders(

"http://localhost:8080/api/contact/2345",

null, headers, Contact.class);




logger.info("Contact is: " + new

ObjectMapper().writeValueAsString(contact));




I get the contact as null.







When I try to get it as Object like this:




Object contact = producerTemplate.requestBodyAndHeaders(

"http://localhost:8080/api/contact/2345",

null, headers);







logger.info("Contact is: " + new

ObjectMapper().writeValueAsString(contact));




com.fasterxml.jackson.databind.JsonMappingException: No serializer found for

class

org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream and

no properties discovered to create BeanSerializer (to avoid exception,

disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )







Why is ProducerTemplate not able to unmarshall the response to the specified

object?

How can this be achieved?




Thanks,

Surendra.










--

View this message in context:
http://camel.465427.n5.nabble.com/ProducerTemplate-not-able-to-unmarshal-response-to-Java-object-tp5783011.html

Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate not able to unmarshal response to Java object.

Posted by souciance <so...@gmail.com>.
Do you actually get a response here?
Contact contact = producerTemplate.requestBodyAndHeaders(
                                "http://localhost:8080/api/contact/2345",
                                null, headers, Contact.class);

Check if contact is not null before you try to unmarshal.

On Tue, May 24, 2016 at 11:17 AM, ndsurendra [via Camel] <
ml-node+s465427n5783011h4@n5.nabble.com> wrote:

> I used the ProducerTemplate to send a http request and get the response
> like this.
>
> Contact contact = producerTemplate.requestBodyAndHeaders(
>                                 "http://localhost:8080/api/contact/2345",
>                                 null, headers, Contact.class);
>
> logger.info("Contact is: " + new
> ObjectMapper().writeValueAsString(contact));
>
> I get the contact as null.
>
>
> When I try to get it as Object like this:
>
> Object contact = producerTemplate.requestBodyAndHeaders(
>                                 "http://localhost:8080/api/contact/2345",
>                                 null, headers);
>
>
> logger.info("Contact is: " + new
> ObjectMapper().writeValueAsString(contact));
>
> com.fasterxml.jackson.databind.JsonMappingException: No serializer found
> for class
> org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream and
> no properties discovered to create BeanSerializer (to avoid exception,
> disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )
>
>
> Why is ProducerTemplate not able to unmarshall the response to the
> specified object?
> How can this be achieved?
>
> Thanks,
> Surendra.
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/ProducerTemplate-not-able-to-unmarshal-response-to-Java-object-tp5783011.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-not-able-to-unmarshal-response-to-Java-object-tp5783011p5783026.html
Sent from the Camel - Users mailing list archive at Nabble.com.