When I was debugging a web application accessing the server with ajax, the response was strange for some reason. Neither the response body nor the HTTP header is returned as expected. I investigated the cause, so I summarized it.
Test.java
@RestController
public class TestController {
@RequestMapping(value = "/test.do", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String test(HttpServletRequest request) throws Exception {
return "{ \"success\" : true }";
}
}
ajax.js
var req = new XMLHttpRequest();
req.open("POST", "test.do");
req.send();
--Because I was able to break in the test method of TestController, there is no URL error etc. --HTTP status 200 is returned --I also checked Filter and Interceptor, but there is no process that changes the response. Rather, the expected content was stored in the response object. --There is no difference between browsers. Weird response is returned in every browser --Sometimes a normal response is returned
When I went deeper and deeper in the step execution, an exception was thrown in `` `NioChannel.class``` in tomcat-coyote.jar.
NioChannel.class
/**
* This method should be used to check the interrupt status before
* attempting a write.
*
* If a thread has been interrupted and the interrupt has not been cleared
* then an attempt to write to the socket will fail. When this happens the
* socket is removed from the poller without the socket being selected. This
* results in a connection limit leak for NIO as the endpoint expects the
* socket to be selected even in error conditions.
*/
protected void checkInterruptStatus() throws IOException {
if (Thread.interrupted()) {
throw new IOException(sm.getString("channel.nio.interrupted"));
}
}
This exception was caught in the upper layer and rewritten as a response for the error.
I had a stack trace of this exception on the console every time, but I was ignoring it because it returned 200. If it looks like an error, you can't ignore it. But I think it's a terrible trap.
Recommended Posts