[英]throwing exceptions from EJB interceptors
假设我有一个看起来像这样的拦截器:
public class AuthorizationInterceptor {
Logger log = Logger.getLogger(getClass().getName());
@AroundInvoke
private Object authorize(InvocationContext ic) throws Exception{
// ... some other logic for authorization
if (!allowedMethods.contains(ic.getMethod().getName())){
log.info("Authorization failed. Preparing to throw exception");
throw new AuthException("Authorization failed for method " +
ic.getMethod().getName());
}
return ic.proceed();
}
}
这适用于我的EJB的不同方法。
我通常希望将异常throed传递给调用客户端,就像所有正常的EJB异常一样。
显然,如果我从Interceptor中抛出它,就不会发生这种情况......它甚至没有记录在服务器上; 喜欢它永远不会抛出,但它是 - 从不执行return语句。
我究竟做错了什么?
我正在使用GF 3.0.1
在仔细搜索了这个问题之后,我发现这个SO帖子几分钟前得到了解答。 引用:
我认为没有正确的方法可以做到这一点。 方法应该只抛出它们声明的异常,并且拦截器不应该添加新的异常。 通过向我们的默认异常添加错误代码来修复我的个人案例,这是所有方法抛出的。
问题作者是回答并接受这个答案的同一个人,所以我猜他试图解决与你相同的问题,并得出结论,它无法完成。
这里有几件事要尝试:
1. Check that the authorize(...) method is called.
2. Try making the authorize(...) method public instead of private.
3. Check that the EJB has an annotation like this:
@Interceptors(AuthorizationInterceptor.class)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.