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.http.client; 018 019import java.net.URI; 020import java.util.Collections; 021import java.util.List; 022 023import org.springframework.http.HttpMethod; 024 025/** 026 * Wrapper for a {@link AsyncClientHttpRequestFactory} that has support for 027 * {@link AsyncClientHttpRequestInterceptor}s. 028 * 029 * @author Jakub Narloch 030 * @since 4.3 031 * @see InterceptingAsyncClientHttpRequest 032 */ 033public class InterceptingAsyncClientHttpRequestFactory implements AsyncClientHttpRequestFactory { 034 035 private AsyncClientHttpRequestFactory delegate; 036 037 private List<AsyncClientHttpRequestInterceptor> interceptors; 038 039 040 /** 041 * Create new instance of {@link InterceptingAsyncClientHttpRequestFactory} 042 * with delegated request factory and list of interceptors. 043 * @param delegate the request factory to delegate to 044 * @param interceptors the list of interceptors to use 045 */ 046 public InterceptingAsyncClientHttpRequestFactory(AsyncClientHttpRequestFactory delegate, 047 List<AsyncClientHttpRequestInterceptor> interceptors) { 048 049 this.delegate = delegate; 050 this.interceptors = (interceptors != null ? interceptors : Collections.<AsyncClientHttpRequestInterceptor>emptyList()); 051 } 052 053 054 @Override 055 public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod method) { 056 return new InterceptingAsyncClientHttpRequest(this.delegate, this.interceptors, uri, method); 057 } 058 059}