Top Description Inners Fields Constructors Methods
org.apache.catalina.connector

public Class Response

extends Object
implements HttpServletResponse
Class Inheritance
All Implemented Interfaces
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse
Imports
java.io.IOException, .PrintWriter, .UnsupportedEncodingException, java.net.MalformedURLException, .URI, .URISyntaxException, .URL, java.nio.charset.Charset, java.security.AccessController, .PrivilegedAction, .PrivilegedActionException, .PrivilegedExceptionAction, java.util.ArrayList, .Arrays, .Collection, .Enumeration, .LinkedHashSet, .List, .Locale, .Map, .Set, java.util.function.Supplier, jakarta.servlet.ServletOutputStream, .ServletResponse, .SessionTrackingMode, jakarta.servlet.http.Cookie, .HttpServletRequest, .HttpServletResponse, .HttpServletResponseWrapper, org.apache.catalina.Context, .Session, org.apache.catalina.security.SecurityUtil, org.apache.catalina.util.SessionConfig, org.apache.coyote.ActionCode, .ContinueResponseTiming, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.CharChunk, .UEncoder, .UEncoder.SafeCharsSet, .UriUtil, org.apache.tomcat.util.http.FastHttpDateFormat, .MimeHeaders, org.apache.tomcat.util.http.parser.MediaTypeCache, org.apache.tomcat.util.res.StringManager, org.apache.tomcat.util.security.Escape

Wrapper object for the Coyote response.
Authors
Remy Maucherat, Craig R. McClanahan

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
protected boolean
appCommitted

The application commit flag.

private HttpServletResponse
private final List<Cookie>
protected Response
coyoteResponse

Coyote response.

protected ResponseFacade
facade

The facade associated with this response.

protected boolean
included

The included flag.

private boolean
isCharacterEncodingSet

The characterEncoding flag

private static final Log
private static final MediaTypeCache
protected final OutputBuffer
outputBuffer

The associated output buffer.

protected CoyoteOutputStream
outputStream

The associated output stream.

protected final CharChunk
redirectURLCC

Recyclable buffer to hold the redirect URL.

protected Request
request

The request with which this response is associated.

protected static final StringManager
protected final UEncoder
urlEncoder

URL encoder.

protected boolean
usingOutputStream

Using output stream flag.

protected boolean
usingWriter

Using writer flag.

protected CoyoteWriter
writer

The associated writer.

Constructor Summary

AccessConstructor and Description
public
public
Response(int outputBufferSize)

Method Summary

Modifier and TypeMethod and Description
public void
addCookie(final Cookie
Cookie to be added
cookie
)

Implements jakarta.servlet.http.HttpServletResponse.addCookie.

Add the specified Cookie to those that will be included with this Response.

public void
addDateHeader(String
Name of the header to set
name
,
long
Date value to be set
value
)

Implements jakarta.servlet.http.HttpServletResponse.addDateHeader.

Add the specified date header to the specified value.

public void
addHeader(String
Name of the header to set
name
,
String
Value to be set
value
)

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

Add the specified header to the specified value.

private void
addHeader(String name, String value, Charset charset)

public void
addIntHeader(String
Name of the header to set
name
,
int
Integer value to be set
value
)

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

Add the specified integer header to the specified value.

public void
addSessionCookieInternal(final Cookie
The new session cookie to add the response
cookie
)

Special method for adding a session cookie as we should be overriding any previous.

private boolean

Returns:

true if the header is special, no need to set the header.
checkSpecialHeader
(String name, String value)

An extended version of this exists in org.apache.coyote.Response.

public boolean

Returns:

true if the header has been set
containsHeader
(String
Name of the header to check
name
)

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

Has the specified header been set already in this response?

private void
copyChars(char[] c, int dest, int src, int len)

private static boolean
doIsEncodeable(Context context, Request hreq, Session session, String location)

public String

Returns:

true if the URL was encoded
encodeRedirectURL
(String
URL to be encoded
url
)

Implements jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

Encode the session identifier associated with this response into the specified redirect URL, if necessary.

public String

Returns:

true if the URL was encoded
encodeURL
(String
URL to be encoded
url
)

Implements jakarta.servlet.http.HttpServletResponse.encodeURL.

Encode the session identifier associated with this response into the specified URL, if necessary.

public void
finishResponse()

Perform whatever actions are required to flush and close the output stream or writer, in a single operation.

public void
flushBuffer()

Implements jakarta.servlet.ServletResponse.flushBuffer.

Flush the buffer and commit this response.

public String
public int

Returns:

the actual buffer size used for this Response.
getBufferSize
()

Implements jakarta.servlet.ServletResponse.getBufferSize.

Returns the actual buffer size used for the response.

public long

Returns:

the number of bytes the actually written to the socket. This includes chunking, compression, etc. but excludes headers.
getBytesWritten
(boolean
if true will perform a buffer flush first
flush
)

public String

Returns:

the character encoding used for this Response.
getCharacterEncoding
()

Implements jakarta.servlet.ServletResponse.getCharacterEncoding.

Returns the name of the character encoding (MIME charset) used for the body sent in this response.

public int

Returns:

the content length that was set or calculated for this Response.
getContentLength
()

public String

Returns:

the content type that was set or calculated for this response, or null if no content type was set.
getContentType
()

Implements jakarta.servlet.ServletResponse.getContentType.

Returns the content type used for the MIME body sent in this response.

public long

Returns:

the number of bytes the application has actually written to the output stream. This excludes chunking, compression, etc. as well as headers.
getContentWritten
()

public Context

Returns:

the Context within which this Request is being processed.
getContext
()

public List<Cookie>
public Response

Returns:

the Coyote response.
getCoyoteResponse
()

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 Locale

Returns:

the Locale assigned to this response.
getLocale
()

Implements jakarta.servlet.ServletResponse.getLocale.

Returns the locale specified for this response using the setLocale method.

public String

Returns:

the error message that was set with sendError() for this Response.
getMessage
()

public ServletOutputStream

Returns:

the servlet output stream associated with this Response.
getOutputStream
()

Implements jakarta.servlet.ServletResponse.getOutputStream.

Returns a ServletOutputStream suitable for writing binary data in the response.

public PrintWriter

Returns:

Writer which can be used for error reports. If the response is not an error report returned using sendError or triggered by an unexpected exception thrown during the servlet processing (and only in that case), null will be returned if the response stream has already been used.
getReporter
()

Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.

public Request

Returns:

the Request with which this Response is associated.
getRequest
()

public HttpServletResponse

Returns:

the ServletResponse for which this object is the facade.
getResponse
()

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 PrintWriter

Returns:

the writer associated with this Response.
getWriter
()

Implements jakarta.servlet.ServletResponse.getWriter.

Returns a PrintWriter object that can send character text to the client.

private boolean

Returns:

true if the URL has a path
hasPath
(String
the URL that will be checked
uri
)

Determine if an absolute URL has a path component.

public boolean

Returns:

true if the application has committed the response
isAppCommitted
()

Application commit flag accessor.

public boolean

Returns:

true if the response has been closed
isClosed
()

Closed flag accessor.

public boolean

Returns:

true if the response has been committed
isCommitted
()

Implements jakarta.servlet.ServletResponse.isCommitted.

Has the output of this response already been committed?

protected boolean

Returns:

true if the URL should be encoded
isEncodeable
(final String
Absolute URL to be validated
location
)

Return true if the specified URL should be encoded with a session identifier.

public boolean

Returns:

true if the response has encountered an error
isError
()

Error flag accessor.

public boolean
public boolean

Returns:

true if the response is suspended
isSuspended
()

Suspended flag accessor.

private void
normalize(CharChunk
the char chunk containing the chars to normalize
cc
)

Removes /./ and /../ sequences from absolute URLs.

public void
recycle()

Release all object references, and initialize instance variables, in preparation for reuse of this object.

public void
reset()

Implements jakarta.servlet.ServletResponse.reset.

Clear any content written to the buffer.

public void
resetBuffer()

Implements jakarta.servlet.ServletResponse.resetBuffer.

Reset the data buffer but not any status or header information.

public void
resetBuffer(boolean
true if the internal usingWriter, usingOutputStream, isCharacterEncodingSet flags should also be reset
resetWriterStreamFlags
)

Reset the data buffer and the using Writer/Stream flags but not any status or header information.

public void
sendAcknowledgement(ContinueResponseTiming
Indicates when the request for the ACK originated so it can be compared with the configured timing for ACK responses.
continueResponseTiming
)

Send an acknowledgement of a request.

public void
sendError(int
HTTP status code to send
status
)

Implements jakarta.servlet.http.HttpServletResponse.sendError.

Send an error response with the specified status and a default message.

public void
sendError(int
HTTP status code to send
status
,
String
Corresponding message to send
message
)

Implements jakarta.servlet.http.HttpServletResponse.sendError.

Send an error response with the specified status and message.

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

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

Sends a redirect response to the client using the specified redirect location URL with the status code SC_FOUND 302 (Found), clears the response buffer and commits the response.

public void
sendRedirect(String
Location URL to redirect to
location
,
int
HTTP status code that will be sent
status
)

Internal method that allows a redirect to be sent with a status other than HttpServletResponse#SC_FOUND (302).

public void
setAppCommitted(boolean
The new application committed flag value
appCommitted
)

Set the application commit flag.

public void
setBufferSize(int
The new buffer size
size
)

Implements jakarta.servlet.ServletResponse.setBufferSize.

Set the buffer size to be used for this Response.

public void
setCharacterEncoding(String
String containing the name of the character encoding.
encoding
)

Implements jakarta.servlet.ServletResponse.setCharacterEncoding.

Overrides the name of the character encoding used in the body of the request.

public void
setContentLength(int
The new content length
length
)

Implements jakarta.servlet.ServletResponse.setContentLength.

Set the content length (in bytes) for this Response.

public void
setContentLengthLong(long
an integer specifying the length of the content being returned to the client; sets the Content-Length header
length
)

Implements jakarta.servlet.ServletResponse.setContentLengthLong.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

public void
setContentType(String
The new content type
type
)

Implements jakarta.servlet.ServletResponse.setContentType.

Set the content type for this Response.

public void
setCoyoteResponse(Response
The Coyote response
coyoteResponse
)

Set the Coyote response.

public void
setDateHeader(String
Name of the header to set
name
,
long
Date value to be set
value
)

Implements jakarta.servlet.http.HttpServletResponse.setDateHeader.

Set the specified date header to the specified value.

public boolean

Returns:

false if the error flag was already set
setError
()
Deprecated This method will be changed to return void in Tomcat 11 onwards

Set the error flag.

public boolean
public void
setHeader(String
Name of the header to set
name
,
String
Value to be set
value
)

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

Set the specified header to the specified value.

public void
setIntHeader(String
Name of the header to set
name
,
int
Integer value to be set
value
)

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

Set the specified integer header to the specified value.

public void
setLocale(Locale
The new locale
locale
)

Implements jakarta.servlet.ServletResponse.setLocale.

Set the Locale that is appropriate for this response, including setting the appropriate character encoding.

public void
setRequest(Request
The new associated request
request
)

Set the Request with which this Response is associated.

public void
setResponse(HttpServletResponse
The wrapped response to pass to the application
applicationResponse
)

Set a wrapped HttpServletResponse to pass to the application.

public void
setStatus(int
The new HTTP status
status
)

Implements jakarta.servlet.http.HttpServletResponse.setStatus.

Set the HTTP status to be returned with this response.

public void
setSuspended(boolean
The new suspended flag value
suspended
)

Set the suspended flag.

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.

protected String

Returns:

the encoded URL
toAbsolute
(String
URL to be (possibly) converted and then returned
location
)

Convert (if necessary) and return the absolute URL that represents the resource referenced by this possibly relative URL.

protected String

Returns:

the encoded URL
toEncoded
(String
URL to be encoded with the session id
url
,
String
Session id to be included in the encoded URL
sessionId
)

Return the specified URL with the specified session identifier suitably encoded.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait