JBoss.org Community Documentation

9.3.3. Create Interceptor

Next we want to create an interceptor to the class.

  • Right click on the "src" directory in the Package Explorer and in the menu, click New > Class. In the resulting dialog:
    • Name the class HelloAOPInterceptor
    • Add org.jboss.aop.advice.Interceptor to the list of interceptors.

Then modify the class so it looks like:

   import org.jboss.aop.advice.Interceptor;
   import org.jboss.aop.joinpoint.Invocation;
   
   public class HelloAOPInterceptor implements Interceptor {
   
   	public String getName() {
   		return "HelloAOPInterceptor";
   	}
   
      //We renamed the arg0 parameter to invocation
   	public Object invoke(Invocation invocation) throws Throwable {
   		System.out.print("Hello, ");
         //Here we invoke the next in the chain
   		return invocation.invokeNext();
   	}
   }