|
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;
|
@@ -439,14 +442,23 @@ protected ResponseEntity<Object> handleNoHandlerFoundException(
|
439 | 442 | * @param ex the exception
|
440 | 443 | * @param headers the headers to be written to the response
|
441 | 444 | * @param status the selected response status
|
442 |
| - * @param request the current request |
| 445 | + * @param webRequest the current request |
443 | 446 | * @return a {@code ResponseEntity} instance
|
444 | 447 | * @since 4.2.8
|
445 | 448 | */
|
446 | 449 | protected ResponseEntity<Object> handleAsyncRequestTimeoutException(
|
447 |
| - AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { |
448 |
| - |
449 |
| - return handleExceptionInternal(ex, null, headers, status, request); |
| 450 | + AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { |
| 451 | + |
| 452 | + if (webRequest instanceof ServletWebRequest) { |
| 453 | + ServletWebRequest servletRequest = (ServletWebRequest) webRequest; |
| 454 | + HttpServletRequest request = servletRequest.getNativeRequest(HttpServletRequest.class); |
| 455 | + HttpServletResponse response = servletRequest.getNativeResponse(HttpServletResponse.class); |
| 456 | + if (response.isCommitted()) { |
| 457 | + logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]"); |
| 458 | + return null; |
| 459 | + } |
| 460 | + } |
| 461 | + return handleExceptionInternal(ex, null, headers, status, webRequest); |
450 | 462 | }
|
451 | 463 |
|
452 | 464 | }
|
0 commit comments