org.springframework.web.context.request.async.AsyncRequestTimeoutException Java Examples
The following examples show how to use
org.springframework.web.context.request.async.AsyncRequestTimeoutException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResponseEntityExceptionHandler.java From spring-analysis-note with MIT License | 6 votes |
/** * Customize the response for AsyncRequestTimeoutException. * <p>This method delegates to {@link #handleExceptionInternal}. * @param ex the exception * @param headers the headers to be written to the response * @param status the selected response status * @param webRequest the current request * @return a {@code ResponseEntity} instance * @since 4.2.8 */ @Nullable protected ResponseEntity<Object> handleAsyncRequestTimeoutException( AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { if (webRequest instanceof ServletWebRequest) { ServletWebRequest servletWebRequest = (ServletWebRequest) webRequest; HttpServletResponse response = servletWebRequest.getResponse(); if (response != null && response.isCommitted()) { if (logger.isWarnEnabled()) { logger.warn("Async request timed out"); } return null; } } return handleExceptionInternal(ex, null, headers, status, webRequest); }
Example #2
Source File: ResponseEntityExceptionHandler.java From java-technology-stack with MIT License | 6 votes |
/** * Customize the response for NoHandlerFoundException. * <p>This method delegates to {@link #handleExceptionInternal}. * @param ex the exception * @param headers the headers to be written to the response * @param status the selected response status * @param webRequest the current request * @return a {@code ResponseEntity} instance * @since 4.2.8 */ @Nullable protected ResponseEntity<Object> handleAsyncRequestTimeoutException( AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { if (webRequest instanceof ServletWebRequest) { ServletWebRequest servletWebRequest = (ServletWebRequest) webRequest; HttpServletResponse response = servletWebRequest.getResponse(); if (response != null && response.isCommitted()) { if (logger.isWarnEnabled()) { logger.warn("Async request timed out"); } return null; } } return handleExceptionInternal(ex, null, headers, status, webRequest); }
Example #3
Source File: ResponseEntityExceptionHandler.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Customize the response for NoHandlerFoundException. * <p>This method delegates to {@link #handleExceptionInternal}. * @param ex the exception * @param headers the headers to be written to the response * @param status the selected response status * @param webRequest the current request * @return a {@code ResponseEntity} instance * @since 4.2.8 */ protected ResponseEntity<Object> handleAsyncRequestTimeoutException( AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) { if (webRequest instanceof ServletWebRequest) { ServletWebRequest servletRequest = (ServletWebRequest) webRequest; HttpServletRequest request = servletRequest.getNativeRequest(HttpServletRequest.class); HttpServletResponse response = servletRequest.getNativeResponse(HttpServletResponse.class); if (response.isCommitted()) { if (logger.isErrorEnabled()) { logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]"); } return null; } } return handleExceptionInternal(ex, null, headers, status, webRequest); }
Example #4
Source File: DefaultHandlerExceptionResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // SPR-14669 public void handleAsyncRequestTimeoutException() throws Exception { Exception ex = new AsyncRequestTimeoutException(); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertNotNull("No ModelAndView returned", mav); assertTrue("No Empty ModelAndView returned", mav.isEmpty()); assertEquals("Invalid status code", 503, response.getStatus()); }
Example #5
Source File: ExceptionAdvice.java From moon-api-gateway with MIT License | 5 votes |
@ExceptionHandler(AsyncRequestTimeoutException.class) public ResponseEntity asyncRequestTimeoutException(Exception e, HttpServletRequest request) { log.error("{}", getStackTrace(e)); ExceptionType exceptionType = ExceptionType.E_1104_OUTBOUND_SERVICE_REQUEST_TIME_OUT; setHttpResponseErrorCode(request, ExceptionType.E_1104_OUTBOUND_SERVICE_REQUEST_TIME_OUT.getCode()); CommonResponseEntity response = CommonResponseEntity.generateException(exceptionType.getCode(), messageManager.getProperty(exceptionType.getCode())); return HttpHelper.newResponseEntityWithId(HttpStatus.REQUEST_TIMEOUT, response); }
Example #6
Source File: OneOffSpringCommonFrameworkExceptionHandlerListenerTest.java From backstopper with Apache License 2.0 | 5 votes |
@Test public void shouldHandleException_returns_TEMPORARY_SERVICE_PROBLEM_for_AsyncRequestTimeoutException() { // given AsyncRequestTimeoutException ex = new AsyncRequestTimeoutException(); assertThat(ex.getClass().getName()) .isEqualTo("org.springframework.web.context.request.async.AsyncRequestTimeoutException"); // when ApiExceptionHandlerListenerResult result = listener.shouldHandleException(ex); // then validateResponse(result, true, singletonList(testProjectApiErrors.getTemporaryServiceProblemApiError())); }
Example #7
Source File: DefaultHandlerExceptionResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test // SPR-14669 public void handleAsyncRequestTimeoutException() throws Exception { Exception ex = new AsyncRequestTimeoutException(); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertNotNull("No ModelAndView returned", mav); assertTrue("No Empty ModelAndView returned", mav.isEmpty()); assertEquals("Invalid status code", 503, response.getStatus()); }
Example #8
Source File: TemperatureController.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 5 votes |
@ExceptionHandler(value = AsyncRequestTimeoutException.class) public ModelAndView handleTimeout(HttpServletResponse rsp) throws IOException { if (!rsp.isCommitted()) { rsp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } return new ModelAndView(); }
Example #9
Source File: TemperatureController.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 5 votes |
@ExceptionHandler(value = AsyncRequestTimeoutException.class) public ModelAndView handleTimeout(HttpServletResponse rsp) throws IOException { if (!rsp.isCommitted()) { rsp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } return new ModelAndView(); }
Example #10
Source File: SpringExceptionHandler.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
@ExceptionHandler(AsyncRequestTimeoutException.class) public final Object handleSpringServiceUnavailableException( Exception e, HandlerMethod handlerMethod) { return logAndHandleException(e, SERVICE_UNAVAILABLE, handlerMethod); }
Example #11
Source File: DefaultHandlerExceptionResolver.java From spring-analysis-note with MIT License | 4 votes |
@Override @Nullable protected ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { try { if (ex instanceof HttpRequestMethodNotSupportedException) { return handleHttpRequestMethodNotSupported( (HttpRequestMethodNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotSupportedException) { return handleHttpMediaTypeNotSupported( (HttpMediaTypeNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotAcceptableException) { return handleHttpMediaTypeNotAcceptable( (HttpMediaTypeNotAcceptableException) ex, request, response, handler); } else if (ex instanceof MissingPathVariableException) { return handleMissingPathVariable( (MissingPathVariableException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestParameterException) { return handleMissingServletRequestParameter( (MissingServletRequestParameterException) ex, request, response, handler); } else if (ex instanceof ServletRequestBindingException) { return handleServletRequestBindingException( (ServletRequestBindingException) ex, request, response, handler); } else if (ex instanceof ConversionNotSupportedException) { return handleConversionNotSupported( (ConversionNotSupportedException) ex, request, response, handler); } else if (ex instanceof TypeMismatchException) { return handleTypeMismatch( (TypeMismatchException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotReadableException) { return handleHttpMessageNotReadable( (HttpMessageNotReadableException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotWritableException) { return handleHttpMessageNotWritable( (HttpMessageNotWritableException) ex, request, response, handler); } else if (ex instanceof MethodArgumentNotValidException) { return handleMethodArgumentNotValidException( (MethodArgumentNotValidException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestPartException) { return handleMissingServletRequestPartException( (MissingServletRequestPartException) ex, request, response, handler); } else if (ex instanceof BindException) { return handleBindException((BindException) ex, request, response, handler); } else if (ex instanceof NoHandlerFoundException) { return handleNoHandlerFoundException( (NoHandlerFoundException) ex, request, response, handler); } else if (ex instanceof AsyncRequestTimeoutException) { return handleAsyncRequestTimeoutException( (AsyncRequestTimeoutException) ex, request, response, handler); } } catch (Exception handlerEx) { if (logger.isWarnEnabled()) { logger.warn("Failure while trying to resolve exception [" + ex.getClass().getName() + "]", handlerEx); } } return null; }
Example #12
Source File: ExampleController.java From opentracing-toolbox with MIT License | 4 votes |
@ExceptionHandler(AsyncRequestTimeoutException.class) public String onTimeout() { return "Interrupted"; }
Example #13
Source File: DefaultHandlerExceptionResolver.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("deprecation") protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { try { if (ex instanceof org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) { return handleNoSuchRequestHandlingMethod((org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) ex, request, response, handler); } else if (ex instanceof HttpRequestMethodNotSupportedException) { return handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotSupportedException) { return handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotAcceptableException) { return handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException) ex, request, response, handler); } else if (ex instanceof MissingPathVariableException) { return handleMissingPathVariable((MissingPathVariableException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestParameterException) { return handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, request, response, handler); } else if (ex instanceof ServletRequestBindingException) { return handleServletRequestBindingException((ServletRequestBindingException) ex, request, response, handler); } else if (ex instanceof ConversionNotSupportedException) { return handleConversionNotSupported((ConversionNotSupportedException) ex, request, response, handler); } else if (ex instanceof TypeMismatchException) { return handleTypeMismatch((TypeMismatchException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotReadableException) { return handleHttpMessageNotReadable((HttpMessageNotReadableException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotWritableException) { return handleHttpMessageNotWritable((HttpMessageNotWritableException) ex, request, response, handler); } else if (ex instanceof MethodArgumentNotValidException) { return handleMethodArgumentNotValidException((MethodArgumentNotValidException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestPartException) { return handleMissingServletRequestPartException((MissingServletRequestPartException) ex, request, response, handler); } else if (ex instanceof BindException) { return handleBindException((BindException) ex, request, response, handler); } else if (ex instanceof NoHandlerFoundException) { return handleNoHandlerFoundException((NoHandlerFoundException) ex, request, response, handler); } else if (ex instanceof AsyncRequestTimeoutException) { return handleAsyncRequestTimeoutException( (AsyncRequestTimeoutException) ex, request, response, handler); } } catch (Exception handlerException) { if (logger.isWarnEnabled()) { logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException); } } return null; }
Example #14
Source File: GlobalExceptionHandler.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 4 votes |
@ExceptionHandler(value = AsyncRequestTimeoutException.class) public ResponseEntity<Result> handleAsyncRequestTimeoutException(AsyncRequestTimeoutException e, HttpServletRequest request) { System.out.println(request.getRequestURI()); System.out.println("请求超时"); return ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body(new Result("请求超时")); }
Example #15
Source File: ResponseEntityExceptionHandlerTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void asyncRequestTimeoutException() { testException(new AsyncRequestTimeoutException()); }
Example #16
Source File: DefaultHandlerExceptionResolver.java From java-technology-stack with MIT License | 4 votes |
@Override @Nullable protected ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { try { if (ex instanceof HttpRequestMethodNotSupportedException) { return handleHttpRequestMethodNotSupported( (HttpRequestMethodNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotSupportedException) { return handleHttpMediaTypeNotSupported( (HttpMediaTypeNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotAcceptableException) { return handleHttpMediaTypeNotAcceptable( (HttpMediaTypeNotAcceptableException) ex, request, response, handler); } else if (ex instanceof MissingPathVariableException) { return handleMissingPathVariable( (MissingPathVariableException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestParameterException) { return handleMissingServletRequestParameter( (MissingServletRequestParameterException) ex, request, response, handler); } else if (ex instanceof ServletRequestBindingException) { return handleServletRequestBindingException( (ServletRequestBindingException) ex, request, response, handler); } else if (ex instanceof ConversionNotSupportedException) { return handleConversionNotSupported( (ConversionNotSupportedException) ex, request, response, handler); } else if (ex instanceof TypeMismatchException) { return handleTypeMismatch( (TypeMismatchException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotReadableException) { return handleHttpMessageNotReadable( (HttpMessageNotReadableException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotWritableException) { return handleHttpMessageNotWritable( (HttpMessageNotWritableException) ex, request, response, handler); } else if (ex instanceof MethodArgumentNotValidException) { return handleMethodArgumentNotValidException( (MethodArgumentNotValidException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestPartException) { return handleMissingServletRequestPartException( (MissingServletRequestPartException) ex, request, response, handler); } else if (ex instanceof BindException) { return handleBindException((BindException) ex, request, response, handler); } else if (ex instanceof NoHandlerFoundException) { return handleNoHandlerFoundException( (NoHandlerFoundException) ex, request, response, handler); } else if (ex instanceof AsyncRequestTimeoutException) { return handleAsyncRequestTimeoutException( (AsyncRequestTimeoutException) ex, request, response, handler); } } catch (Exception handlerEx) { if (logger.isWarnEnabled()) { logger.warn("Failure while trying to resolve exception [" + ex.getClass().getName() + "]", handlerEx); } } return null; }
Example #17
Source File: ResponseEntityExceptionHandlerTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void asyncRequestTimeoutException() { testException(new AsyncRequestTimeoutException()); }
Example #18
Source File: GlobalController.java From BlogManagePlatform with Apache License 2.0 | 3 votes |
/** * 默认异常处理器 * @param HttpServletResponse 响应 * @param ServletRequestBindingException 异常 * @author Frodez * @throws IOException * @throws JsonProcessingException * @date 2018-12-21 */ @ExceptionHandler(value = AsyncRequestTimeoutException.class) public void asyncRequestTimeoutExceptionHandler(HttpServletResponse response, AsyncRequestTimeoutException e) throws JsonProcessingException, IOException { log.error("[frodez.config.mvc.error.GlobalController.asyncRequestTimeoutExceptionHandler]{}"); ServletUtil.writeJson(response, Result.busy()); }
Example #19
Source File: DefaultHandlerExceptionResolver.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Handle the case where an async request timed out. * <p>The default implementation sends an HTTP 503 error. * @param ex the {@link AsyncRequestTimeoutException }to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from response.sendError() * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else if (logger.isErrorEnabled()) { logger.error("Async timeout for " + request.getMethod() + " [" + request.getRequestURI() + "]"); } return new ModelAndView(); }
Example #20
Source File: DefaultHandlerExceptionResolver.java From java-technology-stack with MIT License | 3 votes |
/** * Handle the case where an async request timed out. * <p>The default implementation sends an HTTP 503 error. * @param ex the {@link AsyncRequestTimeoutException }to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { logger.warn("Async request timed out"); } return new ModelAndView(); }
Example #21
Source File: DefaultHandlerExceptionResolver.java From spring-analysis-note with MIT License | 3 votes |
/** * Handle the case where an async request timed out. * <p>The default implementation sends an HTTP 503 error. * @param ex the {@link AsyncRequestTimeoutException }to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { logger.warn("Async request timed out"); } return new ModelAndView(); }