5

假设我有一个看起来像这样的拦截器:

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 的不同方法。

我通常希望将抛出的异常传递给调用客户端,就像所有正常的 EJB 异常一样。

显然,如果我从拦截器中抛出它,这不会发生......它甚至没有登录到服务器上;就像它从未被抛出一样 - return 语句从未被执行。

我究竟做错了什么?

我正在使用 GF 3.0.1

4

2 回答 2

2

在搜索了这个问题之后,我找到了几分钟前回答的这个 SO 帖子。引用:

我认为没有正确的方法可以做到这一点。方法应该只抛出它们声明的异常,并且拦截器不应该添加一个新的。通过将错误代码添加到所有方法抛出的默认异常中,我的个人情况得到了解决。

问题作者是回答并接受此答案的同一个人,所以我猜他正在尝试解决与您相同的问题并得出结论认为无法完成。

于 2010-12-07T13:40:03.017 回答
1

这里有几件事可以尝试:

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)
于 2010-12-07T11:53:51.450 回答