让我们说我们的应用程序中有一些模块:
REST API
WEB
CORE
DAO
对于CORE
中的所有方法,我们定义了EJB @Interceptor。是否可以确定module
中的CORE
调用方法是什么?
示例:我有方法CORE.methodThatHasInterceptor()
我从WEB.unknownMethod(){ CORE.methodThatHasInterceptor() }
它转到methodThatHasInterceptor
方法的拦截器:
@AroundInvoke
public Object interceptor(InvocationContext invocCtx) throws Exception {
// is it possible to know that it was called from WEB.unknownMethod() ?
}
答案 0 :(得分:1)
InvocationContext的javadoc在这个主题上提供了很多信息:
http://docs.oracle.com/javaee/6/api/javax/interceptor/InvocationContext.html
我将在顶部引用示例代码:
@AroundInvoke
public Object logInvocation(InvocationContext ctx) throws Exception {
String class = ctx.getMethod().getDeclaringClass().getName();
String method = ctx.getMethod().getName();
Logger.global.entering(class, method, ctx.getParameters());
try {
Object result = ctx.proceed();
Logger.global.exiting(class, method, result);
return result;
}
catch (Exception e) {
Logger.global.throwing(class, method, e);
throw e;
}
}