Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The difference between after and afterFinally is that afterFinally is invoked from a finally block so it will always be invoked no matter what, eg also in case of an exception occur.

Using from Java DSL

In this route we want to use the AOP to do a before and after logging.

Code Block
java
java

from("jms:queue:inbox")
   .aop().around("log:before", "log:after")
       .to("bean:order?method=validate")
       .to("bean:order?method=handle")
   .end()
   .to("jms:queue:order");

Notice that we use the end to indicate where the AOP around should end, for instance if we do more routing afterwards such as sending to another JMS queue. In the route below the AOP is only being around the bean processing.

The aop in Java DSL have the following methods:

  • around
  • aroundFinally
  • before
  • after
  • afterFinally

Using from Spring DSL

In Spring DSL its nearly the same as in the Java DSL however a bit differently

Code Block
xml
xml

<route>
    <from uri="jms:queue:inbox"/>
    <aop beforeUri="log:before" afterUri="log:after">
        <to uri="bean:order?method=validate"/>
        <to uri="bean:order?method=handle"/>
    </aop>
    <to uri="jms:queue:order"/>

Notice we use attributes on the <aop> tag to chose with AOP concept to use.

The aop in Spring DSL have the following attributes:

  • beforeUri
  • afterUri
  • afterFinallyUri

So in order to do an around we use both the beforeUri and the afterUri.

See Also