Prevent response in controller

后端 未结 2 2024
感动是毒
感动是毒 2021-01-16 12:29

I am using spring boot to make a mock of one of our more complicated services. While all of the standard cases are easily done there is one that is causing me some troubles.

相关标签:
2条回答
  • 2021-01-16 13:07

    Closing the connection is the responsibility of HTTP specification and protocol. You cannot enforce it programmatically. Connection negotitation is happening between HTTP Client and HTTP Server.

    Although you can try interrupting current Thread or setting header Connection: close, but you should not be messing around with that part of the processing of a Connection and Request. Your HTTP server can start behaving unexpectedly.

    Try a different approach. If you need to simulate a closed connection you can programmatically allocate a new instance of HTTP server, send a request to it, put request processing on hold and kill an instance is a separate thread. I'm sure you'll find a better way for this, just get to the root of the problem from a different angle.

    0 讨论(0)
  • 2021-01-16 13:23

    You can create method like this:

    @ResponseBody
    @RequestMapping("/your-url")
    public String test() {
        return null;
    }
    

    you can also change @Controller to @RestController and remove the @ResponseBody

    0 讨论(0)
提交回复
热议问题