Hi

There is a @RecipientList annotation you can use in a method in a bean.
And then use a bean in the DSL, eg either .bean / .beanRef / or
.to("bean:xxx") etc.

Your use-case is a bit unusual as you set the body to null, and
therefore accesses the Exchange directly.

And accordingly to the EIPs you would need 2 eips for that
- message translator
- recipient list

So in the end you may need to use 2 eips. But you can give the
@RecipientList a try.


On Mon, Jul 9, 2012 at 9:46 PM, rhowlett <rhowl...@silverchalice.com> wrote:
> I'm using the Java DSL to do something akin to the following:
>
> from("xxx")
>         .setBody("<root><p>Hi</p></root>")
>         .recipientList(method(MyBean.class, "myMethod"))
> .end()
>
> MyBean's myMethod() method is intended to calculate the HTTP endpoint to
> call:
>
> public String myMethod(
>         @Body String body,
>         @Headers Map<String, Object> inHeaders,
>         @OutHeaders Map<String, Object> outHeaders,
>         Exchange exchange
> ) {
>         outHeaders = inHeaders;
>
>         outHeaders.put(Exchange.HTTP_METHOD, "GET");
>         exchange.getIn().setBody(null);
>
>         return "http://somewebservice.com";;
> }
>
> The problem is because the body of the Exchange's In Message going into the
> recipient list method is not null, an InvalidPayloadException is therefore
> thrown.
>
> Setting the body within the method has no effect because it seems the
> component used by the method's return value is passed the pre-recipient list
> method's body.
>
> What I'm doing now is using two methods, one pre-recipientList method to
> calculate/set the headers etc., and the recipientList's method itself just
> returns the HTTP string now.
>
> What better ways are there of doing this? It would be nice to solve it with
> one method. Use the HTTP component class directly?
>
> Thanks, R
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/RecipientList-with-bean-method-to-set-HTTP-endpoint-string-tp5715771.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to