public class Response extends Object implements javax.servlet.http.HttpServletResponse
Modifier and Type | Field and Description |
---|---|
protected boolean |
appCommitted
The application commit flag.
|
protected javax.servlet.ServletOutputStream |
applicationOutputStream
Application output stream.
|
protected PrintWriter |
applicationWriter
Using writer flag.
|
protected Connector |
connector
Associated Catalina connector.
|
protected ArrayList |
cookies
The set of Cookies associated with this Response.
|
protected Response |
coyoteResponse
Coyote response.
|
protected boolean |
error
The error flag.
|
protected ResponseFacade |
facade
The facade associated with this response.
|
protected SimpleDateFormat |
format
The date format we will use for creating date headers.
|
protected boolean |
included
The included flag.
|
protected static String |
info
Descriptive information about this Response implementation.
|
protected OutputBuffer |
outputBuffer
The associated output buffer.
|
protected CoyoteOutputStream |
outputStream
The associated output stream.
|
protected CharChunk |
redirectURLCC
Recyclable buffer to hold the redirect URL.
|
protected Request |
request
The request with which this response is associated.
|
protected UEncoder |
urlEncoder
URL encoder.
|
protected boolean |
usingOutputStream
Using output stream flag.
|
protected boolean |
usingWriter
Using writer flag.
|
protected CoyoteWriter |
writer
The associated writer.
|
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
Constructor and Description |
---|
Response() |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Add the specified Cookie to those that will be included with
this Response.
|
void |
addCookieInternal(javax.servlet.http.Cookie cookie)
Add the specified Cookie to those that will be included with
this Response.
|
void |
addDateHeader(String name,
long value)
Add the specified date header to the specified value.
|
void |
addHeader(String name,
String value)
Add the specified header to the specified value.
|
void |
addIntHeader(String name,
int value)
Add the specified integer header to the specified value.
|
void |
clearEncoders()
Clear cached encoders (to save memory for event or async requests).
|
void |
clearOutputStream()
Clear output stream.
|
boolean |
containsHeader(String name)
Has the specified header been set already in this response?
|
javax.servlet.ServletOutputStream |
createOutputStream()
Create and return a ServletOutputStream to write the content
associated with this Response.
|
String |
encodeRedirectUrl(String url)
Deprecated.
As of Version 2.1 of the Java Servlet API, use
encodeRedirectURL() instead. |
String |
encodeRedirectURL(String url)
Encode the session identifier associated with this response
into the specified redirect URL, if necessary.
|
String |
encodeUrl(String url)
Deprecated.
As of Version 2.1 of the Java Servlet API, use
encodeURL() instead. |
String |
encodeURL(String url)
Encode the session identifier associated with this response
into the specified URL, if necessary.
|
void |
finishResponse()
Perform whatever actions are required to flush and close the output
stream or writer, in a single operation.
|
void |
flushBuffer()
Flush the buffer and commit this response.
|
int |
getBufferSize()
Return the actual buffer size used for this Response.
|
String |
getCharacterEncoding()
Return the character encoding used for this Response.
|
Connector |
getConnector()
Return the Connector through which this Request was received.
|
int |
getContentCount()
Return the number of bytes actually written to the output stream.
|
long |
getContentCountLong()
Return the number of bytes actually written to the output stream.
|
int |
getContentLength()
Return the content length that was set or calculated for this Response.
|
String |
getContentType()
Return the content type that was set or calculated for this response,
or
null if no content type was set. |
javax.servlet.http.Cookie[] |
getCookies()
Return an array of all cookies set for this response, or
a zero-length array if no cookies have been set.
|
Response |
getCoyoteResponse()
Get the Coyote response.
|
String |
getHeader(String name)
Return the value for the specified header, or
null if this
header has not been set. |
Collection<String> |
getHeaderNames()
Return an array of all the header names set for this response, or
a zero-length array if no headers have been set.
|
String[] |
getHeaderNamesArray()
Return an array of all the header names set for this response, or
a zero-length array if no headers have been set.
|
Collection<String> |
getHeaders(String name)
Return an array of all the header values associated with the
specified header name, or an zero-length array if there are no such
header values.
|
String[] |
getHeaderValues(String name)
Return an array of all the header values associated with the
specified header name, or an zero-length array if there are no such
header values.
|
boolean |
getIncluded()
Return the "processing inside an include" flag.
|
String |
getInfo()
Return descriptive information about this Response implementation and
the corresponding version number, in the format
<description>/<version> . |
Locale |
getLocale()
Return the Locale assigned to this response.
|
String |
getMessage()
Return the error message that was set with
sendError()
for this Response. |
javax.servlet.ServletOutputStream |
getOutputStream()
Return the servlet output stream associated with this Response.
|
PrintWriter |
getReporter()
Return a PrintWriter that can be used to render error messages,
regardless of whether a stream or writer has already been acquired.
|
Request |
getRequest()
Return the Request with which this Response is associated.
|
javax.servlet.http.HttpServletResponse |
getResponse()
Return the
ServletResponse for which this object
is the facade. |
int |
getStatus()
Return the HTTP status code associated with this Response.
|
OutputStream |
getStream()
Return the output stream associated with this Response.
|
WriteListener |
getWriteListener() |
PrintWriter |
getWriter()
Return the writer associated with this Response.
|
boolean |
isAppCommitted()
Application commit flag accessor.
|
boolean |
isClosed()
Closed flag accessor.
|
boolean |
isCommitted()
Has the output of this response already been committed?
|
protected boolean |
isEncodeable(String location)
Return
true if the specified URL should be encoded with
a session identifier. |
boolean |
isError()
Error flag accessor.
|
boolean |
isSuspended()
Suspended flag accessor.
|
boolean |
isWriteable()
Return true if bytes are available.
|
void |
recycle()
Release all object references, and initialize instance variables, in
preparation for reuse of this object.
|
void |
reset()
Clear any content written to the buffer.
|
void |
reset(int status,
String message)
Reset this response, and specify the values for the HTTP status code
and corresponding message.
|
void |
resetBuffer()
Reset the data buffer but not any status or header information.
|
void |
resetBuffer(boolean resetWriterStreamFlags)
Reset the data buffer and the using Writer/Stream flags but not any
status or header information.
|
void |
sendAcknowledgement()
Send an acknowledgment of a request.
|
void |
sendError(int status)
Send an error response with the specified status and a
default message.
|
void |
sendError(int status,
String message)
Send an error response with the specified status and message.
|
void |
sendFile(String path,
String absolutePath,
long start,
long end) |
void |
sendRedirect(String location)
Send a temporary redirect to the specified redirect location URL.
|
void |
sendUpgrade() |
void |
setAppCommitted(boolean appCommitted)
Set the application commit flag.
|
void |
setBufferSize(int size)
Set the buffer size to be used for this Response.
|
void |
setCharacterEncoding(String charset) |
void |
setConnector(Connector connector)
Set the Connector through which this Request was received.
|
void |
setContentLength(int length)
Set the content length (in bytes) for this Response.
|
void |
setContentLengthLong(long length) |
void |
setContentType(String type)
Set the content type for this Response.
|
void |
setCoyoteResponse(Response coyoteResponse)
Set the Coyote response.
|
void |
setDateHeader(String name,
long value)
Set the specified date header to the specified value.
|
void |
setError()
Set the error flag.
|
void |
setHeader(String name,
String value)
Set the specified header to the specified value.
|
void |
setIncluded(boolean included)
Set the "processing inside an include" flag.
|
void |
setIntHeader(String name,
int value)
Set the specified integer header to the specified value.
|
void |
setLocale(Locale locale)
Set the Locale that is appropriate for this response, including
setting the appropriate character encoding.
|
void |
setOutputStream(javax.servlet.ServletOutputStream outputStream) |
void |
setRequest(Request request)
Set the Request with which this Response is associated.
|
void |
setStatus(int status)
Set the HTTP status to be returned with this response.
|
void |
setStatus(int status,
String message)
Deprecated.
As of Version 2.1 of the Java Servlet API, this method
has been deprecated due to the ambiguous meaning of the message
parameter.
|
void |
setSuspended(boolean suspended)
Set the suspended flag.
|
void |
setWriter(PrintWriter writer) |
void |
startUpgrade() |
protected String |
toEncoded(String url,
String sessionId)
Return the specified URL with the specified session identifier
suitably encoded.
|
protected static final String info
protected SimpleDateFormat format
protected Connector connector
protected Response coyoteResponse
protected OutputBuffer outputBuffer
protected CoyoteOutputStream outputStream
protected CoyoteWriter writer
protected boolean appCommitted
protected boolean included
protected boolean error
protected ArrayList cookies
protected boolean usingOutputStream
protected boolean usingWriter
protected javax.servlet.ServletOutputStream applicationOutputStream
protected PrintWriter applicationWriter
protected UEncoder urlEncoder
protected CharChunk redirectURLCC
protected Request request
protected ResponseFacade facade
public Connector getConnector()
public void setConnector(Connector connector)
connector
- The new connectorpublic void setCoyoteResponse(Response coyoteResponse)
coyoteResponse
- The Coyote responsepublic Response getCoyoteResponse()
public void recycle()
public void clearEncoders()
public void clearOutputStream()
public int getContentCount()
public long getContentCountLong()
public void setAppCommitted(boolean appCommitted)
appCommitted
- The new application committed flag valuepublic boolean isAppCommitted()
public boolean getIncluded()
public void setIncluded(boolean included)
included
- true
if we are currently inside a
RequestDispatcher.include(), else false
public String getInfo()
<description>/<version>
.public Request getRequest()
public void setRequest(Request request)
request
- The new associated requestpublic javax.servlet.http.HttpServletResponse getResponse()
ServletResponse
for which this object
is the facade.public OutputStream getStream()
public void setSuspended(boolean suspended)
suspended
- The new suspended flag valuepublic boolean isSuspended()
public boolean isClosed()
public void setError()
public boolean isError()
public javax.servlet.ServletOutputStream createOutputStream() throws IOException
IOException
- if an input/output error occurspublic void finishResponse() throws IOException
IOException
- if an input/output error occurspublic int getContentLength()
public String getContentType()
null
if no content type was set.getContentType
in interface javax.servlet.ServletResponse
public PrintWriter getReporter() throws IOException
IOException
- if an input/output error occurspublic boolean isWriteable()
public void flushBuffer() throws IOException
flushBuffer
in interface javax.servlet.ServletResponse
IOException
- if an input/output error occurspublic int getBufferSize()
getBufferSize
in interface javax.servlet.ServletResponse
public String getCharacterEncoding()
getCharacterEncoding
in interface javax.servlet.ServletResponse
public javax.servlet.ServletOutputStream getOutputStream() throws IOException
getOutputStream
in interface javax.servlet.ServletResponse
IllegalStateException
- if getWriter
has
already been called for this responseIOException
- if an input/output error occurspublic void setOutputStream(javax.servlet.ServletOutputStream outputStream)
public Locale getLocale()
getLocale
in interface javax.servlet.ServletResponse
public PrintWriter getWriter() throws IOException
getWriter
in interface javax.servlet.ServletResponse
IllegalStateException
- if getOutputStream
has
already been called for this responseIOException
- if an input/output error occurspublic void setWriter(PrintWriter writer)
public boolean isCommitted()
isCommitted
in interface javax.servlet.ServletResponse
public void reset()
reset
in interface javax.servlet.ServletResponse
IllegalStateException
- if this response has already
been committedpublic void resetBuffer()
resetBuffer
in interface javax.servlet.ServletResponse
IllegalStateException
- if the response has already
been committedpublic void resetBuffer(boolean resetWriterStreamFlags)
resetWriterStreamFlags
- true
if the internal
usingWriter
, usingOutputStream
,
isCharacterEncodingSet
flags should also be resetIllegalStateException
- if the response has already
been committedpublic void setBufferSize(int size)
setBufferSize
in interface javax.servlet.ServletResponse
size
- The new buffer sizeIllegalStateException
- if this method is called after
output has been committed for this responsepublic void setContentLength(int length)
setContentLength
in interface javax.servlet.ServletResponse
length
- The new content lengthpublic void setContentType(String type)
setContentType
in interface javax.servlet.ServletResponse
type
- The new content typepublic void setCharacterEncoding(String charset)
setCharacterEncoding
in interface javax.servlet.ServletResponse
public void setLocale(Locale locale)
setLocale
in interface javax.servlet.ServletResponse
locale
- The new localepublic javax.servlet.http.Cookie[] getCookies()
public String getHeader(String name)
null
if this
header has not been set. If more than one value was added for this
name, only the first is returned; use getHeaderValues() to retrieve all
of them.getHeader
in interface javax.servlet.http.HttpServletResponse
name
- Header name to look uppublic Collection<String> getHeaderNames()
getHeaderNames
in interface javax.servlet.http.HttpServletResponse
public String[] getHeaderNamesArray()
public Collection<String> getHeaders(String name)
getHeaders
in interface javax.servlet.http.HttpServletResponse
name
- Header name to look uppublic String[] getHeaderValues(String name)
name
- Header name to look uppublic String getMessage()
sendError()
for this Response.public int getStatus()
getStatus
in interface javax.servlet.http.HttpServletResponse
public void reset(int status, String message)
IllegalStateException
- if this response has already been
committedpublic void addCookie(javax.servlet.http.Cookie cookie)
addCookie
in interface javax.servlet.http.HttpServletResponse
cookie
- Cookie to be addedpublic void addCookieInternal(javax.servlet.http.Cookie cookie)
cookie
- Cookie to be addedpublic void addDateHeader(String name, long value)
addDateHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to setvalue
- Date value to be setpublic void addHeader(String name, String value)
addHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to setvalue
- Value to be setpublic void addIntHeader(String name, int value)
addIntHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to setvalue
- Integer value to be setpublic boolean containsHeader(String name)
containsHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to checkpublic String encodeRedirectURL(String url)
encodeRedirectURL
in interface javax.servlet.http.HttpServletResponse
url
- URL to be encodedpublic String encodeRedirectUrl(String url)
encodeRedirectURL()
instead.encodeRedirectUrl
in interface javax.servlet.http.HttpServletResponse
url
- URL to be encodedpublic String encodeURL(String url)
encodeURL
in interface javax.servlet.http.HttpServletResponse
url
- URL to be encodedpublic String encodeUrl(String url)
encodeURL()
instead.encodeUrl
in interface javax.servlet.http.HttpServletResponse
url
- URL to be encodedpublic void sendAcknowledgement() throws IOException
IOException
- if an input/output error occurspublic void sendError(int status) throws IOException
sendError
in interface javax.servlet.http.HttpServletResponse
status
- HTTP status code to sendIllegalStateException
- if this response has
already been committedIOException
- if an input/output error occurspublic void sendError(int status, String message) throws IOException
sendError
in interface javax.servlet.http.HttpServletResponse
status
- HTTP status code to sendmessage
- Corresponding message to sendIllegalStateException
- if this response has
already been committedIOException
- if an input/output error occurspublic void sendRedirect(String location) throws IOException
sendRedirect
in interface javax.servlet.http.HttpServletResponse
location
- Location URL to redirect toIllegalStateException
- if this response has
already been committedIOException
- if an input/output error occurspublic void startUpgrade()
public void sendUpgrade() throws IOException
IOException
public void setDateHeader(String name, long value)
setDateHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to setvalue
- Date value to be setpublic void setHeader(String name, String value)
setHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to setvalue
- Value to be setpublic void setIntHeader(String name, int value)
setIntHeader
in interface javax.servlet.http.HttpServletResponse
name
- Name of the header to setvalue
- Integer value to be setpublic void setStatus(int status)
setStatus
in interface javax.servlet.http.HttpServletResponse
status
- The new HTTP statuspublic void setStatus(int status, String message)
setStatus
in interface javax.servlet.http.HttpServletResponse
status
- The new HTTP statusmessage
- The associated text messagepublic void setContentLengthLong(long length)
public WriteListener getWriteListener()
protected boolean isEncodeable(String location)
true
if the specified URL should be encoded with
a session identifier. This will be true if all of the following
conditions are met:
location
- Absolute URL to be validatedCopyright © 2014 JBoss by Red Hat. All Rights Reserved.