public class Response extends Object
Modifier and Type | Class and Description |
---|---|
class |
Response.SuspendedContextImpl |
protected class |
Response.SuspendTimeout |
Modifier and Type | Field and Description |
---|---|
protected boolean |
appCommitted
The application commit flag.
|
protected FilterChainContext |
ctx
Grizzly
FilterChain context,
related to this HTTP request/response |
protected DelayedExecutor.DelayQueue<Response.SuspendTimeout> |
delayQueue |
protected boolean |
error
The error flag.
|
protected SimpleDateFormat |
format
The date format we will use for creating date headers.
|
protected HttpContext |
httpContext
Grizzly
HttpContext associated with the current Request/Response
processing. |
protected static String |
info
Descriptive information about this Response implementation.
|
protected ServerOutputBuffer |
outputBuffer
The associated output buffer.
|
protected CharChunk |
redirectURLCC
Recyclable buffer to hold the redirect URL.
|
protected Request |
request
The request with which this response is associated.
|
protected HttpResponsePacket |
response
Coyote response.
|
protected UEncoder |
urlEncoder
URL encoder.
|
protected boolean |
usingOutputStream
Using output stream flag.
|
protected boolean |
usingWriter
Using writer flag.
|
Modifier | Constructor and Description |
---|---|
protected |
Response() |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(Cookie cookie)
Add the specified Cookie to those that will be included with
this Response.
|
void |
addDateHeader(Header header,
long value)
Add the specified date header to the specified value.
|
void |
addDateHeader(String name,
long value)
Add the specified date header to the specified value.
|
void |
addHeader(Header header,
HeaderValue value)
Add the specified header to the specified value.
|
void |
addHeader(Header header,
String value)
Add the specified header to the specified value.
|
void |
addHeader(String name,
HeaderValue value)
Add the specified header to the specified value.
|
void |
addHeader(String name,
String value)
Add the specified header to the specified value.
|
void |
addIntHeader(Header header,
int value)
Add the specified integer header to the specified value.
|
void |
addIntHeader(String name,
int value)
Add the specified integer header to the specified value.
|
protected void |
addSessionCookieInternal(Cookie cookie)
Special method for adding a session cookie as we should be overriding
any previous
|
void |
cancel()
Deprecated.
pls. use
resume() |
boolean |
containsHeader(Header header)
Has the specified header been set already in this response?
|
boolean |
containsHeader(String name)
Has the specified header been set already in this response?
|
NIOOutputStream |
createOutputStream()
Create and return a ServletOutputStream to write the content
associated with this Response.
|
String |
encodeRedirectURL(String url)
Encode the session identifier associated with this response
into the specified redirect URL, if necessary.
|
String |
encodeURL(String url)
Encode the session identifier associated with this response
into the specified URL, if necessary.
|
static String |
filter(String message)
Filter the specified message string for characters that are sensitive
in HTML.
|
void |
finish()
Perform whatever actions are required to flush and close the output
stream or writer, in a single operation.
|
void |
flush()
Flush the current buffered content to the network.
|
int |
getBufferSize()
Return the actual buffer size used for this Response.
|
String |
getCharacterEncoding()
Return the character encoding used for this Response.
|
int |
getContentLength()
Return the content length that was set or calculated for this Response.
|
long |
getContentLengthLong()
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. |
Cookie[] |
getCookies()
Return an array of all cookies set for this response, or
a zero-length array if no cookies have been set.
|
String |
getDetailMessage()
Gets detail error message.
|
ErrorPageGenerator |
getErrorPageGenerator() |
String |
getHeader(String name)
Return the value for the specified header, or
null if this
header has not been set. |
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[] |
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.
|
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. |
NIOOutputStream |
getNIOOutputStream()
Return the
NIOOutputStream associated with this Response . |
NIOWriter |
getNIOWriter()
|
OutputBuffer |
getOutputBuffer() |
OutputStream |
getOutputStream()
Return the
OutputStream associated with this Response . |
Request |
getRequest()
Return the Request with which this Response is associated.
|
HttpResponsePacket |
getResponse()
Get the
HttpResponsePacket . |
int |
getStatus()
Return the HTTP status code associated with this Response.
|
SuspendContext |
getSuspendContext()
Get the context of the suspended Response.
|
Writer |
getWriter()
|
void |
initialize(Request request,
HttpResponsePacket response,
FilterChainContext ctx,
DelayedExecutor.DelayQueue<Response.SuspendTimeout> delayQueue,
HttpServerFilter serverFilter) |
boolean |
isCacheEnabled()
Is the file cache enabled?
|
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 |
isSendFileEnabled() |
boolean |
isSuspended()
Return true/tt> if that
suspend() has been
invoked and set to true |
protected void |
recycle()
Release all object references, and initialize instance variables, in
preparation for reuse of this object.
|
protected void |
removeSessionCookies()
Removes any Set-Cookie response headers whose value contains the
string "JSESSIONID=" or "JSESSIONIDSSO="
|
void |
reset()
Clears any data that exists in the buffer as well as the status code
and headers.
|
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 |
resume()
Complete the
Response and finish/commit it. |
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 |
sendRedirect(String location)
Send a temporary redirect to the specified redirect location URL.
|
void |
setBufferSize(int size)
Set the buffer size to be used for this Response.
|
void |
setCharacterEncoding(String charset) |
void |
setContentLength(int length)
Set the content length (in bytes) for this Response.
|
void |
setContentLengthLong(long length)
Set the content length (in bytes) for this Response.
|
void |
setContentType(ContentType type)
Set the content type for this Response.
|
void |
setContentType(String type)
Set the content type for this Response.
|
void |
setDateHeader(Header header,
long value)
Set the specified date header to the specified value.
|
void |
setDateHeader(String name,
long value)
Set the specified date header to the specified value.
|
void |
setDetailMessage(String message)
Sets detail error message.
|
void |
setError()
Set the error flag.
|
void |
setErrorPageGenerator(ErrorPageGenerator errorPageGenerator)
|
void |
setHeader(Header header,
HeaderValue value)
Set the specified header to the specified value.
|
void |
setHeader(Header header,
String value)
Set the specified header to the specified value.
|
void |
setHeader(String name,
HeaderValue value)
Set the specified header to the specified value.
|
void |
setHeader(String name,
String value)
Set the specified header to the specified value.
|
void |
setIntHeader(Header header,
int value)
Set the specified integer header to the specified value.
|
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 |
setStatus(HttpStatus status)
Set the HTTP status and message to be returned with this response.
|
void |
setStatus(int status)
Set the HTTP status to be returned with this response.
|
void |
setStatus(int status,
String message)
Set the HTTP status and message to be returned with this response.
|
void |
suspend()
Suspend the
Response . |
void |
suspend(long timeout,
TimeUnit timeunit)
Deprecated.
timeout parameters don't make any sense without CompletionHandler
|
void |
suspend(long timeout,
TimeUnit timeunit,
CompletionHandler<Response> completionHandler)
Suspend the
Response . |
void |
suspend(long timeout,
TimeUnit timeunit,
CompletionHandler<Response> completionHandler,
TimeoutHandler timeoutHandler)
Suspend the
Response . |
protected String |
toAbsolute(String location,
boolean normalize)
Convert (if necessary) and return the absolute URL that represents the
resource referenced by this possibly relative URL.
|
protected String |
toEncoded(String url,
String sessionId)
Return the specified URL with the specified session identifier
suitably encoded.
|
protected SimpleDateFormat format
protected static final String info
protected Request request
protected HttpResponsePacket response
protected FilterChainContext ctx
FilterChain
context,
related to this HTTP request/responseprotected HttpContext httpContext
HttpContext
associated with the current Request/Response
processing.protected final ServerOutputBuffer outputBuffer
protected boolean appCommitted
protected boolean error
protected boolean usingOutputStream
protected boolean usingWriter
protected final UEncoder urlEncoder
protected final CharChunk redirectURLCC
protected DelayedExecutor.DelayQueue<Response.SuspendTimeout> delayQueue
public void initialize(Request request, HttpResponsePacket response, FilterChainContext ctx, DelayedExecutor.DelayQueue<Response.SuspendTimeout> delayQueue, HttpServerFilter serverFilter)
public Request getRequest()
public HttpResponsePacket getResponse()
HttpResponsePacket
.protected void recycle()
public String encodeURL(String url)
url
- URL to be encodedpublic String encodeRedirectURL(String url)
url
- URL to be encodedprotected boolean isEncodeable(String location)
location
- Absolute URL to be validatedpublic String getInfo()
<description>/<version>
.public void setError()
public boolean isError()
public ErrorPageGenerator getErrorPageGenerator()
ErrorPageGenerator
to be used by
sendError(int)
or sendError(int, java.lang.String)
.public void setErrorPageGenerator(ErrorPageGenerator errorPageGenerator)
errorPageGenerator
- public void setDetailMessage(String message)
message
- detail error messagepublic String getDetailMessage()
public void finish()
public int getContentLength()
public long getContentLengthLong()
public String getContentType()
null
if no content type was set.public int getBufferSize()
public String getCharacterEncoding()
public void setCharacterEncoding(String charset)
public NIOOutputStream createOutputStream()
public NIOOutputStream getNIOOutputStream()
Return the NIOOutputStream
associated with this Response
.
This NIOOutputStream
will write content in a non-blocking manner.
IllegalStateException
- if getWriter()
or getNIOWriter()
were already invoked.public OutputStream getOutputStream()
Return the OutputStream
associated with this Response
.
NIOOutputStream
will work as blocking
OutputStream
, but it will be possible to call OutputSink.canWrite()
or
OutputSink.notifyCanWrite(org.glassfish.grizzly.WriteHandler)
to
avoid blocking.NIOOutputStream
associated with this Response
.IllegalStateException
- if getWriter()
or getNIOWriter()
were already invoked.public Locale getLocale()
public Writer getWriter()
Return the NIOWriter
associated with this Response
.
NIOWriter
will work as blocking
Writer
, but it will be possible to call OutputSink.canWrite()
or
OutputSink.notifyCanWrite(org.glassfish.grizzly.WriteHandler)
to
avoid blocking.IllegalStateException
- if getOutputStream()
or
getNIOOutputStream()
were already invoked.public NIOWriter getNIOWriter()
Return the NIOWriter
associated with this Response
.
The NIOWriter
will write content in a non-blocking manner.
NIOWriter
associated with this Response
.IllegalStateException
- if getOutputStream()
or
getNIOOutputStream()
were already invoked.public boolean isCommitted()
public void flush() throws IOException
IOException
public OutputBuffer getOutputBuffer()
OutputBuffer
associated with this
Response
.public void reset()
IllegalStateException
- if this response has already
been committedpublic void resetBuffer()
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)
size
- The new buffer sizeIllegalStateException
- if this method is called after
output has been committed for this responsepublic void setContentLengthLong(long length)
length
argument is negative - then HttpPacket
content-length value will be reset to -1 and
Content-Length header (if present) will be removed.length
- The new content lengthpublic void setContentLength(int length)
length
argument is negative - then HttpPacket
content-length value will be reset to -1 and
Content-Length header (if present) will be removed.length
- The new content lengthpublic void setContentType(String type)
type
- The new content typepublic void setContentType(ContentType type)
type
- The new content typepublic void setLocale(Locale locale)
locale
- The new localepublic 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.name
- Header name to look uppublic String[] getHeaderNames()
public String[] getHeaderValues(String name)
name
- Header name to look uppublic String getMessage()
sendError()
for this Response.public int getStatus()
public void reset(int status, String message)
IllegalStateException
- if this response has already been
committedpublic void addCookie(Cookie cookie)
cookie
- Cookie to be addedprotected void addSessionCookieInternal(Cookie cookie)
cookie
- protected void removeSessionCookies()
public void addDateHeader(String name, long value)
name
- Name of the header to setvalue
- Date value to be setpublic void addDateHeader(Header header, long value)
header
- the Header
to setvalue
- Date value to be setpublic void addHeader(String name, String value)
name
- Name of the header to setvalue
- Value to be setpublic void addHeader(String name, HeaderValue value)
name
- Name of the header to setvalue
- Value to be setpublic void addHeader(Header header, String value)
header
- the Header
to setvalue
- Value to be setpublic void addHeader(Header header, HeaderValue value)
header
- the Header
to setvalue
- Value to be setpublic void addIntHeader(String name, int value)
name
- Name of the header to setvalue
- Integer value to be setpublic void addIntHeader(Header header, int value)
header
- the Header
to setvalue
- Integer value to be setpublic boolean containsHeader(String name)
name
- Name of the header to checkpublic boolean containsHeader(Header header)
header
- the Header
to checkpublic void sendAcknowledgement() throws IOException
HTTP/1.1 [STATUS] [REASON-PHRASE].
IOException
- if an input/output error occurspublic void sendError(int status) throws IOException
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
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
location
- Location URL to redirect toIllegalStateException
- if this response has
already been committedIOException
- if an input/output error occurspublic void setDateHeader(String name, long value)
name
- Name of the header to setvalue
- Date value to be setpublic void setDateHeader(Header header, long value)
header
- the Header
to setvalue
- Date value to be setpublic void setHeader(String name, String value)
name
- Name of the header to setvalue
- Value to be setpublic void setHeader(String name, HeaderValue value)
name
- Name of the header to setvalue
- Value to be setpublic void setHeader(Header header, String value)
header
- the Header
to setvalue
- Value to be setpublic void setHeader(Header header, HeaderValue value)
header
- the Header
to setvalue
- Value to be setpublic void setIntHeader(String name, int value)
name
- Name of the header to setvalue
- Integer value to be setpublic void setIntHeader(Header header, int value)
header
- the Header
to setvalue
- Integer value to be setpublic void setStatus(int status)
status
- The new HTTP statuspublic void setStatus(int status, String message)
status
- The new HTTP statusmessage
- The associated text messagepublic void setStatus(HttpStatus status)
status
- HttpStatus
to setprotected String toAbsolute(String location, boolean normalize)
location
- URL to be (possibly) converted and then returnedIllegalArgumentException
- if a MalformedURLException is
thrown when converting the relative URL to an absolute onepublic static String filter(String message)
message
- The message string to be filteredprotected String toEncoded(String url, String sessionId)
url
- URL to be encoded with the session idsessionId
- Session id to be included in the encoded URLpublic boolean isCacheEnabled()
public SuspendContext getSuspendContext()
public boolean isSuspended()
suspend()
has been
invoked and set to truesuspend()
has been
invoked and set to truepublic void suspend()
public void suspend(long timeout, TimeUnit timeunit)
Response
. Suspending a Response
will
tell the underlying container to avoid recycling objects associated with
the current instance, and also to avoid committing response.timeout
- The maximum amount of time,
a Response
can be suspended. When the timeout expires (because
nothing has been written or because the resume()
or cancel()
), the Response
will be automatically
resumed and committed. Usage of any methods of a Response
that
times out will throw an IllegalStateException
.timeunit
- timeout unitspublic void suspend(long timeout, TimeUnit timeunit, CompletionHandler<Response> completionHandler)
Response
. Suspending a Response
will
tell the underlying container to avoid recycling objects associated with
the current instance, and also to avoid committing response. When the
resume()
is invoked, the container will
make sure CompletionHandler.completed(Object)
is invoked with the original attachment. When the
cancel()
is invoked, the container will
make sure CompletionHandler.cancelled()
is invoked with the original attachment. If the timeout expires, the
CompletionHandler.cancelled()
is invoked with the original attachment and
the Response
committed.timeout
- The maximum amount of time the Response
can be suspended.
When the timeout expires (because nothing has been written or because the
resume()
or cancel()
), the Response
will be automatically resumed and committed. Usage of any methods of a
Response
that times out will throw an IllegalStateException
.timeunit
- timeout unitscompletionHandler
- a CompletionHandler
public void suspend(long timeout, TimeUnit timeunit, CompletionHandler<Response> completionHandler, TimeoutHandler timeoutHandler)
Response
. Suspending a Response
will
tell the underlying container to avoid recycling objects associated with
the current instance, and also to avoid committing response. When the
resume()
is invoked, the container will
make sure CompletionHandler.completed(Object)
is invoked with the original attachment. When the
cancel()
is invoked, the container will
make sure CompletionHandler.cancelled()
is invoked with the original attachment. If the timeout expires, the
CompletionHandler.cancelled()
is invoked with the original attachment and
the Response
committed.timeout
- The maximum amount of time the Response
can be suspended.
When the timeout expires (because nothing has been written or because the
resume()
or cancel()
), the Response
will be automatically resumed and committed. Usage of any methods of a
Response
that times out will throw an IllegalStateException
.timeunit
- timeout unitscompletionHandler
- a CompletionHandler
timeoutHandler
- TimeoutHandler
to customize the suspended Response timeout logic.public void resume()
Response
and finish/commit it. If a
CompletionHandler
has been defined, its CompletionHandler.completed(Object)
will first be invoked, then the finish()
.
Those operations commit the response.public void cancel()
resume()
Response
and finish/commit it. If a
CompletionHandler
has been defined, its CompletionHandler.cancelled()
will first be invoked, then the finish()
.
Those operations commit the response.public boolean isSendFileEnabled()
Copyright © 2015 Oracle Corporation. All rights reserved.