Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不要在tomcat中记录未处理的异常_Java_Tomcat_Logging_Exception Handling_Spring Saml - Fatal编程技术网

Java 不要在tomcat中记录未处理的异常

Java 不要在tomcat中记录未处理的异常,java,tomcat,logging,exception-handling,spring-saml,Java,Tomcat,Logging,Exception Handling,Spring Saml,我们有一个tomcat webapp,在一次正常的无效登录尝试中,它在疯狂的Spring SAML内部抛出了一些可怕的SAML身份验证异常。异常未处理,用户被重定向到一个半有用的错误页面,使用 <error-page> <exception-type>com.test.SomeException</exception-type> <location>/error.jsp</location> <

我们有一个tomcat webapp,在一次正常的无效登录尝试中,它在疯狂的Spring SAML内部抛出了一些可怕的SAML身份验证异常。异常未处理,用户被重定向到一个半有用的错误页面,使用

   <error-page>
      <exception-type>com.test.SomeException</exception-type>
      <location>/error.jsp</location>
   </error-page>

com.test.SomeException
/error.jsp

它工作正常,只是tomcat仍然在catalina.out中记录未处理的异常。是否有一些简单的方法来防止它污染带有strack痕迹的日志文件(这些痕迹会被日志监控软件等拾取),而不必重新构造所有内容?那么,处理这个问题的正确方法是什么

当然,您可以在Spring中处理异常,不需要让它们冒泡到web.xml中的处理程序。请参见中的一些示例。

因此,以下是我目前所了解的内容,不是理想的,而是一些作品:

   @Override
   public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
      try {
         doFilterInternal(servletRequest, servletResponse, filterChain);
      } catch (MyVerySpecificSamlAuthException ex) {
         HttpServletRequest request = (HttpServletRequest)servletRequest;
         RequestDispatcher requestDispatcher = request.getRequestDispatcher("/general_error.jsp");
         request.setAttribute(RequestDispatcher.ERROR_MESSAGE, ex.getMessage());
         requestDispatcher.forward(request, servletResponse);
      }
   }

您是否使用外部日志框架,如log4j?是的,log4j2。但是用它来过滤这些东西感觉很糟糕。但是这难道不是只适用于MVC控制器中发生的异常吗?在我的例子中,SAMLContextProviderImpl的自定义实现中会抛出异常(当我们找不到有效的partnerId时)。