com.caucho.server.http
Class StubServletResponse

java.lang.Object
  extended by com.caucho.server.http.StubServletResponse
All Implemented Interfaces:
CauchoResponse, HttpServletResponse, ServletResponse

public class StubServletResponse
extends java.lang.Object
implements CauchoResponse


Field Summary
 
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_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Constructor Summary
StubServletResponse()
           
 
Method Summary
 void addCookie(Cookie cookie)
          Sends a new cookie to the client.
 void addDateHeader(java.lang.String header, long value)
          Adds a header by converting a date to a string.
 void addFooter(java.lang.String key, java.lang.String value)
           
 void addHeader(java.lang.String header, java.lang.String value)
          Adds a header.
 void addIntHeader(java.lang.String header, int value)
          Adds a header by converting an integer value to a string.
 void clearBuffer()
           
 void close()
           
 void completeCache()
           
 boolean containsHeader(java.lang.String header)
          Returns true if the output headers include name
protected  AbstractResponseStream createResponseStream()
           
 void disable()
           
 boolean disableHeaders(boolean disable)
           
 void enable()
           
 java.lang.String encodeRedirectUrl(java.lang.String url)
           
 java.lang.String encodeRedirectURL(java.lang.String url)
          Encodes session information in a URL suitable for sendRedirect()
 java.lang.String encodeUrl(java.lang.String url)
           
 java.lang.String encodeURL(java.lang.String url)
          Encodes session information in a URL.
 void flushBuffer()
          Flushes the buffer to the client.
 AbstractHttpResponse getAbstractHttpResponse()
           
 int getBufferSize()
          Returns the size of the output buffer.
 java.lang.String getCharacterEncoding()
          Returns the character encoding the response is using for output.
 java.lang.String getContentType()
          Returns the content type for the response.
 FlushBuffer getFlushBuffer()
           
 boolean getForbidForward()
           
 java.lang.String getHeader(java.lang.String key)
          Retuns value of header with a given name
 java.util.Collection<java.lang.String> getHeaderNames()
          Returns an Iterable for header names set via HttpServletResponse.setHeader(java.lang.String, java.lang.String), HttpServletResponse.addHeader(java.lang.String, java.lang.String), HttpServletResponse.setDateHeader(java.lang.String, long), HttpServletResponse.addDateHeader(java.lang.String, long), HttpServletResponse.setIntHeader(java.lang.String, int), or HttpServletResponse.addIntHeader(java.lang.String, int), respectively.
 java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
          Returns an Iterable for header values with a given name
 java.util.Locale getLocale()
          Returns the output locale.
 ServletOutputStream getOutputStream()
          Returns an output stream for writing to the client.
 int getRemaining()
           
 ServletResponse getResponse()
          Return wrapped response
 AbstractResponseStream getResponseStream()
           
 int getStatus()
          Returns the current status code of this response
 int getStatusCode()
           
 java.lang.String getStatusMessage()
           
 java.io.PrintWriter getWriter()
          Returns a PrintWriter with the proper character encoding for writing text data to the client.
 boolean hasError()
           
 boolean isCauchoResponseStream()
           
 boolean isCommitted()
          Returns true if some data has actually been send to the client.
 boolean isDisabled()
           
 boolean isForwardEnclosed()
           
 boolean isNoCacheUnlessVary()
           
 void killCache()
           
 void reset()
          Resets the output stream, clearing headers and the output buffer.
 void resetBuffer()
          Resets the output stream, clearing headers and the output buffer.
 void sendError(int i)
          Sends an HTTP error page based on the status code
 void sendError(int i, java.lang.String message)
          Sends an HTTP error page based on the status code
 void sendRedirect(java.lang.String location)
          Redirects the client to another page.
 void setBufferSize(int size)
          Sets the output buffer size to size.
 void setCacheInvocation(AbstractCacheFilterChain cacheFilterChain)
           
 void setCharacterEncoding(java.lang.String enc)
          Sets the character encoding the response is using for output.
 void setContentLength(int length)
          Explicitly sets the length of the result value.
 void setContentType(java.lang.String type)
          Sets the response content type.
 void setDateHeader(java.lang.String header, long value)
          Sets a header by converting a date to a string.
 void setFlushBuffer(FlushBuffer out)
           
 void setFooter(java.lang.String key, java.lang.String value)
           
 void setForbidForward(boolean forbid)
           
 void setForwardEnclosed(boolean isForwardEnclosed)
           
 void setHasError(boolean hasError)
           
 void setHeader(java.lang.String header, java.lang.String value)
          Sets a header.
 void setIntHeader(java.lang.String header, int value)
          Sets a header by converting an integer value to a string.
 void setLocale(java.util.Locale locale)
          Sets the output locale.
 void setMatchCacheEntry(AbstractCacheEntry cacheEntry)
           
 void setNoCache(boolean killCache)
           
 void setPrivateCache(boolean isPrivate)
           
 void setResponseStream(AbstractResponseStream stream)
           
 void setSessionId(java.lang.String id)
           
 void setStatus(int status)
          Sets the HTTP status
 void setStatus(int status, java.lang.String messages)
           
 void writeHeaders(int length)
           
 boolean writeHeadersInt(WriteStream out, int length, boolean isHead)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StubServletResponse

public StubServletResponse()
Method Detail

createResponseStream

protected AbstractResponseStream createResponseStream()

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Description copied from interface: ServletResponse
Returns the character encoding the response is using for output. If no character encoding is specified, ISO-8859-1 will be used.

Specified by:
getCharacterEncoding in interface ServletResponse

setLocale

public void setLocale(java.util.Locale locale)
Description copied from interface: ServletResponse
Sets the output locale. The response will set the character encoding based on the locale. For example, setting the "kr" locale will set the character encoding to "EUC_KR".

Specified by:
setLocale in interface ServletResponse

getLocale

public java.util.Locale getLocale()
Description copied from interface: ServletResponse
Returns the output locale.

Specified by:
getLocale in interface ServletResponse

writeHeadersInt

public boolean writeHeadersInt(WriteStream out,
                               int length,
                               boolean isHead)

setBufferSize

public void setBufferSize(int size)
Description copied from interface: ServletResponse
Sets the output buffer size to size. The servlet engine may round the size up.

Specified by:
setBufferSize in interface ServletResponse
Parameters:
size - the new output buffer size.

getBufferSize

public int getBufferSize()
Description copied from interface: ServletResponse
Returns the size of the output buffer.

Specified by:
getBufferSize in interface ServletResponse

flushBuffer

public void flushBuffer()
Description copied from interface: ServletResponse
Flushes the buffer to the client.

Specified by:
flushBuffer in interface ServletResponse

isCommitted

public boolean isCommitted()
Description copied from interface: ServletResponse
Returns true if some data has actually been send to the client. The data will be sent if the buffer overflows or if it's explicitly flushed.

Specified by:
isCommitted in interface ServletResponse

reset

public void reset()
Description copied from interface: ServletResponse
Resets the output stream, clearing headers and the output buffer. Calling reset() after data has been committed is illegal.

Specified by:
reset in interface ServletResponse

resetBuffer

public void resetBuffer()
Description copied from interface: ServletResponse
Resets the output stream, clearing headers and the output buffer. Calling reset() after data has been committed is illegal.

Specified by:
resetBuffer in interface ServletResponse

setContentLength

public void setContentLength(int length)
Description copied from interface: ServletResponse
Explicitly sets the length of the result value. Normally, the servlet engine will handle this.

Specified by:
setContentLength in interface ServletResponse

setContentType

public void setContentType(java.lang.String type)
Description copied from interface: ServletResponse
Sets the response content type. The content type includes the character encoding. The content type must be set before calling getWriter() so the writer can use the proper character encoding.

To set the output character encoding to ISO-8859-2, use the following:

 response.setContentType("text/html; charset=ISO-8859-2");
 

Specified by:
setContentType in interface ServletResponse
Parameters:
type - the mime type of the output

setStatus

public void setStatus(int status)
Description copied from interface: HttpServletResponse
Sets the HTTP status

Specified by:
setStatus in interface HttpServletResponse
Parameters:
status - the HTTP status code

setStatus

public void setStatus(int status,
                      java.lang.String messages)
Specified by:
setStatus in interface HttpServletResponse

sendRedirect

public void sendRedirect(java.lang.String location)
Description copied from interface: HttpServletResponse
Redirects the client to another page.

Specified by:
sendRedirect in interface HttpServletResponse
Parameters:
location - the location to redirect to.

sendError

public void sendError(int i)
Description copied from interface: HttpServletResponse
Sends an HTTP error page based on the status code

Specified by:
sendError in interface HttpServletResponse
Parameters:
i - the HTTP status code

sendError

public void sendError(int i,
                      java.lang.String message)
Description copied from interface: HttpServletResponse
Sends an HTTP error page based on the status code

Specified by:
sendError in interface HttpServletResponse
Parameters:
i - the HTTP status code

encodeUrl

public java.lang.String encodeUrl(java.lang.String url)
Specified by:
encodeUrl in interface HttpServletResponse

encodeURL

public java.lang.String encodeURL(java.lang.String url)
Description copied from interface: HttpServletResponse
Encodes session information in a URL. Calling this will enable sessions for users who have disabled cookies.

Specified by:
encodeURL in interface HttpServletResponse
Parameters:
url - the url to encode
Returns:
a url with session information encoded

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String url)
Specified by:
encodeRedirectUrl in interface HttpServletResponse

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String url)
Description copied from interface: HttpServletResponse
Encodes session information in a URL suitable for sendRedirect()

Specified by:
encodeRedirectURL in interface HttpServletResponse
Parameters:
url - the url to encode
Returns:
a url with session information encoded

addCookie

public void addCookie(Cookie cookie)
Description copied from interface: HttpServletResponse
Sends a new cookie to the client.

Specified by:
addCookie in interface HttpServletResponse

containsHeader

public boolean containsHeader(java.lang.String header)
Description copied from interface: HttpServletResponse
Returns true if the output headers include name

Specified by:
containsHeader in interface HttpServletResponse
Parameters:
header - the header name to test

setHeader

public void setHeader(java.lang.String header,
                      java.lang.String value)
Description copied from interface: HttpServletResponse
Sets a header. This will override a previous header with the same name.

Specified by:
setHeader in interface HttpServletResponse
Parameters:
header - the header name
value - the header value

setIntHeader

public void setIntHeader(java.lang.String header,
                         int value)
Description copied from interface: HttpServletResponse
Sets a header by converting an integer value to a string.

Specified by:
setIntHeader in interface HttpServletResponse
Parameters:
header - name of the header
value - the value as an integer

setDateHeader

public void setDateHeader(java.lang.String header,
                          long value)
Description copied from interface: HttpServletResponse
Sets a header by converting a date to a string.

To set the page to expire in 15 seconds use the following:


 long now = System.currentTime();
 response.setDateHeader("Expires", now + 15000);
 

Specified by:
setDateHeader in interface HttpServletResponse
Parameters:
header - name of the header
value - the date in milliseconds since the epoch.

addHeader

public void addHeader(java.lang.String header,
                      java.lang.String value)
Description copied from interface: HttpServletResponse
Adds a header. If another header with the same name exists, both will be sent to the client.

Specified by:
addHeader in interface HttpServletResponse
Parameters:
header - the header name
value - the header value

addIntHeader

public void addIntHeader(java.lang.String header,
                         int value)
Description copied from interface: HttpServletResponse
Adds a header by converting an integer value to a string.

Specified by:
addIntHeader in interface HttpServletResponse
Parameters:
header - name of the header
value - the value as an integer

addDateHeader

public void addDateHeader(java.lang.String header,
                          long value)
Description copied from interface: HttpServletResponse
Adds a header by converting a date to a string.

Specified by:
addDateHeader in interface HttpServletResponse
Parameters:
header - name of the header
value - the date in milliseconds since the epoch.

getHeader

public java.lang.String getHeader(java.lang.String key)
Description copied from interface: HttpServletResponse
Retuns value of header with a given name

Specified by:
getHeader in interface CauchoResponse
Specified by:
getHeader in interface HttpServletResponse
Returns:

clearBuffer

public void clearBuffer()

completeCache

public void completeCache()
Specified by:
completeCache in interface CauchoResponse

close

public void close()
           throws java.io.IOException
Specified by:
close in interface CauchoResponse
Throws:
java.io.IOException

disableHeaders

public boolean disableHeaders(boolean disable)

getRemaining

public int getRemaining()

setForbidForward

public void setForbidForward(boolean forbid)
Specified by:
setForbidForward in interface CauchoResponse

getForbidForward

public boolean getForbidForward()
Specified by:
getForbidForward in interface CauchoResponse

setHasError

public void setHasError(boolean hasError)
Specified by:
setHasError in interface CauchoResponse

hasError

public boolean hasError()
Specified by:
hasError in interface CauchoResponse

killCache

public void killCache()
Specified by:
killCache in interface CauchoResponse

setPrivateCache

public void setPrivateCache(boolean isPrivate)
Specified by:
setPrivateCache in interface CauchoResponse

setSessionId

public void setSessionId(java.lang.String id)
Specified by:
setSessionId in interface CauchoResponse

getStatus

public int getStatus()
Description copied from interface: HttpServletResponse
Returns the current status code of this response

Specified by:
getStatus in interface HttpServletResponse
Returns:

getHeaders

public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface: HttpServletResponse
Returns an Iterable for header values with a given name

Specified by:
getHeaders in interface HttpServletResponse
Returns:

getHeaderNames

public java.util.Collection<java.lang.String> getHeaderNames()
Description copied from interface: HttpServletResponse
Returns an Iterable for header names set via HttpServletResponse.setHeader(java.lang.String, java.lang.String), HttpServletResponse.addHeader(java.lang.String, java.lang.String), HttpServletResponse.setDateHeader(java.lang.String, long), HttpServletResponse.addDateHeader(java.lang.String, long), HttpServletResponse.setIntHeader(java.lang.String, int), or HttpServletResponse.addIntHeader(java.lang.String, int), respectively.

Specified by:
getHeaderNames in interface HttpServletResponse
Returns:

getAbstractHttpResponse

public AbstractHttpResponse getAbstractHttpResponse()
Specified by:
getAbstractHttpResponse in interface CauchoResponse

getResponse

public ServletResponse getResponse()
Description copied from interface: CauchoResponse
Return wrapped response

Specified by:
getResponse in interface CauchoResponse

setNoCache

public void setNoCache(boolean killCache)
Specified by:
setNoCache in interface CauchoResponse

getStatusCode

public int getStatusCode()

getStatusMessage

public java.lang.String getStatusMessage()
Specified by:
getStatusMessage in interface CauchoResponse

setFooter

public void setFooter(java.lang.String key,
                      java.lang.String value)
Specified by:
setFooter in interface CauchoResponse

addFooter

public void addFooter(java.lang.String key,
                      java.lang.String value)
Specified by:
addFooter in interface CauchoResponse

setFlushBuffer

public void setFlushBuffer(FlushBuffer out)

getFlushBuffer

public FlushBuffer getFlushBuffer()

isCauchoResponseStream

public boolean isCauchoResponseStream()
Specified by:
isCauchoResponseStream in interface CauchoResponse

setResponseStream

public void setResponseStream(AbstractResponseStream stream)
Specified by:
setResponseStream in interface CauchoResponse

getResponseStream

public AbstractResponseStream getResponseStream()
Specified by:
getResponseStream in interface CauchoResponse

isDisabled

public boolean isDisabled()

enable

public void enable()

disable

public void disable()

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Description copied from interface: ServletResponse
Returns a PrintWriter with the proper character encoding for writing text data to the client.

Specified by:
getWriter in interface ServletResponse
Throws:
java.io.IOException

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws java.io.IOException
Description copied from interface: ServletResponse
Returns an output stream for writing to the client. You can use the output stream to write binary data.

Specified by:
getOutputStream in interface ServletResponse
Throws:
java.io.IOException

setCharacterEncoding

public void setCharacterEncoding(java.lang.String enc)
Description copied from interface: ServletResponse
Sets the character encoding the response is using for output. If no character encoding is specified, ISO-8859-1 will be used.

Specified by:
setCharacterEncoding in interface ServletResponse

getContentType

public java.lang.String getContentType()
Description copied from interface: ServletResponse
Returns the content type for the response.

Specified by:
getContentType in interface ServletResponse

isNoCacheUnlessVary

public boolean isNoCacheUnlessVary()
Specified by:
isNoCacheUnlessVary in interface CauchoResponse

setCacheInvocation

public void setCacheInvocation(AbstractCacheFilterChain cacheFilterChain)
Specified by:
setCacheInvocation in interface CauchoResponse

setMatchCacheEntry

public void setMatchCacheEntry(AbstractCacheEntry cacheEntry)

setForwardEnclosed

public void setForwardEnclosed(boolean isForwardEnclosed)
Specified by:
setForwardEnclosed in interface CauchoResponse

isForwardEnclosed

public boolean isForwardEnclosed()
Specified by:
isForwardEnclosed in interface CauchoResponse

writeHeaders

public void writeHeaders(int length)
Specified by:
writeHeaders in interface CauchoResponse