Tomcat发回HTML而不是servlet过滤器的错误消息

时间:2019-10-10 13:12:39

标签: java spring rest spring-boot tomcat

我有一个从RestTemplate调用的REST服务(Spring MVC)。在REST应用程序中,有一个servlet过滤器,该过滤器会检查某些内容,并可能将错误消息发送回401。 在这种情况下,我在RestTemplate中得到一个HttpClientErrorException,这是可以的。不能确定的是,我没有取回在servlet过滤器中发回的错误消息,但是REST响应正文包含以下HTML:

<html lang="en">
    <head>
        <title>HTTP Status 401 – Unauthorized</title>
        <style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style>
    </head>
    <body>
        <h1>HTTP Status 401 – Unauthorized</h1>
        <hr class="line" />
        <p>
            <b>Type</b> Status Report</p>
        <p>
            <b>Message</b> Access Denied</p>
        <p>
            <b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p>
        <hr class="line" />
        <h3>Apache Tomcat/9.0.8</h3>
    </body>
</html>

它是由Tomcat生成和发送的。我在servlet过滤器中使用的代码发送回错误代码和消息如下:

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    ...
    catch(...) {
        response.sendError(errorCode, message);
        return;
    }
    ...
}

我的问题是为什么我没有在客户端收到错误消息?我正在使用Spring Boot(1.5.8.RELEASE)。据我所知 有什么提示吗?另外我该如何调试我的响应被劫持的地方?

谢谢,
V。

0 个答案:

没有答案