Как перехватить определенный интерфейс в Java?

1

В MyInterceptor, в каком интерфейсе Ifclocal или IfcRemote вызывается метод doStuff в MyEjb? Возможно ли узнать, через какой "канал" был вызван ваш боб? Мне нужно знать, какая инъекция зависимости вызвала метод.

@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 
  }
}
Теги:
ejb

1 ответ

1
Лучший ответ

@Resource private SessionContext sessionContext; в MyInterceptor. После: Class<?> interfaceReference = sessionContext.getInvokedBusinessInterface().

Ещё вопросы

Сообщество Overcoder
Наверх
Меню