com.sun.grizzly.tcp.http11
Class GrizzlyResponse<A>

java.lang.Object
  extended by com.sun.grizzly.tcp.http11.GrizzlyResponse<A>

public class GrizzlyResponse<A>
extends Object

Wrapper object for the Coyote response.

Version:
$Revision: 1.2 $ $Date: 2006/11/02 20:01:44 $
Author:
Remy Maucherat, Craig R. McClanahan

Field Summary
protected  boolean appCommitted
          The application commit flag.
protected  ArrayList cookies
          The set of Cookies associated with this Response.
protected  boolean error
          The error flag.
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  GrizzlyOutputBuffer outputBuffer
          The associated output buffer.
protected  GrizzlyOutputStream outputStream
          The associated output stream.
protected  MessageBytes redirectURLCC
          Recyclable buffer to hold the redirect URL.
protected  GrizzlyRequest request
          The request with which this response is associated.
protected  Response response
          Coyote response.
protected static StringManager sm
          The string manager for this package.
protected  UEncoder urlEncoder
          URL encoder.
protected  boolean usingOutputStream
          Using output stream flag.
protected  boolean usingWriter
          Using writer flag.
protected  GrizzlyWriter writer
          The associated writer.
 
Constructor Summary
GrizzlyResponse()
           
GrizzlyResponse(boolean chunkingDisabled, boolean cacheEnabled)
           
GrizzlyResponse(boolean chunkingDisabled, boolean cacheEnabled, int outputBufferSize)
           
 
Method Summary
 void addCookie(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 addResponseFilter(ResponseFilter responseFilter)
          Add a ResponseFilter, which will be called every bytes are ready to be written.
 void cancel()
          Cancel the GrizzlyResponse and finish/commit it.
 boolean containsHeader(String name)
          Has the specified header been set already in this response?
 GrizzlyOutputStream createOutputStream()
          Create and return a ServletOutputStream to write the content associated with this Response.
 void enableCache(boolean cacheEnabled)
          Enable/disable the cache
 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 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.
 boolean getChunkingDisabled()
          Is chunking enabled?
 int getContentCount()
          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.
 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.
 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.
 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.
 GrizzlyOutputBuffer getOutputBuffer()
          Return the underlying OutputBuffer
 GrizzlyOutputStream 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.
 GrizzlyRequest getRequest()
          Return the Request with which this Response is associated.
 Response getResponse()
          Get the Coyote response.
 int getStatus()
          Return the HTTP status code associated with this Response.
 OutputStream getStream()
          Return the output stream associated with this Response.
 PrintWriter getWriter()
          Return the writer associated with this Response.
 boolean isAppCommitted()
          Application commit flag accessor.
 boolean isBufferSuspended()
          Suspended flag accessor.
 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 isSuspended()
          Return true if that suspend() has been invoked and set to true
 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 resume()
          Complete the GrizzlyResponse 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 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 setChunkingDisabled(boolean chunkingDisabled)
          Enabled or Disable response chunking.
 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(String type)
          Set the content type for this Response.
 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 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 setRequest(GrizzlyRequest request)
          Set the Request with which this Response is associated.
 void setResponse(Response response)
          Set the Coyote 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 setStream(OutputStream stream)
          Set the output stream associated with this Response.
 void setSuspended(boolean suspended)
          Set the suspended flag.
 void suspend()
          Suspend the Response.
 void suspend(long timeout)
          Suspend the GrizzlyResponse.
 void suspend(long timeout, A attachment, CompletionHandler<? super A> competionHandler)
          Suspend the GrizzlyResponse.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

format

protected SimpleDateFormat format
The date format we will use for creating date headers.


info

protected static final String info
Descriptive information about this Response implementation.

See Also:
Constant Field Values

sm

protected static StringManager sm
The string manager for this package.


request

protected GrizzlyRequest request
The request with which this response is associated.


response

protected Response response
Coyote response.


outputBuffer

protected final GrizzlyOutputBuffer outputBuffer
The associated output buffer.


outputStream

protected GrizzlyOutputStream outputStream
The associated output stream.


writer

protected GrizzlyWriter writer
The associated writer.


appCommitted

protected boolean appCommitted
The application commit flag.


included

protected boolean included
The included flag.


error

protected boolean error
The error flag.


cookies

protected ArrayList cookies
The set of Cookies associated with this Response.


usingOutputStream

protected boolean usingOutputStream
Using output stream flag.


usingWriter

protected boolean usingWriter
Using writer flag.


urlEncoder

protected UEncoder urlEncoder
URL encoder.


redirectURLCC

protected MessageBytes redirectURLCC
Recyclable buffer to hold the redirect URL.

Constructor Detail

GrizzlyResponse

public GrizzlyResponse()

GrizzlyResponse

public GrizzlyResponse(boolean chunkingDisabled,
                       boolean cacheEnabled)

GrizzlyResponse

public GrizzlyResponse(boolean chunkingDisabled,
                       boolean cacheEnabled,
                       int outputBufferSize)
Method Detail

getRequest

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


setRequest

public void setRequest(GrizzlyRequest request)
Set the Request with which this Response is associated.

Parameters:
request - The new associated request

setResponse

public void setResponse(Response response)
Set the Coyote response.

Parameters:
response - The Coyote response

getResponse

public Response getResponse()
Get the Coyote response.


recycle

public void recycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.


encodeURL

public String encodeURL(String url)
Encode the session identifier associated with this response into the specified URL, if necessary.

Parameters:
url - URL to be encoded

isEncodeable

protected boolean isEncodeable(String location)
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:

Parameters:
location - Absolute URL to be validated

getContentCount

public int getContentCount()
Return the number of bytes actually written to the output stream.


setAppCommitted

public void setAppCommitted(boolean appCommitted)
Set the application commit flag.

Parameters:
appCommitted - The new application committed flag value

isAppCommitted

public boolean isAppCommitted()
Application commit flag accessor.


getIncluded

public boolean getIncluded()
Return the "processing inside an include" flag.


setIncluded

public void setIncluded(boolean included)
Set the "processing inside an include" flag.

Parameters:
included - true if we are currently inside a RequestDispatcher.include(), else false

getInfo

public String getInfo()
Return descriptive information about this Response implementation and the corresponding version number, in the format <description>/<version>.


getStream

public OutputStream getStream()
Return the output stream associated with this Response.


setStream

public void setStream(OutputStream stream)
Set the output stream associated with this Response.

Parameters:
stream - The new output stream

setSuspended

public void setSuspended(boolean suspended)
Set the suspended flag.

Parameters:
suspended - The new suspended flag value

isBufferSuspended

public boolean isBufferSuspended()
Suspended flag accessor.


setError

public void setError()
Set the error flag.


isError

public boolean isError()
Error flag accessor.


setDetailMessage

public void setDetailMessage(String message)
Sets detail error message.

Parameters:
message - detail error message

getDetailMessage

public String getDetailMessage()
Gets detail error message.

Returns:
the detail error message

createOutputStream

public GrizzlyOutputStream createOutputStream()
                                       throws IOException
Create and return a ServletOutputStream to write the content associated with this Response.

Throws:
IOException - if an input/output error occurs

finishResponse

public void finishResponse()
                    throws IOException
Perform whatever actions are required to flush and close the output stream or writer, in a single operation.

Throws:
IOException - if an input/output error occurs

getContentLength

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


getContentType

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


getReporter

public PrintWriter getReporter()
                        throws IOException
Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.

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.
Throws:
IOException - if an input/output error occurs

flushBuffer

public void flushBuffer()
                 throws IOException
Flush the buffer and commit this response.

Throws:
IOException - if an input/output error occurs

getBufferSize

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


getCharacterEncoding

public String getCharacterEncoding()
Return the character encoding used for this Response.


getOutputStream

public GrizzlyOutputStream getOutputStream()
                                    throws IOException
Return the servlet output stream associated with this Response.

Throws:
IllegalStateException - if getWriter has already been called for this response
IOException - if an input/output error occurs

getLocale

public Locale getLocale()
Return the Locale assigned to this response.


getWriter

public PrintWriter getWriter()
                      throws IOException
Return the writer associated with this Response.

Throws:
IllegalStateException - if getOutputStream has already been called for this response
IOException - if an input/output error occurs

isCommitted

public boolean isCommitted()
Has the output of this response already been committed?


reset

public void reset()
Clear any content written to the buffer.

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 - true if the internal usingWriter, usingOutputStream, isCharacterEncodingSet flags 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.

Parameters:
length - The new content length

setContentLength

public void setContentLength(int length)
Set the content length (in bytes) for this Response.

Parameters:
length - The new content length

setContentType

public void setContentType(String type)
Set the content type for this Response.

Parameters:
type - The new content type

setCharacterEncoding

public void setCharacterEncoding(String charset)

setLocale

public void setLocale(Locale locale)
Set the Locale that is appropriate for this response, including setting the appropriate character encoding.

Parameters:
locale - The new locale

getCookies

public Cookie[] getCookies()
Return an array of all cookies set for this response, or a zero-length array if no cookies have been set.


getHeader

public String getHeader(String name)
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 getHeaderValues() to retrieve all of them.

Parameters:
name - Header name to look up

getHeaderNames

public 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.


getHeaderValues

public 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.

Parameters:
name - Header name to look up

getMessage

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


getStatus

public int getStatus()
Return the HTTP status code associated with this Response.


reset

public void reset(int status,
                  String message)
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

public void addCookie(Cookie cookie)
Add the specified Cookie to those that will be included with this Response.

Parameters:
cookie - Cookie to be added

addDateHeader

public void addDateHeader(String name,
                          long value)
Add the specified date header to the specified value.

Parameters:
name - Name of the header to set
value - Date value to be set

addHeader

public void addHeader(String name,
                      String value)
Add the specified header to the specified value.

Parameters:
name - Name of the header to set
value - Value to be set

addIntHeader

public void addIntHeader(String name,
                         int value)
Add the specified integer header to the specified value.

Parameters:
name - Name of the header to set
value - Integer value to be set

containsHeader

public boolean containsHeader(String name)
Has the specified header been set already in this response?

Parameters:
name - Name of the header to check

sendAcknowledgement

public void sendAcknowledgement()
                         throws IOException
Send an acknowledgment of a request.

Throws:
IOException - if an input/output error occurs

sendError

public void sendError(int status)
               throws IOException
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 committed
IOException - if an input/output error occurs

sendError

public void sendError(int status,
                      String message)
               throws IOException
Send an error response with the specified status and message.

Parameters:
status - HTTP status code to send
message - Corresponding message to send
Throws:
IllegalStateException - if this response has already been committed
IOException - if an input/output error occurs

sendRedirect

public void sendRedirect(String location)
                  throws IOException
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 committed
IOException - if an input/output error occurs

setDateHeader

public void setDateHeader(String name,
                          long value)
Set the specified date header to the specified value.

Parameters:
name - Name of the header to set
value - Date value to be set

setHeader

public void setHeader(String name,
                      String value)
Set the specified header to the specified value.

Parameters:
name - Name of the header to set
value - Value to be set

setIntHeader

public void setIntHeader(String name,
                         int value)
Set the specified integer header to the specified value.

Parameters:
name - Name of the header to set
value - Integer value to be set

setStatus

public void setStatus(int status)
Set the HTTP status to be returned with this response.

Parameters:
status - The new HTTP status

setStatus

public void setStatus(int status,
                      String message)
Set the HTTP status and message to be returned with this response.

Parameters:
status - The new HTTP status
message - The associated text message

toAbsolute

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. 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

public static String filter(String message)
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

protected String toEncoded(String url,
                           String sessionId)
Return the specified URL with the specified session identifier suitably encoded.

Parameters:
url - URL to be encoded with the session id
sessionId - Session id to be included in the encoded URL

isCacheEnabled

public boolean isCacheEnabled()
Is the file cache enabled?


enableCache

public void enableCache(boolean cacheEnabled)
Enable/disable the cache


getOutputBuffer

public GrizzlyOutputBuffer getOutputBuffer()
Return the underlying OutputBuffer


setChunkingDisabled

public void setChunkingDisabled(boolean chunkingDisabled)
Enabled or Disable response chunking.

Parameters:
chunkingDisabled -

getChunkingDisabled

public boolean getChunkingDisabled()
Is chunking enabled?


resume

public void resume()
Complete the GrizzlyResponse and finish/commit it. If a CompletionHandler has been defined, its CompletionHandler#resumed(A) will first be invoked, then the finishResponse(). Those operations commit the response.


cancel

public void cancel()
Cancel the GrizzlyResponse and finish/commit it. If a CompletionHandler has been defined, its CompletionHandler#cancelled(A) will first be invoked, then the finishResponse(). Those operations commit the response.


isSuspended

public boolean isSuspended()
Return true if that suspend() has been invoked and set to true

Returns:
true if that suspend() has been invoked and set to true

suspend

public void suspend()
Suspend the Response. Suspending a Response will tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid commiting response.


suspend

public void suspend(long timeout)
Suspend the GrizzlyResponse. Suspending a GrizzlyResponse will tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid commiting response.

Parameters:
timeout - The maximum amount of time, in milliseconds, a GrizzlyResponse can be suspended. When the timeout expires (because nothing has been written or because the Response.resume() or cancel()), the GrizzlyResponse will be automatically resumed and commited. Usage of any methods of a GrizzlyResponse that times out will throw an IllegalStateException.

suspend

public void suspend(long timeout,
                    A attachment,
                    CompletionHandler<? super A> competionHandler)
Suspend the GrizzlyResponse. Suspending a GrizzlyResponse will tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid commiting response. When the resume() is invoked, the container will make sure CompletionHandler.resumed(E) is invoked with the original attachement. When the cancel() is invoked, the container will make sure CompletionHandler.cancelled(E) is invoked with the original attachement. If the timeout expires, the CompletionHandler.cancelled(E) is invoked with the original attachement and the Response commited.

Parameters:
timeout - The maximum amount of time, in milliseconds, a GrizzlyResponse can be suspended. When the timeout expires (because nothing has been written or because the resume() or cancel()), the GrizzlyResponse will be automatically resumed and commited. Usage of any methods of a Response that times out will throw an IllegalStateException.
attachment - Any Object that will be passed back to the CompletionHandler
competionHandler - a CompletionHandler

addResponseFilter

public void addResponseFilter(ResponseFilter responseFilter)
Add a ResponseFilter, which will be called every bytes are ready to be written.



Copyright © 2013 Oracle Corporation. All Rights Reserved.