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.http.client; 018 019import java.io.IOException; 020 021import org.springframework.http.HttpRequest; 022import org.springframework.util.concurrent.ListenableFuture; 023 024/** 025 * Intercepts client-side HTTP requests. Implementations of this interface can be 026 * {@linkplain org.springframework.web.client.AsyncRestTemplate#setInterceptors registered} 027 * with the {@link org.springframework.web.client.AsyncRestTemplate} as to modify 028 * the outgoing {@link HttpRequest} and/or register to modify the incoming 029 * {@link ClientHttpResponse} with help of a 030 * {@link org.springframework.util.concurrent.ListenableFutureAdapter}. 031 * 032 * <p>The main entry point for interceptors is {@link #intercept}. 033 * 034 * @author Jakub Narloch 035 * @author Rossen Stoyanchev 036 * @since 4.3 037 * @see org.springframework.web.client.AsyncRestTemplate 038 * @see org.springframework.http.client.support.InterceptingAsyncHttpAccessor 039 * @deprecated as of Spring 5.0, in favor of 040 * {@link org.springframework.web.reactive.function.client.ExchangeFilterFunction} 041 */ 042@Deprecated 043public interface AsyncClientHttpRequestInterceptor { 044 045 /** 046 * Intercept the given request, and return a response future. The given 047 * {@link AsyncClientHttpRequestExecution} allows the interceptor to pass on 048 * the request to the next entity in the chain. 049 * <p>An implementation might follow this pattern: 050 * <ol> 051 * <li>Examine the {@linkplain HttpRequest request} and body</li> 052 * <li>Optionally {@linkplain org.springframework.http.client.support.HttpRequestWrapper 053 * wrap} the request to filter HTTP attributes.</li> 054 * <li>Optionally modify the body of the request.</li> 055 * <li>One of the following: 056 * <ul> 057 * <li>execute the request through {@link ClientHttpRequestExecution}</li> 058 * <li>don't execute the request to block the execution altogether</li> 059 * </ul> 060 * <li>Optionally adapt the response to filter HTTP attributes with the help of 061 * {@link org.springframework.util.concurrent.ListenableFutureAdapter 062 * ListenableFutureAdapter}.</li> 063 * </ol> 064 * @param request the request, containing method, URI, and headers 065 * @param body the body of the request 066 * @param execution the request execution 067 * @return the response future 068 * @throws IOException in case of I/O errors 069 */ 070 ListenableFuture<ClientHttpResponse> intercept(HttpRequest request, byte[] body, 071 AsyncClientHttpRequestExecution execution) throws IOException; 072 073}