001/* 002 * Copyright 2002-2017 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; 020 021import org.springframework.web.context.request.NativeWebRequest; 022 023/** 024 * Sends a 503 (SERVICE_UNAVAILABLE) in case of a timeout if the response is not 025 * already committed. As of 4.2.8 this is done indirectly by setting the result 026 * to an {@link AsyncRequestTimeoutException} which is then handled by 027 * Spring MVC's default exception handling as a 503 error. 028 * 029 * <p>Registered at the end, after all other interceptors and 030 * therefore invoked only if no other interceptor handles the timeout. 031 * 032 * <p>Note that according to RFC 7231, a 503 without a 'Retry-After' header is 033 * interpreted as a 500 error and the client should not retry. Applications 034 * can install their own interceptor to handle a timeout and add a 'Retry-After' 035 * header if necessary. 036 * 037 * @author Rossen Stoyanchev 038 * @since 3.2 039 */ 040public class TimeoutCallableProcessingInterceptor implements CallableProcessingInterceptor { 041 042 @Override 043 public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception { 044 return new AsyncRequestTimeoutException(); 045 } 046 047}