Question

Im using camel proxy to call an endpoint in camel say direct:say.

public interface xyz{ 
public void sayhello(String body,??????); 
} 

??? i want to set headers or send headers can any one help with an example in binding interface. Thanks Saitsh

No correct solution

OTHER TIPS

You should have a look at http://camel.apache.org/parameter-binding-annotations.html. One nifty example:

 public void sayhello(@Header("user") String user, @Body String body, Exchange exchange) {
     exchange.getIn().setBody(body + "MyBean");
 }

Beside that following annotations are available:

  • @Headers to bind to the Map of the inbound message headers
  • @OutHeaders to bind to the Map of the outbound message headers

Very quick leads...

look at http://camel.apache.org/bean and http://camel.apache.org/bean-binding.html

JndiContext context = new JndiContext();
context.bind("xyz", new XyzImp());

CamelContext camelContext = new DefaultCamelContext(context);

then you can call

to("bean:xyz?method=sayhello(${body}, ${headers})")

or you can add annotation to you interface

sayhello(@Body String body,@Headers Map headers); 

and then

to("bean:xyz?method=sayhello(*, *)")

or

to("bean:xyz?method=sayhello")

should be enough...

The BIG question is, how do you instantiate your xyz interface? Is it singleton or you need a fresh instance for each message or one per thread? But that would be different question :)

Camel 2.16+

Use native proxy parameter binding as described here: http://camel.apache.org/using-camelproxy.html ("What is send on the Message" section).

Previous versions

There no standard way of parameter binding for Camel route proxy. Only one String argument can be bound to exchange body.
But you can create custom implementation of InvocationHandler which will extend Camel core AbstractCamelInvocationHandler class and provide desired parameter binding by overriding of invokeWithbody(...) method.

Check Camel ProxyUtil.createProxyObject(...) method to understand how proxy object is initiated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top