2014-03-12 21 views
1

MyInterceptor,哪個接口,IfclocalIfcRemote,調用方法doStuffMyEjb?有可能知道你的bean被調用了哪個「通道」? 我需要知道哪個依賴注入調用了該方法。如何攔截java中的特定接口?

@Local 
public interface IfcLocal { 
void doStuff(String s); 
} 

@Remote 
public interface IfcRemote { 
    void doStuff(String s); 
} 

@Stateless 
@Interceptors({ MyInterceptor.class }) 
public class MyEjb implements IfcLocal, IfcRemote { 
    @Override 
    public void doStuff(String s) { 
    System.out.println(s); 
    } 
} 

public class MyManagedBean { 
    @EJB private ifcLocal ifcLocal; 
    @EJB private IfcRemote ifcRemote; 

    public void go() { 
    ifcLocal.doStuff("xxx"); 
    ifcRemote.doStuff("xxx"); 
    } 
} 

public class MyInterceptor { 
    @AroundInvoke 
    public Object intercept(InvocationContext inv) throws Exception { 
    // ??? who invoked ??? 
    System.out.prinln(inv.getTarget().getClass()); // print MyEjb 
    } 
} 
+1

爲什麼你需要知道這一點? – 2014-03-12 14:07:54

+0

如果一個本地接口的方法,所以我可能要克隆一些參數。 –

回答

1

進樣@Resource private SessionContext sessionContext;MyInterceptor。之後:Class<?> interfaceReference = sessionContext.getInvokedBusinessInterface()