You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by fradj zayen <za...@gmail.com> on 2012/06/12 11:33:31 UTC
add interceptor to a camel context
Hi all,
I'd like to add interceptors to camel context programatically. below some
code snippet
Camel Context definition:
CamelContext camelContext=new DefaultCamelContext();
RouteDefinition routeDefinition=new RouteDefinition();
routeDefinition.from("direct:a").to("direct:b").to("direct:c");
camelContext.getRouteDefinitions().add(routeDefinition);
camelContext.setTracing(true);
camelContext.start();
Interceptor to be used:
InterceptSendToEndpointDefinition interceptor=new
InterceptSendToEndpointDefinition( "direct:b");
interceptor.process(new Processor()
{
public void process(Exchange exchange) throws Exception
{
System.out.println(exchange);
}
});
interceptor.to("log:intercepted ${body}");
interceptor.end();
I used the following configuration to add the interceptor to the camel
context, but the interceptor is not fired when an exchange is sent to the
intercepted endpoint
((ModelCamelContext)
camelContext).getRouteDefinitions()..get(0).getOutputs().add( interceptor);
Can someone help on this?
thanks for your help
Re: add interceptor to a camel context
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
You need to add the interceptors to the RoutesDefinition
On Tue, Jun 12, 2012 at 11:33 AM, fradj zayen <za...@gmail.com> wrote:
> Hi all,
> I'd like to add interceptors to camel context programatically. below some
> code snippet
>
> Camel Context definition:
>
> CamelContext camelContext=new DefaultCamelContext();
> RouteDefinition routeDefinition=new RouteDefinition();
> routeDefinition.from("direct:a").to("direct:b").to("direct:c");
> camelContext.getRouteDefinitions().add(routeDefinition);
> camelContext.setTracing(true);
> camelContext.start();
>
>
> Interceptor to be used:
>
> InterceptSendToEndpointDefinition interceptor=new
> InterceptSendToEndpointDefinition( "direct:b");
> interceptor.process(new Processor()
> {
>
> public void process(Exchange exchange) throws Exception
> {
> System.out.println(exchange);
>
> }
> });
> interceptor.to("log:intercepted ${body}");
>
> interceptor.end();
>
> I used the following configuration to add the interceptor to the camel
> context, but the interceptor is not fired when an exchange is sent to the
> intercepted endpoint
> ((ModelCamelContext)
> camelContext).getRouteDefinitions()..get(0).getOutputs().add( interceptor);
>
>
> Can someone help on this?
> thanks for your help
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen