Class Response
java.lang.Object
org.glassfish.grizzly.http.server.Response
Wrapper object for the Coyote response.
- Version:
- $Revision: 1.2 $ $Date: 2006/11/02 20:01:44 $
- Author:
- Remy Maucherat, Craig R. McClanahan
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanThe application commit flag.protected FilterChainContextGrizzlyFilterChaincontext, related to this HTTP request/responseprotected booleanThe error flag.protected SimpleDateFormatThe date format we will use for creating date headers.protected HttpContextGrizzlyHttpContextassociated with the current Request/Response processing.protected static final StringDescriptive information about this Response implementation.protected final ServerOutputBufferThe associated output buffer.protected final CharChunkRecyclable buffer to hold the redirect URL.protected RequestThe request with which this response is associated.protected HttpResponsePacketCoyote response.protected final UEncoderURL encoder.protected booleanUsing output stream flag.protected booleanUsing writer flag. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the specified Cookie to those that will be included with this Response.voidaddDateHeader(String name, long value) Add the specified date header to the specified value.voidaddDateHeader(Header header, long value) Add the specified date header to the specified value.voidAdd the specified header to the specified value.voidaddHeader(String name, HeaderValue value) Add the specified header to the specified value.voidAdd the specified header to the specified value.voidaddHeader(Header header, HeaderValue value) Add the specified header to the specified value.voidaddIntHeader(String name, int value) Add the specified integer header to the specified value.voidaddIntHeader(Header header, int value) Add the specified integer header to the specified value.protected voidaddSessionCookieInternal(Cookie cookie) Special method for adding a session cookie as we should be overriding any previousvoidcancel()Deprecated.pls.booleancontainsHeader(String name) Has the specified header been set already in this response?booleancontainsHeader(Header header) Has the specified header been set already in this response?Create and return a ServletOutputStream to write the content associated with this Response.encodeRedirectURL(String url) Encode the session identifier associated with this response into the specified redirect URL, if necessary.Encode the session identifier associated with this response into the specified URL, if necessary.static StringFilter the specified message string for characters that are sensitive in HTML.voidfinish()Perform whatever actions are required to flush and close the output stream or writer, in a single operation.voidflush()Flush the current buffered content to the network.intReturn the actual buffer size used for this Response.Return the character encoding used for this Response.intReturn the content length that was set or calculated for this Response.longReturn the content length that was set or calculated for this Response.Return the content type that was set or calculated for this response, ornullif no content type was set.Cookie[]Return an array of all cookies set for this response, or a zero-length array if no cookies have been set.Gets detail error message.Return the value for the specified header, ornullif this header has not been set.String[]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.getInfo()Return descriptive information about this Response implementation and the corresponding version number, in the format<description>/<version>.Return the Locale assigned to this response.Return the error message that was set withsendError()for this Response.Return theNIOOutputStreamassociated with thisResponse.Return theOutputStreamassociated with thisResponse.Return the Request with which this Response is associated.Get theHttpResponsePacket.intReturn the HTTP status code associated with this Response.Get the context of the suspended Response.voidinitialize(Request request, HttpResponsePacket response, FilterChainContext ctx, DelayedExecutor.DelayQueue<Response.SuspendTimeout> delayQueue, HttpServerFilter serverFilter) booleanIs the file cache enabled?booleanHas the output of this response already been committed?protected booleanisEncodeable(String location) Return true if the specified URL should be encoded with a session identifier.booleanisError()Error flag accessor.booleanbooleanReturn true<//tt> if thatsuspend()has been invoked and set to trueprotected voidrecycle()Release all object references, and initialize instance variables, in preparation for reuse of this object.protected voidRemoves any Set-Cookie response headers whose value contains the string "JSESSIONID=" or "JSESSIONIDSSO="voidreset()Clears any data that exists in the buffer as well as the status code and headers.voidReset this response, and specify the values for the HTTP status code and corresponding message.voidReset the data buffer but not any status or header information.voidresetBuffer(boolean resetWriterStreamFlags) Reset the data buffer and the using Writer/Stream flags but not any status or header information.voidresume()Complete theResponseand finish/commit it.voidSend an acknowledgment of a request.voidsendError(int status) Send an error response with the specified status and a default message.voidSend an error response with the specified status and message.voidsendRedirect(String location) Send a temporary redirect to the specified redirect location URL.voidsetBufferSize(int size) Set the buffer size to be used for this Response.voidsetCharacterEncoding(String charset) voidsetContentLength(int length) Set the content length (in bytes) for this Response.voidsetContentLengthLong(long length) Set the content length (in bytes) for this Response.voidsetContentType(String type) Set the content type for this Response.voidsetContentType(ContentType type) Set the content type for this Response.voidsetDateHeader(String name, long value) Set the specified date header to the specified value.voidsetDateHeader(Header header, long value) Set the specified date header to the specified value.voidsetDetailMessage(String message) Sets detail error message.voidsetError()Set the error flag.voidsetErrorPageGenerator(ErrorPageGenerator errorPageGenerator) voidSet the specified header to the specified value.voidsetHeader(String name, HeaderValue value) Set the specified header to the specified value.voidSet the specified header to the specified value.voidsetHeader(Header header, HeaderValue value) Set the specified header to the specified value.voidsetIntHeader(String name, int value) Set the specified integer header to the specified value.voidsetIntHeader(Header header, int value) Set the specified integer header to the specified value.voidSet the Locale that is appropriate for this response, including setting the appropriate character encoding.voidsetStatus(int status) Set the HTTP status to be returned with this response.voidSet the HTTP status and message to be returned with this response.voidsetStatus(HttpStatus status) Set the HTTP status and message to be returned with this response.voidsetTrailers(Supplier<Map<String, String>> trailerSupplier) Set the supplier of trailer headers.voidsuspend()Suspend theResponse.voidDeprecated.timeout parameters don't make any sense without CompletionHandlervoidsuspend(long timeout, TimeUnit timeunit, CompletionHandler<Response> completionHandler) Suspend theResponse.voidsuspend(long timeout, TimeUnit timeunit, CompletionHandler<Response> completionHandler, TimeoutHandler timeoutHandler) Suspend theResponse.protected StringtoAbsolute(String location, boolean normalize) Convert (if necessary) and return the absolute URL that represents the resource referenced by this possibly relative URL.protected StringReturn the specified URL with the specified session identifier suitably encoded.
-
Field Details
-
format
The date format we will use for creating date headers. -
info
Descriptive information about this Response implementation.- See Also:
-
request
The request with which this response is associated. -
response
Coyote response. -
ctx
GrizzlyFilterChaincontext, related to this HTTP request/response -
httpContext
GrizzlyHttpContextassociated with the current Request/Response processing. -
outputBuffer
The associated output buffer. -
appCommitted
protected boolean appCommittedThe application commit flag. -
error
protected boolean errorThe error flag. -
usingOutputStream
protected boolean usingOutputStreamUsing output stream flag. -
usingWriter
protected boolean usingWriterUsing writer flag. -
urlEncoder
URL encoder. -
redirectURLCC
Recyclable buffer to hold the redirect URL. -
delayQueue
-
-
Constructor Details
-
Response
protected Response()
-
-
Method Details
-
initialize
public void initialize(Request request, HttpResponsePacket response, FilterChainContext ctx, DelayedExecutor.DelayQueue<Response.SuspendTimeout> delayQueue, HttpServerFilter serverFilter) -
getRequest
Return the Request with which this Response is associated. -
getResponse
Get theHttpResponsePacket. -
recycle
protected void recycle()Release all object references, and initialize instance variables, in preparation for reuse of this object. -
setTrailers
Set the supplier of trailer headers. The supplier will be called within the scope of whatever thread/call causes the response content to be completed. Typically this will be any thread calling close() on the output stream or writer. The trailers that run afoul of the provisions of section 4.1.2 of RFC 7230 are ignored.- Parameters:
trailerSupplier- the supplier of trailer headers- Throws:
IllegalStateException- if it is invoked after the response has has been committed, or trailers cannot be supported given the current protocol and/or configuration (chunked transfer encoding disabled in HTTP/1.1 as an example).- Since:
- 2.4.0
-
getTrailers
- Returns:
- the trailers supplier, if any.
- Since:
- 2.4.0
-
encodeURL
Encode the session identifier associated with this response into the specified URL, if necessary.- Parameters:
url- URL to be encoded
-
encodeRedirectURL
Encode the session identifier associated with this response into the specified redirect URL, if necessary.- Parameters:
url- URL to be encoded
-
isEncodeable
Return true if the specified URL should be encoded with a session identifier. This will be true if all of the following conditions are met:- The request we are responding to asked for a valid session
- The requested session ID was not received via a cookie
- The specified URL points back to somewhere within the web application that is responding to this request
- Parameters:
location- Absolute URL to be validated
-
getInfo
Return descriptive information about this Response implementation and the corresponding version number, in the format<description>/<version>. -
setError
public void setError()Set the error flag. -
isError
public boolean isError()Error flag accessor. -
getErrorPageGenerator
- Returns:
- the
ErrorPageGeneratorto be used bysendError(int)orsendError(int, java.lang.String).
-
setErrorPageGenerator
- Parameters:
errorPageGenerator- the customErrorPageGenerator.
-
setDetailMessage
Sets detail error message.- Parameters:
message- detail error message
-
getDetailMessage
Gets detail error message.- Returns:
- the detail error message
-
finish
public void finish()Perform whatever actions are required to flush and close the output stream or writer, in a single operation. -
getContentLength
public int getContentLength()Return the content length that was set or calculated for this Response. -
getContentLengthLong
public long getContentLengthLong()Return the content length that was set or calculated for this Response. -
getContentType
Return the content type that was set or calculated for this response, ornullif no content type was set. -
getBufferSize
public int getBufferSize()Return the actual buffer size used for this Response. -
getCharacterEncoding
Return the character encoding used for this Response. -
setCharacterEncoding
-
createOutputStream
Create and return a ServletOutputStream to write the content associated with this Response. -
getNIOOutputStream
Return the
NIOOutputStreamassociated with thisResponse. ThisNIOOutputStreamwill write content in a non-blocking manner.- Throws:
IllegalStateException- ifgetWriter()orgetNIOWriter()were already invoked.
-
getOutputStream
Return the
By default the returnedOutputStreamassociated with thisResponse.NIOOutputStreamwill work as blockingOutputStream, but it will be possible to callOutputSink.canWrite()orOutputSink.notifyCanWrite(org.glassfish.grizzly.WriteHandler)to avoid blocking.- Returns:
- the
NIOOutputStreamassociated with thisResponse. - Throws:
IllegalStateException- ifgetWriter()orgetNIOWriter()were already invoked.- Since:
- 2.1.2
-
getLocale
Return the Locale assigned to this response. -
getWriter
Return the
By default the returnedNIOWriterassociated with thisResponse.NIOWriterwill work as blockingWriter, but it will be possible to callOutputSink.canWrite()orOutputSink.notifyCanWrite(org.glassfish.grizzly.WriteHandler)to avoid blocking.- Throws:
IllegalStateException- ifgetOutputStream()orgetNIOOutputStream()were already invoked.
-
getNIOWriter
Return the
NIOWriterassociated with thisResponse. TheNIOWriterwill write content in a non-blocking manner.- Returns:
- the
NIOWriterassociated with thisResponse. - Throws:
IllegalStateException- ifgetOutputStream()orgetNIOOutputStream()were already invoked.- Since:
- 2.1.2
-
isCommitted
public boolean isCommitted()Has the output of this response already been committed? -
flush
Flush the current buffered content to the network.- Throws:
IOException- if an occur occurs flushing to the wire.
-
getOutputBuffer
- Returns:
- the
OutputBufferassociated with thisResponse.
-
reset
public void reset()Clears any data that exists in the buffer as well as the status code and headers.- Throws:
IllegalStateException- if this response has already been committed
-
resetBuffer
public void resetBuffer()Reset the data buffer but not any status or header information.- Throws:
IllegalStateException- if the response has already been committed
-
resetBuffer
public void resetBuffer(boolean resetWriterStreamFlags) Reset the data buffer and the using Writer/Stream flags but not any status or header information.- Parameters:
resetWriterStreamFlags-trueif the internalusingWriter,usingOutputStream,isCharacterEncodingSetflags should also be reset- Throws:
IllegalStateException- if the response has already been committed
-
setBufferSize
public void setBufferSize(int size) Set the buffer size to be used for this Response.- Parameters:
size- The new buffer size- Throws:
IllegalStateException- if this method is called after output has been committed for this response
-
setContentLengthLong
public void setContentLengthLong(long length) Set the content length (in bytes) for this Response. If thelengthargument is negative - thenHttpPacketcontent-length value will be reset to -1 and Content-Length header (if present) will be removed.- Parameters:
length- The new content length
-
setContentLength
public void setContentLength(int length) Set the content length (in bytes) for this Response. If thelengthargument is negative - thenHttpPacketcontent-length value will be reset to -1 and Content-Length header (if present) will be removed.- Parameters:
length- The new content length
-
setContentType
Set the content type for this Response.- Parameters:
type- The new content type
-
setContentType
Set the content type for this Response.- Parameters:
type- The new content type
-
setLocale
Set the Locale that is appropriate for this response, including setting the appropriate character encoding.- Parameters:
locale- The new locale
-
getCookies
Return an array of all cookies set for this response, or a zero-length array if no cookies have been set. -
getHeader
Return the value for the specified header, ornullif 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.- Parameters:
name- Header name to look up
-
getHeaderNames
Return an array of all the header names set for this response, or a zero-length array if no headers have been set. -
getHeaderValues
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.- Parameters:
name- Header name to look up
-
getMessage
Return the error message that was set withsendError()for this Response. -
getStatus
public int getStatus()Return the HTTP status code associated with this Response. -
reset
Reset this response, and specify the values for the HTTP status code and corresponding message.- Throws:
IllegalStateException- if this response has already been committed
-
addCookie
Add the specified Cookie to those that will be included with this Response.- Parameters:
cookie- Cookie to be added
-
addSessionCookieInternal
Special method for adding a session cookie as we should be overriding any previous -
removeSessionCookies
protected void removeSessionCookies()Removes any Set-Cookie response headers whose value contains the string "JSESSIONID=" or "JSESSIONIDSSO=" -
addDateHeader
Add the specified date header to the specified value.- Parameters:
name- Name of the header to setvalue- Date value to be set
-
addDateHeader
Add the specified date header to the specified value.- Parameters:
header- theHeaderto setvalue- Date value to be set- Since:
- 2.1.2
-
addHeader
Add the specified header to the specified value.- Parameters:
name- Name of the header to setvalue- Value to be set
-
addHeader
Add the specified header to the specified value.- Parameters:
name- Name of the header to setvalue- Value to be set- Since:
- 2.3.8
-
addHeader
Add the specified header to the specified value.- Parameters:
header- theHeaderto setvalue- Value to be set- Since:
- 2.1.2
-
addHeader
Add the specified header to the specified value.- Parameters:
header- theHeaderto setvalue- Value to be set- Since:
- 2.3.8
-
addIntHeader
Add the specified integer header to the specified value.- Parameters:
name- Name of the header to setvalue- Integer value to be set
-
addIntHeader
Add the specified integer header to the specified value.- Parameters:
header- theHeaderto setvalue- Integer value to be set- Since:
- 2.1.2
-
containsHeader
Has the specified header been set already in this response?- Parameters:
name- Name of the header to check
-
containsHeader
Has the specified header been set already in this response?- Parameters:
header- theHeaderto check- Since:
- 2.1.2
-
sendAcknowledgement
Send an acknowledgment of a request. An acknowledgment in this case is simply an HTTP response status line, i.e.HTTP/1.1 [STATUS] [REASON-PHRASE].- Throws:
IOException- if an input/output error occurs
-
sendError
Send an error response with the specified status and a default message.- Parameters:
status- HTTP status code to send- Throws:
IllegalStateException- if this response has already been committedIOException- if an input/output error occurs
-
sendError
Send an error response with the specified status and message.- Parameters:
status- HTTP status code to sendmessage- Corresponding message to send- Throws:
IllegalStateException- if this response has already been committedIOException- if an input/output error occurs
-
sendRedirect
Send a temporary redirect to the specified redirect location URL.- Parameters:
location- Location URL to redirect to- Throws:
IllegalStateException- if this response has already been committedIOException- if an input/output error occurs
-
setDateHeader
Set the specified date header to the specified value.- Parameters:
name- Name of the header to setvalue- Date value to be set
-
setDateHeader
Set the specified date header to the specified value.- Parameters:
header- theHeaderto setvalue- Date value to be set- Since:
- 2.1.2
-
setHeader
Set the specified header to the specified value.- Parameters:
name- Name of the header to setvalue- Value to be set
-
setHeader
Set the specified header to the specified value.- Parameters:
name- Name of the header to setvalue- Value to be set- Since:
- 2.3.8
-
setHeader
Set the specified header to the specified value.- Parameters:
header- theHeaderto setvalue- Value to be set- Since:
- 2.1.2
-
setHeader
Set the specified header to the specified value.- Parameters:
header- theHeaderto setvalue- Value to be set- Since:
- 2.3.8
-
setIntHeader
Set the specified integer header to the specified value.- Parameters:
name- Name of the header to setvalue- Integer value to be set
-
setIntHeader
Set the specified integer header to the specified value.- Parameters:
header- theHeaderto setvalue- Integer value to be set- Since:
- 2.1.2
-
setStatus
public void setStatus(int status) Set the HTTP status to be returned with this response.- Parameters:
status- The new HTTP status
-
setStatus
Set the HTTP status and message to be returned with this response.- Parameters:
status- The new HTTP statusmessage- The associated text message
-
setStatus
Set the HTTP status and message to be returned with this response.- Parameters:
status-HttpStatusto set
-
toAbsolute
Convert (if necessary) and return the absolute URL that represents the resource referenced by this possibly relative URL. If this URL is already absolute, return it unchanged.- Parameters:
location- URL to be (possibly) converted and then returned- Throws:
IllegalArgumentException- if a MalformedURLException is thrown when converting the relative URL to an absolute one
-
filter
Filter the specified message string for characters that are sensitive in HTML. This avoids potential attacks caused by including JavaScript codes in the request URL that is often reported in error messages.- Parameters:
message- The message string to be filtered
-
toEncoded
Return the specified URL with the specified session identifier suitably encoded.- Parameters:
url- URL to be encoded with the session idsessionId- Session id to be included in the encoded URL
-
isCacheEnabled
public boolean isCacheEnabled()Is the file cache enabled? -
getSuspendContext
Get the context of the suspended Response.- Returns:
- the context of the suspended Response.
-
isSuspended
public boolean isSuspended()Return true<//tt> if thatsuspend()has been invoked and set to true- Returns:
- true<//tt> if that
suspend()has been invoked and set to true
-
suspend
public void suspend() -
suspend
Deprecated.timeout parameters don't make any sense without CompletionHandlerSuspend theResponse. Suspending aResponsewill tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid committing response.- Parameters:
timeout- The maximum amount of time, aResponsecan be suspended. When the timeout expires (because nothing has been written or because theresume()orcancel()), theResponsewill be automatically resumed and committed. Usage of any methods of aResponsethat times out will throw anIllegalStateException.timeunit- timeout units
-
suspend
Suspend theResponse. Suspending aResponsewill tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid committing response. When theresume()is invoked, the container will make sureCompletionHandler.completed(Object)is invoked with the original attachment. When thecancel()is invoked, the container will make sureCompletionHandler.cancelled()is invoked with the original attachment. If the timeout expires, theCompletionHandler.cancelled()is invoked with the original attachment and theResponsecommitted.- Parameters:
timeout- The maximum amount of time theResponsecan be suspended. When the timeout expires (because nothing has been written or because theresume()orcancel()), theResponsewill be automatically resumed and committed. Usage of any methods of aResponsethat times out will throw anIllegalStateException.timeunit- timeout unitscompletionHandler- aCompletionHandler
-
suspend
public void suspend(long timeout, TimeUnit timeunit, CompletionHandler<Response> completionHandler, TimeoutHandler timeoutHandler) Suspend theResponse. Suspending aResponsewill tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid committing response. When theresume()is invoked, the container will make sureCompletionHandler.completed(Object)is invoked with the original attachment. When thecancel()is invoked, the container will make sureCompletionHandler.cancelled()is invoked with the original attachment. If the timeout expires, theCompletionHandler.cancelled()is invoked with the original attachment and theResponsecommitted.- Parameters:
timeout- The maximum amount of time theResponsecan be suspended. When the timeout expires (because nothing has been written or because theresume()orcancel()), theResponsewill be automatically resumed and committed. Usage of any methods of aResponsethat times out will throw anIllegalStateException.timeunit- timeout unitscompletionHandler- aCompletionHandlertimeoutHandler-TimeoutHandlerto customize the suspended Response timeout logic.
-
resume
public void resume()Complete theResponseand finish/commit it. If aCompletionHandlerhas been defined, itsCompletionHandler.completed(Object)will first be invoked, then thefinish(). Those operations commit the response. -
cancel
Deprecated.pls. useresume()Cancel theResponseand finish/commit it. If aCompletionHandlerhas been defined, itsCompletionHandler.cancelled()will first be invoked, then thefinish(). Those operations commit the response. -
isSendFileEnabled
public boolean isSendFileEnabled()
-