|
18 | 18 |
|
19 | 19 | import java.util.List;
|
20 | 20 | import java.util.Set;
|
| 21 | +import javax.servlet.http.HttpServletRequest; |
| 22 | +import javax.servlet.http.HttpServletResponse; |
21 | 23 |
|
22 | 24 | import org.apache.commons.logging.Log;
|
23 | 25 | import org.apache.commons.logging.LogFactory;
|
|
43 | 45 | import org.springframework.web.bind.ServletRequestBindingException;
|
44 | 46 | import org.springframework.web.bind.annotation.ControllerAdvice;
|
45 | 47 | import org.springframework.web.bind.annotation.ExceptionHandler;
|
| 48 | +import org.springframework.web.context.request.ServletWebRequest; |
46 | 49 | import org.springframework.web.context.request.WebRequest;
|
47 | 50 | import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
|
48 | 51 | import org.springframework.web.multipart.support.MissingServletRequestPartException;
|
@@ -464,14 +467,23 @@ protected ResponseEntity<Object> handleNoHandlerFoundException(
|
464 | 467 | * @param ex the exception
|
465 | 468 | * @param headers the headers to be written to the response
|
466 | 469 | * @param status the selected response status
|
467 |
| - * @param request the current request |
| 470 | + * @param webRequest the current request |
468 | 471 | * @return a {@code ResponseEntity} instance
|
469 | 472 | * @since 4.2.8
|
470 | 473 | */
|
471 | 474 | protected ResponseEntity<Object> handleAsyncRequestTimeoutException(
|
472 |
| - AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { |
473 |
| - |
474 |
| - return handleExceptionInternal(ex, null, headers, status, request); |
| 475 | + AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { |
| 476 | + |
| 477 | + if (webRequest instanceof ServletWebRequest) { |
| 478 | + ServletWebRequest servletRequest = (ServletWebRequest) webRequest; |
| 479 | + HttpServletRequest request = servletRequest.getNativeRequest(HttpServletRequest.class); |
| 480 | + HttpServletResponse response = servletRequest.getNativeResponse(HttpServletResponse.class); |
| 481 | + if (response.isCommitted()) { |
| 482 | + logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]"); |
| 483 | + return null; |
| 484 | + } |
| 485 | + } |
| 486 | + return handleExceptionInternal(ex, null, headers, status, webRequest); |
475 | 487 | }
|
476 | 488 |
|
477 | 489 | }
|
0 commit comments