camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <willem.ji...@gmail.com>
Subject Re: recipientList with POST and request body
Date Thu, 10 Jan 2013 03:33:18 GMT
Oh, you need to start the template before using it to send the request.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Thursday, January 10, 2013 at 4:42 AM, Zemin Hu wrote:

> I tried producerTemplate for bean approach (in groovy) too. I got exception
> when I tried to POST to an HTTP endpoint:
> def template = context.createProducerTemplate()
>  
> def endpointUri = headers.END_POINT
> def xheaders = ["Content-Type":"application/json",
> "CamelHttpMethod":"POST"]
> def xbody ='''{"id":["48792683442"],"index":"0"}'''
>  
> def response = template.requestBodyAndHeaders(endpointUri, xbody, xheaders,
> java.lang.String.class)
> exchange.in.setBody(response)
> the exception is:
>  
> org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message:
> {"id":["48792683442"],"index":"0"}]
> at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1237)[camel-core-2.9.1.jar:2.9.1]
> at
> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:509)[camel-core-2.9.1.jar:2.9.1]
> at
> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)[camel-core-2.9.1.jar:2.9.1]
> at
> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeaders(DefaultProducerTemplate.java:247)[camel-core-2.9.1.jar:2.9.1]
> at
> org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:296)[camel-core-2.9.1.jar:2.9.1]
> at
> org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:292)[camel-core-2.9.1.jar:2.9.1]
> at
> org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:329)[camel-core-2.9.1.jar:2.9.1]
> at org.apache.camel.ProducerTemplate$requestBodyAndHeaders.call(Unknown
> Source)
>  
> I changed to use template.sendBodyAndHeaders(endpointUri, xbody, xheaders)
> in case the result is causing problem, I got same exception.
> Can anybody help to use producerTemplate to POST/PUT/DELETE HTTP request? It
> should not be limited to do only GET, isn't it? no document says anything
> about setting HTTP methods for producerTemplate. It would be tedious to
> write my own httpClient based code.
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/recipientList-with-POST-and-request-body-tp5725142p5725201.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Mime
View raw message