使用@ResponseBody注释做出响应时的多余字符

时间:2018-12-15 06:38:47

标签: java spring spring-mvc request-mapping

当负载均衡器调用我的应用程序时,我正在使用@RequestMapping和@ResponseBody批注做出简单的运行状况检查响应(确定/失败)。 这是我的代码:

@Controller

public class HealthCheck {

protected ir.iic.release.middleware.persistence.JDBCController JDBCController;

@Autowired
@Qualifier("JDBCController")
public void setJDBCController(JDBCController JDBCController) {
    this.JDBCController = JDBCController;
}

@RequestMapping(value = "/healthCheck", method = RequestMethod.GET)
@ResponseBody
String getHealthStatus() {
    long connectionStatus = 1;
    try {
        connectionStatus = JDBCController.queryForLong("SELECT 1 FROM DUAL");
    } catch (Exception e) {
        connectionStatus = 0;
    }
    return (connectionStatus == 1 ? "OK" : "FAILED");
}
}

当我通过浏览器调用指定的URL,但负载均衡器不接受响应时,一切正常。我用WireShark实用程序检查了响应以监视数据包,HTTP流中没有问题,但在TCP流中,在OK / FAILED响应之前和之后看起来都存在多余的字符。 这是TCP流:

GET /iic-auto/cluster/healthCheck HTTP/1.1
Host: 192.168.136.37:9001
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: JSESSIONID=3hdJcJXJPvVtbndx27hqrbcK81Qj7gFF660mLj5jnTXg5rWT26j0!-2081249701
Upgrade-Insecure-Requests: 1

HTTP/1.1 200 OK
Date: Sat, 15 Dec 2018 06:19:54 GMT
Transfer-Encoding: chunked
Content-Type: text/html
X-Powered-By: Servlet/2.5 JSP/2.1

0002
OK
HTTP/1.1 200 OK
Date: Sat, 15 Dec 2018 06:19:54 GMT
Transfer-Encoding: chunked
Content-Type: text/html
X-Powered-By: Servlet/2.5 JSP/2.1

0002
OK
0000

有人知道我可以解决这个问题吗? 感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

它们不是extra characters

它们是Transfer-Encoding: chunked使用的控制代码的一部分