Tie

Java Method Interception

Cook Book

Only intercepting some methods

Problem:

You have an interface with a multiple methods, and you only want to apply interception to some of them.

Solution 1

Use the InterceptionBuilder to apply InterceptionRules to your stack.

Read the javadoc or the following recipes for more information on using rules.

Solution 2

Add logic into your interceptors to simply call MethodInvocation.proceed() for methods that do not match your criteria. e.g.

public Object invoke(MethodInvocation invocation) throws Throwable
{
    if( shouldIntercept( invocation.getMethod() ) )
    {
        // ...
    }
    else
    {
        return invocation.proceed() ;
    }

}