2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package javax.servlet.http;
19 import java.io.IOException;
20 import java.util.Collection;
22 import javax.servlet.ServletResponseWrapper;
25 * Provides a convenient implementation of the HttpServletResponse interface
26 * that can be subclassed by developers wishing to adapt the response from a
27 * Servlet. This class implements the Wrapper or Decorator pattern. Methods
28 * default to calling through to the wrapped response object.
31 * @see javax.servlet.http.HttpServletResponse
33 public class HttpServletResponseWrapper extends ServletResponseWrapper
34 implements HttpServletResponse {
37 * Constructs a response adaptor wrapping the given response.
39 * @throws java.lang.IllegalArgumentException
40 * if the response is null
42 public HttpServletResponseWrapper(HttpServletResponse response) {
46 private HttpServletResponse _getHttpServletResponse() {
47 return (HttpServletResponse) super.getResponse();
51 * The default behavior of this method is to call addCookie(Cookie cookie)
52 * on the wrapped response object.
55 public void addCookie(Cookie cookie) {
56 this._getHttpServletResponse().addCookie(cookie);
60 * The default behavior of this method is to call containsHeader(String
61 * name) on the wrapped response object.
64 public boolean containsHeader(String name) {
65 return this._getHttpServletResponse().containsHeader(name);
69 * The default behavior of this method is to call encodeURL(String url) on
70 * the wrapped response object.
73 public String encodeURL(String url) {
74 return this._getHttpServletResponse().encodeURL(url);
78 * The default behavior of this method is to return encodeRedirectURL(String
79 * url) on the wrapped response object.
82 public String encodeRedirectURL(String url) {
83 return this._getHttpServletResponse().encodeRedirectURL(url);
87 * The default behavior of this method is to call encodeUrl(String url) on
88 * the wrapped response object.
90 * @deprecated As of Version 3.0 of the Java Servlet API
93 @SuppressWarnings("dep-ann")
94 // Spec API does not use @Deprecated
95 public String encodeUrl(String url) {
96 return this._getHttpServletResponse().encodeUrl(url);
100 * The default behavior of this method is to return encodeRedirectUrl(String
101 * url) on the wrapped response object.
103 * @deprecated As of Version 3.0 of the Java Servlet API
106 @SuppressWarnings("dep-ann")
107 // Spec API does not use @Deprecated
108 public String encodeRedirectUrl(String url) {
109 return this._getHttpServletResponse().encodeRedirectUrl(url);
113 * The default behavior of this method is to call sendError(int sc, String
114 * msg) on the wrapped response object.
117 public void sendError(int sc, String msg) throws IOException {
118 this._getHttpServletResponse().sendError(sc, msg);
122 * The default behavior of this method is to call sendError(int sc) on the
123 * wrapped response object.
126 public void sendError(int sc) throws IOException {
127 this._getHttpServletResponse().sendError(sc);
131 * The default behavior of this method is to return sendRedirect(String
132 * location) on the wrapped response object.
135 public void sendRedirect(String location) throws IOException {
136 this._getHttpServletResponse().sendRedirect(location);
140 * The default behavior of this method is to call setDateHeader(String name,
141 * long date) on the wrapped response object.
144 public void setDateHeader(String name, long date) {
145 this._getHttpServletResponse().setDateHeader(name, date);
149 * The default behavior of this method is to call addDateHeader(String name,
150 * long date) on the wrapped response object.
153 public void addDateHeader(String name, long date) {
154 this._getHttpServletResponse().addDateHeader(name, date);
158 * The default behavior of this method is to return setHeader(String name,
159 * String value) on the wrapped response object.
162 public void setHeader(String name, String value) {
163 this._getHttpServletResponse().setHeader(name, value);
167 * The default behavior of this method is to return addHeader(String name,
168 * String value) on the wrapped response object.
171 public void addHeader(String name, String value) {
172 this._getHttpServletResponse().addHeader(name, value);
176 * The default behavior of this method is to call setIntHeader(String name,
177 * int value) on the wrapped response object.
180 public void setIntHeader(String name, int value) {
181 this._getHttpServletResponse().setIntHeader(name, value);
185 * The default behavior of this method is to call addIntHeader(String name,
186 * int value) on the wrapped response object.
189 public void addIntHeader(String name, int value) {
190 this._getHttpServletResponse().addIntHeader(name, value);
194 * The default behavior of this method is to call setStatus(int sc) on the
195 * wrapped response object.
198 public void setStatus(int sc) {
199 this._getHttpServletResponse().setStatus(sc);
203 * The default behavior of this method is to call setStatus(int sc, String
204 * sm) on the wrapped response object.
206 * @deprecated As of Version 3.0 of the Java Servlet API
209 @SuppressWarnings("dep-ann")
210 // Spec API does not use @Deprecated
211 public void setStatus(int sc, String sm) {
212 this._getHttpServletResponse().setStatus(sc, sm);
218 * The default implementation is to call
219 * {@link HttpServletResponse#getStatus()}
220 * on the wrapper {@link HttpServletResponse}.
225 public int getStatus() {
226 return this._getHttpServletResponse().getStatus();
232 * The default implementation is to call
233 * {@link HttpServletResponse#getHeader(String)}
234 * on the wrapper {@link HttpServletResponse}.
239 public String getHeader(String name) {
240 return this._getHttpServletResponse().getHeader(name);
246 * The default implementation is to call
247 * {@link HttpServletResponse#getHeaders(String)}
248 * on the wrapper {@link HttpServletResponse}.
253 public Collection<String> getHeaders(String name) {
254 return this._getHttpServletResponse().getHeaders(name);
260 * The default implementation is to call
261 * {@link HttpServletResponse#getHeaderNames()}
262 * on the wrapper {@link HttpServletResponse}.
267 public Collection<String> getHeaderNames() {
268 return this._getHttpServletResponse().getHeaderNames();