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.support; 018 019import java.net.URI; 020 021import org.springframework.http.HttpHeaders; 022import org.springframework.http.HttpMethod; 023import org.springframework.http.HttpRequest; 024import org.springframework.util.Assert; 025 026/** 027 * Provides a convenient implementation of the {@link HttpRequest} interface 028 * that can be overridden to adapt the request. 029 * 030 * <p>These methods default to calling through to the wrapped request object. 031 * 032 * @author Arjen Poutsma 033 * @since 3.1 034 */ 035public class HttpRequestWrapper implements HttpRequest { 036 037 private final HttpRequest request; 038 039 040 /** 041 * Create a new {@code HttpRequest} wrapping the given request object. 042 * @param request the request object to be wrapped 043 */ 044 public HttpRequestWrapper(HttpRequest request) { 045 Assert.notNull(request, "HttpRequest must not be null"); 046 this.request = request; 047 } 048 049 050 /** 051 * Return the wrapped request. 052 */ 053 public HttpRequest getRequest() { 054 return this.request; 055 } 056 057 /** 058 * Return the method of the wrapped request. 059 */ 060 @Override 061 public HttpMethod getMethod() { 062 return this.request.getMethod(); 063 } 064 065 /** 066 * Return the URI of the wrapped request. 067 */ 068 @Override 069 public URI getURI() { 070 return this.request.getURI(); 071 } 072 073 /** 074 * Return the headers of the wrapped request. 075 */ 076 @Override 077 public HttpHeaders getHeaders() { 078 return this.request.getHeaders(); 079 } 080 081}