1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. * ====================================================================
  55. *
  56. * This source code implements specifications defined by the Java
  57. * Community Process. In order to remain compliant with the specification
  58. * DO NOT add / change / or delete method signatures!
  59. */
  60. package javax.servlet;
  61. import java.io.BufferedReader;
  62. import java.io.IOException;
  63. import java.io.UnsupportedEncodingException;
  64. import java.util.Enumeration;
  65. import java.util.Locale;
  66. import java.util.Map;
  67. /**
  68. *
  69. * Provides a convenient implementation of the ServletRequest interface that
  70. * can be subclassed by developers wishing to adapt the request to a Servlet.
  71. * This class implements the Wrapper or Decorator pattern. Methods default to
  72. * calling through to the wrapped request object.
  73. * @since v 2.3
  74. *
  75. *
  76. *
  77. * @see javax.servlet.ServletRequest
  78. *
  79. */
  80. public class ServletRequestWrapper implements ServletRequest {
  81. private ServletRequest request;
  82. /**
  83. * Creates a ServletRequest adaptor wrapping the given request object.
  84. * @throws java.lang.IllegalArgumentException if the request is null
  85. */
  86. public ServletRequestWrapper(ServletRequest request) {
  87. if (request == null) {
  88. throw new IllegalArgumentException("Request cannot be null");
  89. }
  90. this.request = request;
  91. }
  92. /**
  93. * Return the wrapped request object.
  94. */
  95. public ServletRequest getRequest() {
  96. return this.request;
  97. }
  98. /**
  99. * Sets the request object being wrapped.
  100. * @throws java.lang.IllegalArgumentException if the request is null.
  101. */
  102. public void setRequest(ServletRequest request) {
  103. if (request == null) {
  104. throw new IllegalArgumentException("Request cannot be null");
  105. }
  106. this.request = request;
  107. }
  108. /**
  109. *
  110. * The default behavior of this method is to call getAttribute(String name)
  111. * on the wrapped request object.
  112. */
  113. public Object getAttribute(String name) {
  114. return this.request.getAttribute(name);
  115. }
  116. /**
  117. * The default behavior of this method is to return getAttributeNames()
  118. * on the wrapped request object.
  119. */
  120. public Enumeration getAttributeNames() {
  121. return this.request.getAttributeNames();
  122. }
  123. /**
  124. * The default behavior of this method is to return getCharacterEncoding()
  125. * on the wrapped request object.
  126. */
  127. public String getCharacterEncoding() {
  128. return this.request.getCharacterEncoding();
  129. }
  130. /**
  131. * The default behavior of this method is to set the character encoding
  132. * on the wrapped request object.
  133. */
  134. public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException {
  135. this.request.setCharacterEncoding(enc);
  136. }
  137. /**
  138. * The default behavior of this method is to return getContentLength()
  139. * on the wrapped request object.
  140. */
  141. public int getContentLength() {
  142. return this.request.getContentLength();
  143. }
  144. /**
  145. * The default behavior of this method is to return getContentType()
  146. * on the wrapped request object.
  147. */
  148. public String getContentType() {
  149. return this.request.getContentType();
  150. }
  151. /**
  152. * The default behavior of this method is to return getInputStream()
  153. * on the wrapped request object.
  154. */
  155. public ServletInputStream getInputStream() throws IOException {
  156. return this.request.getInputStream();
  157. }
  158. /**
  159. * The default behavior of this method is to return getParameter(String name)
  160. * on the wrapped request object.
  161. */
  162. public String getParameter(String name) {
  163. return this.request.getParameter(name);
  164. }
  165. /**
  166. * The default behavior of this method is to return getParameterMap()
  167. * on the wrapped request object.
  168. */
  169. public Map getParameterMap() {
  170. return this.request.getParameterMap();
  171. }
  172. /**
  173. * The default behavior of this method is to return getParameterNames()
  174. * on the wrapped request object.
  175. */
  176. public Enumeration getParameterNames() {
  177. return this.request.getParameterNames();
  178. }
  179. /**
  180. * The default behavior of this method is to return getParameterValues(String name)
  181. * on the wrapped request object.
  182. */
  183. public String[] getParameterValues(String name) {
  184. return this.request.getParameterValues(name);
  185. }
  186. /**
  187. * The default behavior of this method is to return getProtocol()
  188. * on the wrapped request object.
  189. */
  190. public String getProtocol() {
  191. return this.request.getProtocol();
  192. }
  193. /**
  194. * The default behavior of this method is to return getScheme()
  195. * on the wrapped request object.
  196. */
  197. public String getScheme() {
  198. return this.request.getScheme();
  199. }
  200. /**
  201. * The default behavior of this method is to return getServerName()
  202. * on the wrapped request object.
  203. */
  204. public String getServerName() {
  205. return this.request.getServerName();
  206. }
  207. /**
  208. * The default behavior of this method is to return getServerPort()
  209. * on the wrapped request object.
  210. */
  211. public int getServerPort() {
  212. return this.request.getServerPort();
  213. }
  214. /**
  215. * The default behavior of this method is to return getReader()
  216. * on the wrapped request object.
  217. */
  218. public BufferedReader getReader() throws IOException {
  219. return this.request.getReader();
  220. }
  221. /**
  222. * The default behavior of this method is to return getRemoteAddr()
  223. * on the wrapped request object.
  224. */
  225. public String getRemoteAddr() {
  226. return this.request.getRemoteAddr();
  227. }
  228. /**
  229. * The default behavior of this method is to return getRemoteHost()
  230. * on the wrapped request object.
  231. */
  232. public String getRemoteHost() {
  233. return this.request.getRemoteHost();
  234. }
  235. /**
  236. * The default behavior of this method is to return setAttribute(String name, Object o)
  237. * on the wrapped request object.
  238. */
  239. public void setAttribute(String name, Object o) {
  240. this.request.setAttribute(name, o);
  241. }
  242. /**
  243. * The default behavior of this method is to call removeAttribute(String name)
  244. * on the wrapped request object.
  245. */
  246. public void removeAttribute(String name) {
  247. this.request.removeAttribute(name);
  248. }
  249. /**
  250. * The default behavior of this method is to return getLocale()
  251. * on the wrapped request object.
  252. */
  253. public Locale getLocale() {
  254. return this.request.getLocale();
  255. }
  256. /**
  257. * The default behavior of this method is to return getLocales()
  258. * on the wrapped request object.
  259. */
  260. public Enumeration getLocales() {
  261. return this.request.getLocales();
  262. }
  263. /**
  264. * The default behavior of this method is to return isSecure()
  265. * on the wrapped request object.
  266. */
  267. public boolean isSecure() {
  268. return this.request.isSecure();
  269. }
  270. /**
  271. * The default behavior of this method is to return getRequestDispatcher(String path)
  272. * on the wrapped request object.
  273. */
  274. public RequestDispatcher getRequestDispatcher(String path) {
  275. return this.request.getRequestDispatcher(path);
  276. }
  277. /**
  278. * The default behavior of this method is to return getRealPath(String path)
  279. * on the wrapped request object.
  280. */
  281. public String getRealPath(String path) {
  282. return this.request.getRealPath(path);
  283. }
  284. }