Top Description Constructors Methods
jakarta.servlet.http

public Class HttpServletResponseWrapper

extends ServletResponseWrapper
implements HttpServletResponse
Class Inheritance
All Implemented Interfaces
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse
Known Direct Subclasses
org.apache.catalina.filters.AddDefaultCharsetFilter.ResponseWrapper, org.apache.catalina.filters.CsrfPreventionFilter.CsrfResponseWrapper, org.apache.catalina.filters.ExpiresFilter.XHttpServletResponse, org.apache.catalina.core.ApplicationHttpResponse, jakarta.servlet.http.HttpServlet.NoBodyResponse
Imports
java.io.IOException, java.util.Collection, .Map, java.util.function.Supplier, jakarta.servlet.ServletResponseWrapper

Provides a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped response object.
Since
Servlet 2.3
See Also
jakarta.servlet.http.HttpServletResponse

Constructor Summary

AccessConstructor and Description
public
HttpServletResponseWrapper(HttpServletResponse
The response to be wrapped
response
)

Constructs a response adaptor wrapping the given response.

Method Summary

Modifier and TypeMethod and Description
private HttpServletResponse
public void
addCookie(Cookie
the Cookie to return to the client
cookie
)

Implements jakarta.servlet.http.HttpServletResponse.addCookie.

The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.

public void
addDateHeader(String
the name of the header to set
name
,
long
the additional date value
date
)

Implements jakarta.servlet.http.HttpServletResponse.addDateHeader.

The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object.

public void
addHeader(String
the name of the header
name
,
String
the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

public void
addIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.

public boolean
containsHeader(String
the header name
name
)

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

The default behavior of this method is to call containsHeader(String name) on the wrapped response object.

public String
encodeRedirectURL(String
the url to be encoded.
url
)

Implements jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

The default behavior of this method is to return encodeRedirectURL(String url) on the wrapped response object.

public String
encodeURL(String
the url to be encoded.
url
)

Implements jakarta.servlet.http.HttpServletResponse.encodeURL.

The default behavior of this method is to call encodeURL(String url) on the wrapped response object.

public String
getHeader(String
Header name to look up
name
)

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

Return the value for the specified header, or null if this header has not been set.

public Collection<String>
getHeaderNames()

Implements jakarta.servlet.http.HttpServletResponse.getHeaderNames.

Get the header names set for this HTTP response.

public Collection<String>
getHeaders(String
Header name to look up
name
)

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

Return a Collection of all the header values associated with the specified header name.

public int
getStatus()

Implements jakarta.servlet.http.HttpServletResponse.getStatus.

Get the HTTP status code for this Response.

public Supplier<Map<String, String>>
getTrailerFields()

Overrides default jakarta.servlet.http.HttpServletResponse.getTrailerFields.

Obtain the supplier of the trailer headers.

public void
sendError(int
the error status code
sc
,
String
the descriptive message
msg
)

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.

public void
sendError(int
the error status code
sc
)

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc) on the wrapped response object.

public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
)

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to call sendRedirect(String location) on the wrapped response object.

public void
setDateHeader(String
the name of the header to set
name
,
long
the assigned date value
date
)

Implements jakarta.servlet.http.HttpServletResponse.setDateHeader.

The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.

public void
setHeader(String
the name of the header
name
,
String
the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.

public void
setIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.

public void
setStatus(int
the status code
sc
)

Implements jakarta.servlet.http.HttpServletResponse.setStatus.

The default behavior of this method is to call setStatus(int sc) on the wrapped response object.

public void
setTrailerFields(Supplier<Map<String, String>>
The supplier for the trailer headers
supplier
)

Overrides default jakarta.servlet.http.HttpServletResponse.setTrailerFields.

Configure the supplier of the trailer headers.

Inherited from jakarta.servlet.ServletResponseWrapper:
flushBuffergetBufferSizegetCharacterEncodinggetContentTypegetLocalegetOutputStreamgetResponsegetWriterisCommittedisWrapperForisWrapperForresetresetBuffersetBufferSizesetCharacterEncodingsetContentLengthsetContentLengthLongsetContentTypesetLocalesetResponse

Constructor Detail

HttpServletResponseWrapperback to summary
public HttpServletResponseWrapper(HttpServletResponse response)

Constructs a response adaptor wrapping the given response.

Parameters
response:HttpServletResponse

The response to be wrapped

Exceptions
IllegalArgumentException:
if the response is null

Method Detail

_getHttpServletResponseback to summary
private HttpServletResponse _getHttpServletResponse()
addCookieback to summary
public void addCookie(Cookie cookie)

Implements jakarta.servlet.http.HttpServletResponse.addCookie.

The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.

Parameters
cookie:Cookie

Doc from jakarta.servlet.http.HttpServletResponse.addCookie.

the Cookie to return to the client

Annotations
@Override
addDateHeaderback to summary
public void addDateHeader(String name, long date)

Implements jakarta.servlet.http.HttpServletResponse.addDateHeader.

The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addDateHeader.

the name of the header to set

date:long

Doc from jakarta.servlet.http.HttpServletResponse.addDateHeader.

the additional date value

Annotations
@Override
addHeaderback to summary
public void addHeader(String name, String value)

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addHeader.

the name of the header

value:String

Doc from jakarta.servlet.http.HttpServletResponse.addHeader.

the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

Annotations
@Override
addIntHeaderback to summary
public void addIntHeader(String name, int value)

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addIntHeader.

the name of the header

value:int

Doc from jakarta.servlet.http.HttpServletResponse.addIntHeader.

the assigned integer value

Annotations
@Override
containsHeaderback to summary
public boolean containsHeader(String name)

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

The default behavior of this method is to call containsHeader(String name) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.containsHeader.

the header name

Returns:boolean

Doc from jakarta.servlet.http.HttpServletResponse.containsHeader.

true if the named response header has already been set; false otherwise

Annotations
@Override
encodeRedirectURLback to summary
public String encodeRedirectURL(String url)

Implements jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

The default behavior of this method is to return encodeRedirectURL(String url) on the wrapped response object.

Parameters
url:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

the url to be encoded.

Returns:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

the encoded URL if encoding is needed; the unchanged URL otherwise.

Annotations
@Override
encodeURLback to summary
public String encodeURL(String url)

Implements jakarta.servlet.http.HttpServletResponse.encodeURL.

The default behavior of this method is to call encodeURL(String url) on the wrapped response object.

Parameters
url:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeURL.

the url to be encoded.

Returns:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeURL.

the encoded URL if encoding is needed; the unchanged URL otherwise.

Annotations
@Override
getHeaderback to summary
public String getHeader(String name)

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

Doc from jakarta.servlet.http.HttpServletResponse.getHeader.

Return the value for the specified header, or null if this header has not been set. If more than one value was added for this name, only the first is returned; use getHeaders(String) to retrieve all of them.

The default implementation is to call HttpServletResponse#getHeader(String) on the wrapped HttpServletResponse.

Parameters
name:String

Header name to look up

Returns:String

The first value for the specified header. This is the raw value so if multiple values are specified in the first header then they will be returned as a single header value .

Annotations
@Override
Since
Servlet 3.0
getHeaderNamesback to summary
public Collection<String> getHeaderNames()

Implements jakarta.servlet.http.HttpServletResponse.getHeaderNames.

Doc from jakarta.servlet.http.HttpServletResponse.getHeaderNames.

Get the header names set for this HTTP response.

The default implementation is to call HttpServletResponse#getHeaderNames() on the wrapped HttpServletResponse.

Returns:Collection<String>

The header names set for this HTTP response.

Annotations
@Override
Since
Servlet 3.0
getHeadersback to summary
public Collection<String> getHeaders(String name)

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

Doc from jakarta.servlet.http.HttpServletResponse.getHeaders.

Return a Collection of all the header values associated with the specified header name.

The default implementation is to call HttpServletResponse#getHeaders(String) on the wrapped HttpServletResponse.

Parameters
name:String

Header name to look up

Returns:Collection<String>

The values for the specified header. These are the raw values so if multiple values are specified in a single header that will be returned as a single header value.

Annotations
@Override
Since
Servlet 3.0
getStatusback to summary
public int getStatus()

Implements jakarta.servlet.http.HttpServletResponse.getStatus.

Doc from jakarta.servlet.http.HttpServletResponse.getStatus.

Get the HTTP status code for this Response.

The default implementation is to call HttpServletResponse#getStatus() on the wrapped HttpServletResponse.

Returns:int

The HTTP status code for this Response

Annotations
@Override
Since
Servlet 3.0
getTrailerFieldsback to summary
public Supplier<Map<String, String>> getTrailerFields()

Overrides default jakarta.servlet.http.HttpServletResponse.getTrailerFields.

Doc from jakarta.servlet.http.HttpServletResponse.getTrailerFields.

Obtain the supplier of the trailer headers.
The default implementation returns null.

The default implementation is to call HttpServletResponse#getTrailerFields() on the wrapped HttpServletResponse.

Returns:Supplier<Map<String, String>>

The supplier for the trailer headers

Annotations
@Override
Since
Servlet 4.0
sendErrorback to summary
public void sendError(int sc, String msg) throws IOException

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the error status code

msg:String

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the descriptive message

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

If an input or output exception occurs

sendErrorback to summary
public void sendError(int sc) throws IOException

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the error status code

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

If an input or output exception occurs

sendRedirectback to summary
public void sendRedirect(String location) throws IOException

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to call sendRedirect(String location) on the wrapped response object.

Parameters
location:String

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the redirect location URL (may be absolute or relative)

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

If an input or output exception occurs

setDateHeaderback to summary
public void setDateHeader(String name, long date)

Implements jakarta.servlet.http.HttpServletResponse.setDateHeader.

The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setDateHeader.

the name of the header to set

date:long

Doc from jakarta.servlet.http.HttpServletResponse.setDateHeader.

the assigned date value

Annotations
@Override
setHeaderback to summary
public void setHeader(String name, String value)

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setHeader.

the name of the header

value:String

Doc from jakarta.servlet.http.HttpServletResponse.setHeader.

the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

Annotations
@Override
setIntHeaderback to summary
public void setIntHeader(String name, int value)

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setIntHeader.

the name of the header

value:int

Doc from jakarta.servlet.http.HttpServletResponse.setIntHeader.

the assigned integer value

Annotations
@Override
setStatusback to summary
public void setStatus(int sc)

Implements jakarta.servlet.http.HttpServletResponse.setStatus.

The default behavior of this method is to call setStatus(int sc) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.setStatus.

the status code

Annotations
@Override
setTrailerFieldsback to summary
public void setTrailerFields(Supplier<Map<String, String>> supplier)

Overrides default jakarta.servlet.http.HttpServletResponse.setTrailerFields.

Doc from jakarta.servlet.http.HttpServletResponse.setTrailerFields.

Configure the supplier of the trailer headers. The supplier will be called in the scope of the thread that completes the response.
Trailers that don't meet the requirements of RFC 7230, section 4.1.2 will be ignored.
The default implementation is a NO-OP.

The default implementation is to call HttpServletResponse#setTrailerFields(Supplier) on the wrapped HttpServletResponse.

Parameters
supplier:Supplier<Map<String, String>>

The supplier for the trailer headers

Annotations
@Override
Since
Servlet 4.0