001/* 002 * Copyright 2002-2016 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.context.request.async; 018 019import java.util.concurrent.Callable; 020import javax.servlet.http.HttpServletResponse; 021 022import org.springframework.http.HttpStatus; 023import org.springframework.web.context.request.NativeWebRequest; 024 025/** 026 * Sends a 503 (SERVICE_UNAVAILABLE) in case of a timeout if the response is not 027 * already committed. As of 4.2.8 this is done indirectly by setting the result 028 * to an {@link AsyncRequestTimeoutException} which is then handled by 029 * Spring MVC's default exception handling as a 503 error. 030 * 031 * <p>Registered at the end, after all other interceptors and 032 * therefore invoked only if no other interceptor handles the timeout. 033 * 034 * <p>Note that according to RFC 7231, a 503 without a 'Retry-After' header is 035 * interpreted as a 500 error and the client should not retry. Applications 036 * can install their own interceptor to handle a timeout and add a 'Retry-After' 037 * header if necessary. 038 * 039 * @author Rossen Stoyanchev 040 * @since 3.2 041 */ 042public class TimeoutCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter { 043 044 @Override 045 public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception { 046 return new AsyncRequestTimeoutException(); 047 } 048 049}