[jboss-user] [JBoss AOP] - Interceptor not getting called when pointcut is defined at i

harivenkatrajan do-not-reply at jboss.com
Thu Mar 13 17:45:02 EDT 2008



Hello,

 I have this requirement where when a method is called
on EJB local interface some security code needs to get executed.
Hence I tried annotating the EJB local interface method and understood
that aopc does not instrument interface classes as I see this compilation
log. 

[aopc] [cannot compile] isInterface: com.abc.HelloServiceLocal


I tried running a small example in eclipse with pointcut-interceptor
defined at interface level and do not see the interception happening
when invocation happens at interface level. I am not sure if I got 
this concept itself wrong or if something else needs to be done to
get this working.

Pls, find the following files.

1. HelloAOP.java
2. HelloAOPInterceptor.java
3. HelloAOPInterface.java
4. jboss-aop.xml


1.
package com;
public class HelloAOP implements HelloAOPInterface{

	public void callMe ()
	{
		System.out.println("AOP!");
	}
	
	
	public void secondCallMe ()
	{
		System.out.println("Second AOP!");
	}
	
	
	public static void main (String args[])
	{
		
		System.out.println("Calling through interface");
		HelloAOPInterface helloI = new HelloAOP();
		helloI.callMe();
		
		System.out.println("Calling direct ");
                HelloAOP hello = new HelloAOP();
		hello.callMe();
		hello.secondCallMe();
	}
}


2.
package com;
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();
	}
}
   

3.
package com;
public interface HelloAOPInterface {
	public void callMe ();
}


4.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    
        
    
    
        
    



Here is output log :
Calling through interface
AOP!
Calling direct 
AOP!
Hello, Second AOP!


Any suggestions will be appreciated.




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4136474#4136474

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4136474



More information about the jboss-user mailing list