我已经创建了一个servlet过滤器,现在抛出异常的地方 - 原因始终是过滤器类。
我正在使用request.exception
在ErrorController中检索异常类。
的堆栈跟踪:
java.lang.RuntimeException:
at my.MyController $ _closure4.doCall( MyController.groovy:68 )
......
at my.MyFilter.doFilter( MyFilter.groovy:38 )
...
在java.lang.Thread.run(Thread.java:745)
我无法得到异常的真正原因:/
为什么request.exception.getClassName()
会返回 MyFilter 而不是 MyController ?
MyFilter:
@CompileStatic
类MyFilter实现Filter {
UrlMappingsHolder grailsUrlMappingsHolder
MyService myService
@Override
void init(FilterConfig filterConfig) throws ServletException {
}
@Override
void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String url = ((HttpServletRequest)servletRequest).getServletPath()
def urlInfo = grailsUrlMappingsHolder.match(url).getParameters()
if (!myService.controllersToNotCheck.contains(urlInfo.controller) && !myService.sourcesExist()) {
throw new NoEnvironmentException()
}
filterChain.doFilter(servletRequest, servletResponse)
}
@Override
void destroy() {
}
}
答案 0 :(得分:0)
谢谢你们帮助我们。 问题如下: Grails使用GrailsWrappedRuntimeException类包装异常; 这个解析堆栈跟踪,并查找带有.groovy扩展名的文件的最后一次出现。 MyFilter始终是stacktrace中的最后一个groovy类(如果从顶部到底部读取),这就是为什么className始终是MyFilter,因此它隐藏了有关抛出异常的控制器或服务的信息。 我的解决方案很简单:我将过滤器改写为" MyFilter .java " :)