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