4

So, I have a RestController and a PostMapping that's responsible for an upload:

@RestController
@RequestMapping("/api/v1/upload")
public class UploadResource {

    @PostMapping
    public void upload(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {


    }
}

What I want to achieve is: reset the connection after a specific amount of time (some kind of timeout). I tried to close the response and request stream:

response.getOutputStream().close();
request.getInputStream().close();

I also tried to throw an exception inside the method.

But my client is still sending data (also wireshark tells me the packets are still arriving at the target)

Is it somehow possible to close the underlying socket? The desirable result would be a SocketException: connection reset (or something similar) on the client side

Luk B
  • 41
  • 1
  • 2
  • have you tried `reponse.reset()`? ;) [javadoc](https://docs.oracle.com/javaee/6/api/javax/servlet/ServletResponse.html#reset()) – xerx593 Jan 30 '18 at 20:25
  • Yes I have. The socket is still open and the client is still sending data – Luk B Jan 31 '18 at 07:41
  • [This guy has the issue, which you'd like as a feature](https://stackoverflow.com/questions/12476604/processing-of-multipart-form-data-request-failed-read-timed-out/18543887#18543887) ...they solved by activating(-> increasing) upload timeout on the container (tomcat) ... can u check this approach? ..but i am not sure about the client outcome: a connection reset or a "502"... – xerx593 Jan 31 '18 at 19:56
  • [MyKong has also the issue and desired outcome](https://www.mkyong.com/spring/spring-file-upload-and-connection-reset-issue/) ...but it is file **size** based :/ – xerx593 Jan 31 '18 at 19:59

0 Answers0