org.w3c.jigsaw.servlet
Class JigsawHttpServletResponse

java.lang.Object
  extended by org.w3c.jigsaw.servlet.JigsawHttpServletResponse
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class JigsawHttpServletResponse
extends java.lang.Object
implements javax.servlet.http.HttpServletResponse


Field Summary
protected  int buffer_size
           
static java.lang.String CHARSET_PARAMETER
           
static int DEFAULT_BUFFER_SIZE
           
static java.lang.String INCLUDED
           
protected  JigsawHttpServletRequest jrequest
           
protected  java.util.Locale locale
           
static int MIN_BUFFER_SIZE
           
static java.lang.String MONITOR
           
protected  java.io.ByteArrayOutputStream out
          Our temp stream.
protected  java.io.PipedOutputStream pout
           
static java.lang.String STREAM
           
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, 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_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
          Adds the specified cookie to the response.
 void addDateHeader(java.lang.String name, long date)
           
 void addHeader(java.lang.String name, java.lang.String value)
           
 void addIntHeader(java.lang.String name, int value)
           
 boolean containsHeader(java.lang.String header)
          Checks whether the response message header has a field with the specified name.
 java.lang.String encodeRedirectUrl(java.lang.String url)
          Deprecated. since jsdk2.1
 java.lang.String encodeRedirectURL(java.lang.String url)
          Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
 java.lang.String encodeUrl(java.lang.String url)
          Deprecated. since jsdk2.1
 java.lang.String encodeURL(java.lang.String url)
          Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
 void flushBuffer()
          Forces any content in the buffer to be written to the client.
protected  void flushStream(boolean close)
          Flush the output stream.
 int getBufferSize()
          Returns the actual buffer size used for the response.
 java.lang.String getCharacterEncoding()
          Return the Charset parameter of content type
 java.util.Locale getLocale()
          Returns the locale assigned to the response.
 javax.servlet.ServletOutputStream getOutputStream()
          Returns an output stream for writing binary response data.
protected  java.io.OutputStream getRawOutputStream()
          returns the raw output stream regardless of what happened before used for internal operation (e.g.
protected  Reply getReply()
           
 java.io.PrintWriter getWriter()
          Returns a print writer for writing formatted text responses.
 boolean isCommitted()
          Returns a boolean indicating if the response has been committed.
protected  boolean isStreamObtained()
           
 void reset()
          Clears any data that exists in the buffer as well as the status code and headers.
 void resetBuffer()
          Clears any data that exists in the buffer but not status code and headers.
 void sendError(int i)
          Sends an error response to the client using the specified status code and a default message.
 void sendError(int i, java.lang.String msg)
          Sends an error response to the client using the specified status code and descriptive message.
 void sendRedirect(java.lang.String url)
          Sends a temporary redirect response to the client using the specified redirect location URL.
 void setBufferSize(int size)
          Sets the preferred buffer size for the body of the response.
 void setContentLength(int i)
          Sets the content length for this response.
 void setContentType(java.lang.String spec)
          Sets the content type for this response.
 void setDateHeader(java.lang.String name, long date)
          Adds a field to the response header with the given name and date-valued field.
 void setHeader(java.lang.String name, java.lang.String value)
          Adds a field to the response header with the given name and value.
 void setIntHeader(java.lang.String name, int value)
          Adds a field to the response header with the given name and integer value.
 void setLocale(java.util.Locale locale)
          Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
protected  void setServletRequest(JigsawHttpServletRequest jrequest)
           
 void setStatus(int i)
          Sets the status code for this response.
 void setStatus(int i, java.lang.String reason)
          Deprecated. since jsdk2.1
 void unsetHeader(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARSET_PARAMETER

public static final java.lang.String CHARSET_PARAMETER
See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

MIN_BUFFER_SIZE

public static final int MIN_BUFFER_SIZE
See Also:
Constant Field Values

locale

protected java.util.Locale locale

out

protected java.io.ByteArrayOutputStream out
Our temp stream.


pout

protected java.io.PipedOutputStream pout

jrequest

protected JigsawHttpServletRequest jrequest

buffer_size

protected int buffer_size

INCLUDED

public static final java.lang.String INCLUDED
See Also:
Constant Field Values

STREAM

public static final java.lang.String STREAM
See Also:
Constant Field Values

MONITOR

public static final java.lang.String MONITOR
See Also:
Constant Field Values
Method Detail

setServletRequest

protected void setServletRequest(JigsawHttpServletRequest jrequest)

setContentLength

public void setContentLength(int i)
Sets the content length for this response.

Specified by:
setContentLength in interface javax.servlet.ServletResponse
Parameters:
len - - the content length

setContentType

public void setContentType(java.lang.String spec)
Sets the content type for this response. This type may later be implicitly modified by addition of properties such as the MIME charset= if the service finds it necessary, and the appropriate media type property has not been set.

This response property may only be assigned one time. If a writer is to be used to write a text response, this method must be called before the method getWriter. If an output stream will be used to write a response, this method must be called before the output stream is used to write response data.

Specified by:
setContentType in interface javax.servlet.ServletResponse
Parameters:
spec - - the content's MIME type
See Also:
getOutputStream(), getWriter()

isStreamObtained

protected boolean isStreamObtained()

getReply

protected Reply getReply()

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Returns an output stream for writing binary response data.

Specified by:
getOutputStream in interface javax.servlet.ServletResponse
Returns:
A ServletOutputStream
Throws:
java.io.IOException - if an I/O exception has occurred
java.lang.IllegalStateException - if getWriter has been called on this same request.
See Also:
getWriter()

getRawOutputStream

protected java.io.OutputStream getRawOutputStream()
returns the raw output stream regardless of what happened before used for internal operation (e.g. writing an exception trailer).

Returns:
an underlying output stream if available (even when a writer is used)

setStatus

public void setStatus(int i,
                      java.lang.String reason)
Deprecated. since jsdk2.1

Sets the status code and message for this response. If the field had already been set, the new value overwrites the previous one. The message is sent as the body of an HTML page, which is returned to the user to describe the problem. The page is sent with a default HTML header; the message is enclosed in simple body tags ().

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Parameters:
i - - the status code
reason - - the status message

setStatus

public void setStatus(int i)
Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there is an error, the sendError method should be used instead.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Parameters:
i - - the status code
See Also:
sendError(int, java.lang.String)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Adds a field to the response header with the given name and value. If the field had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - - the name of the header field
value - - the header field's value
See Also:
containsHeader(java.lang.String)

setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Adds a field to the response header with the given name and integer value. If the field had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - - the name of the header field
value - - the header field's integer value
See Also:
containsHeader(java.lang.String)

setDateHeader

public void setDateHeader(java.lang.String name,
                          long date)
Adds a field to the response header with the given name and date-valued field. The date is specified in terms of milliseconds since the epoch. If the date field had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - - the name of the header field
value - - the header field's date value
See Also:
containsHeader(java.lang.String)

unsetHeader

public void unsetHeader(java.lang.String name)

sendError

public void sendError(int i,
                      java.lang.String msg)
               throws java.io.IOException
Sends an error response to the client using the specified status code and descriptive message. If setStatus has previously been called, it is reset to the error status code. The message is sent as the body of an HTML page, which is returned to the user to describe the problem. The page is sent with a default HTML header; the message is enclosed in simple body tags ().

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Parameters:
sc - - the status code
msg - - the detail message
Throws:
java.io.IOException - If an I/O error has occurred.

sendError

public void sendError(int i)
               throws java.io.IOException
Sends an error response to the client using the specified status code and a default message.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Parameters:
sc - - the status code
Throws:
java.io.IOException - If an I/O error has occurred.

sendRedirect

public void sendRedirect(java.lang.String url)
                  throws java.io.IOException
Sends a temporary redirect response to the client using the specified redirect location URL. The URL must be absolute (for example, https://hostname/path/file.html). Relative URLs are not permitted here.

Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Parameters:
url - - the redirect location URL
Throws:
java.io.IOException - If an I/O error has occurred.

containsHeader

public boolean containsHeader(java.lang.String header)
Checks whether the response message header has a field with the specified name.

Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - - the header field name
Returns:
true if the response message header has a field with the specified name; false otherwise

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response. It can be called multiple times to set more than one cookie.

Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse
Parameters:
cookie - - the Cookie to return to the client

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String url)
Deprecated. since jsdk2.1

Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method should include the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination differ from those used to decide whether to encode a normal link, this method is seperate from the encodeUrl method.

All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting canont be used with browsers which do not support cookies.

Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse
Parameters:
url - - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.
See Also:
sendRedirect(java.lang.String), encodeUrl(java.lang.String)

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method should include the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination differ from those used to decide whether to encode a normal link, this method is seperate from the encodeUrl method.

All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting canont be used with browsers which do not support cookies.

Specified by:
encodeRedirectURL in interface javax.servlet.http.HttpServletResponse
Parameters:
url - - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.
See Also:
sendRedirect(java.lang.String), encodeUrl(java.lang.String)

encodeUrl

public java.lang.String encodeUrl(java.lang.String url)
Deprecated. since jsdk2.1

Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method should include the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

All URLs emitted by a Servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse
Parameters:
url - - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeURL

public java.lang.String encodeURL(java.lang.String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method should include the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

All URLs emitted by a Servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

Specified by:
encodeURL in interface javax.servlet.http.HttpServletResponse
Parameters:
url - - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Return the Charset parameter of content type

Specified by:
getCharacterEncoding in interface javax.servlet.ServletResponse
Returns:
A String instance

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException,
                                     java.io.UnsupportedEncodingException
Returns a print writer for writing formatted text responses. The MIME type of the response will be modified, if necessary, to reflect the character encoding used, through the charset=... property. This means that the content type must be set before calling this method.

Specified by:
getWriter in interface javax.servlet.ServletResponse
Throws:
java.io.UnsupportedEncodingException - if no such encoding can be provided
java.lang.IllegalStateException - if getOutputStream has been called on this same request.
java.io.IOException - on other errors.
See Also:
getOutputStream(), setContentType(java.lang.String)

flushStream

protected void flushStream(boolean close)
                    throws java.io.IOException
Flush the output stream.

Parameters:
close - Close the stream if true.
Throws:
java.io.IOException - if an IO error occurs.

setBufferSize

public void setBufferSize(int size)
Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using getBufferSize.

A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.

This method must be called before any response body content is written; if content has been written, this method throws an IllegalStateException.

Specified by:
setBufferSize in interface javax.servlet.ServletResponse
Parameters:
size - the preferred buffer size
Throws:
java.lang.IllegalStateException - if this method is called after content has been written
See Also:
getBufferSize(), flushBuffer(), isCommitted(), reset()

getBufferSize

public int getBufferSize()
Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.

Specified by:
getBufferSize in interface javax.servlet.ServletResponse
Returns:
the actual buffer size used
See Also:
setBufferSize(int), flushBuffer(), isCommitted(), reset()

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.

Specified by:
flushBuffer in interface javax.servlet.ServletResponse
Throws:
java.io.IOException
See Also:
setBufferSize(int), getBufferSize(), isCommitted(), reset()

isCommitted

public boolean isCommitted()
Returns a boolean indicating if the response has been committed. A commited response has already had its status code and headers written.

Specified by:
isCommitted in interface javax.servlet.ServletResponse
Returns:
a boolean indicating if the response has been committed
See Also:
setBufferSize(int), getBufferSize(), flushBuffer(), reset()

reset

public void reset()
Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.

Specified by:
reset in interface javax.servlet.ServletResponse
Throws:
java.lang.IllegalStateException - if the response has already been committed
See Also:
setBufferSize(int), getBufferSize(), flushBuffer(), isCommitted()

resetBuffer

public void resetBuffer()
Clears any data that exists in the buffer but not status code and headers. If the response has been committed, this method throws an IllegalStateException.

Throws:
java.lang.IllegalStateException - if the response has already been committed
See Also:
setBufferSize(int), getBufferSize(), flushBuffer(), isCommitted()

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. This method should be called before a call to getWriter(). By default, the response locale is the default locale for the server.

Specified by:
setLocale in interface javax.servlet.ServletResponse
Parameters:
loc - the locale of the response
See Also:
getLocale()

getLocale

public java.util.Locale getLocale()
Returns the locale assigned to the response.

Specified by:
getLocale in interface javax.servlet.ServletResponse
See Also:
setLocale(java.util.Locale)

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse

addDateHeader

public void addDateHeader(java.lang.String name,
                          long date)
Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse

addIntHeader

public void addIntHeader(java.lang.String name,
                         int value)
Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse