001/* 002 * Copyright 2002-2015 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; 020import java.net.URI; 021 022import org.springframework.http.HttpMethod; 023import org.springframework.util.Assert; 024 025/** 026 * Abstract base class for {@link ClientHttpRequestFactory} implementations 027 * that decorate another request factory. 028 * 029 * @author Arjen Poutsma 030 * @since 3.1 031 */ 032public abstract class AbstractClientHttpRequestFactoryWrapper implements ClientHttpRequestFactory { 033 034 private final ClientHttpRequestFactory requestFactory; 035 036 037 /** 038 * Create a {@code AbstractClientHttpRequestFactoryWrapper} wrapping the given request factory. 039 * @param requestFactory the request factory to be wrapped 040 */ 041 protected AbstractClientHttpRequestFactoryWrapper(ClientHttpRequestFactory requestFactory) { 042 Assert.notNull(requestFactory, "ClientHttpRequestFactory must not be null"); 043 this.requestFactory = requestFactory; 044 } 045 046 047 /** 048 * This implementation simply calls {@link #createRequest(URI, HttpMethod, ClientHttpRequestFactory)} 049 * with the wrapped request factory provided to the 050 * {@linkplain #AbstractClientHttpRequestFactoryWrapper(ClientHttpRequestFactory) constructor}. 051 */ 052 @Override 053 public final ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { 054 return createRequest(uri, httpMethod, this.requestFactory); 055 } 056 057 /** 058 * Create a new {@link ClientHttpRequest} for the specified URI and HTTP method 059 * by using the passed-on request factory. 060 * <p>Called from {@link #createRequest(URI, HttpMethod)}. 061 * @param uri the URI to create a request for 062 * @param httpMethod the HTTP method to execute 063 * @param requestFactory the wrapped request factory 064 * @return the created request 065 * @throws IOException in case of I/O errors 066 */ 067 protected abstract ClientHttpRequest createRequest( 068 URI uri, HttpMethod httpMethod, ClientHttpRequestFactory requestFactory) throws IOException; 069 070}