|
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;
|
@@ -462,14 +465,23 @@ protected ResponseEntity<Object> handleNoHandlerFoundException(
|
462 | 465 | * @param ex the exception
|
463 | 466 | * @param headers the headers to be written to the response
|
464 | 467 | * @param status the selected response status
|
465 |
| - * @param request the current request |
| 468 | + * @param webRequest the current request |
466 | 469 | * @return a {@code ResponseEntity} instance
|
467 | 470 | * @since 4.2.8
|
468 | 471 | */
|
469 | 472 | protected ResponseEntity<Object> handleAsyncRequestTimeoutException(
|
470 |
| - AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { |
471 |
| - |
472 |
| - return handleExceptionInternal(ex, null, headers, status, request); |
| 473 | + AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { |
| 474 | + |
| 475 | + if (webRequest instanceof ServletWebRequest) { |
| 476 | + ServletWebRequest servletRequest = (ServletWebRequest) webRequest; |
| 477 | + HttpServletRequest request = servletRequest.getNativeRequest(HttpServletRequest.class); |
| 478 | + HttpServletResponse response = servletRequest.getNativeResponse(HttpServletResponse.class); |
| 479 | + if (response.isCommitted()) { |
| 480 | + logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]"); |
| 481 | + return null; |
| 482 | + } |
| 483 | + } |
| 484 | + return handleExceptionInternal(ex, null, headers, status, webRequest); |
473 | 485 | }
|
474 | 486 |
|
475 | 487 | }
|
0 commit comments