Spring MVC Disable request time-out for specific endpoint

1 day ago 3
ARTICLE AD BOX

Yes. Instead of changing the global async timeout, you can set the timeout per request. WebAsyncTask or DeferredResult. This lets you keep the default timeout for other endpoints.

For your case StreamingResponseBody, wrap it in WebAsyncTask and specify a custom timeout.

Example:

@PostMapping(value = "/.../endpoint", produces = "application/zip") public WebAsyncTask<ResponseEntity<StreamingResponseBody>> renderImages(...) { StreamingResponseBody stream = outputStream -> { // rendering + streaming logic }; ResponseEntity<StreamingResponseBody> response = ResponseEntity.ok().body(stream); // disable timeout for this endpoint (-1) or set custom timeout in ms return new WebAsyncTask<>(-1, () -> response); }

You could also set a longer timeout instead of disabling it:

return new WebAsyncTask<>(600_000, () -> response); // 10 minutes

Somil Jain's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article