You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Łukasz Dywicki <lu...@code-house.org> on 2012/08/17 22:17:36 UTC
Intercept processor/bean
Hey all,
Is there a way to intercept custom processor execution?
For example my route is following:
process(new LoggingProcessor())
or
processRef("loggingProcessor")
Also, is it's even possible to use interceptSendToEndpoint with
bean or beanRef DSL elements?
Kind regards,
Lukasz
Re: Intercept processor/bean
Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi Lukasz,
Nice to hear from you :-)
> For example my route is following:
> process(new LoggingProcessor())
> or
> processRef("loggingProcessor")
As far as I know No, as interception for a given processor is not given at
the DSL level. However what you could do is to make use of your own
InterceptStrategy, something like:
private static class LoggingProcessorInterceptor implements
InterceptStrategy {
@Override
public Processor wrapProcessorInInterceptors(CamelContext context,
ProcessorDefinition<?> definition, final Processor target, Processor
nextTarget) throws Exception {
if ("process[MyLoggingProcessor]".equals(definition.toString()))
{
return new Processor() {
public void process(Exchange exchange) throws Exception
{
// do some interception logic here...
exchange.getContext().createProducerTemplate().requestBody("mock:intercepted",
exchange.getIn().getBody());
// and then continue with the given target
target.process(exchange);
}
};
}
return target;
}
}
Where your LoggingProcessor is given as something like:
private static class LoggingProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
// your logging logic
}
@Override
public String toString() {
return "MyLoggingProcessor";
}
}
And then add this InterceptorStrategy to your Camel context:
context.addInterceptStrategy(new LoggingProcessorInterceptor());
> Also, is it's even possible to use interceptSendToEndpoint with bean or
> beanRef DSL elements?
Yes as interceptSendToEndpoint can be used for any kind of Endpoint
including the bean endpoint:
interceptSendToEndpoint("bean:hello?method=camel").to("mock:intercepted");
Also note that you could make use of wildcard or regular expressions while
specifying the endpoint uri:
http://camel.apache.org/intercept.html
Babak
--
View this message in context: http://camel.465427.n5.nabble.com/Intercept-processor-bean-tp5717639p5717664.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Intercept processor/bean
Posted by Christian Müller <ch...@gmail.com>.
Yeah, I also favor to use
to("bean://myBean?method=foo")
which you can intercept...
Best,
Christian
On Mon, Aug 20, 2012 at 8:11 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Fri, Aug 17, 2012 at 10:17 PM, Łukasz Dywicki <lu...@code-house.org>
> wrote:
> > Hey all,
> > Is there a way to intercept custom processor execution?
> >
> > For example my route is following:
> > process(new LoggingProcessor())
> > or
> > processRef("loggingProcessor")
> >
> > Also, is it's even possible to use interceptSendToEndpoint with
> >
> > bean or beanRef DSL elements?
> >
>
> Hi
>
> I think Babak have covered this well. Just to add that if you use
> bean/beanRef instead of process/processRef then you can use the
> interceptSendToEndpoint etc. to intercept sending to the bean.
>
> in the bean you can still implement org.apache.camel.Processor, and
> have Camel leverage that. So its just a matter of changing in the
> route DSL.
>
> > Kind regards,
> > Lukasz
>
>
>
> --
> 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
>
--
Re: Intercept processor/bean
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Aug 17, 2012 at 10:17 PM, Łukasz Dywicki <lu...@code-house.org> wrote:
> Hey all,
> Is there a way to intercept custom processor execution?
>
> For example my route is following:
> process(new LoggingProcessor())
> or
> processRef("loggingProcessor")
>
> Also, is it's even possible to use interceptSendToEndpoint with
>
> bean or beanRef DSL elements?
>
Hi
I think Babak have covered this well. Just to add that if you use
bean/beanRef instead of process/processRef then you can use the
interceptSendToEndpoint etc. to intercept sending to the bean.
in the bean you can still implement org.apache.camel.Processor, and
have Camel leverage that. So its just a matter of changing in the
route DSL.
> Kind regards,
> Lukasz
--
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