com.caucho.server.http
Class HttpServletResponseImpl

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

public final class HttpServletResponseImpl
extends AbstractCauchoResponse
implements CauchoResponse

User facade for http responses.


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
HttpServletResponseImpl(HttpServletRequestImpl request, AbstractHttpResponse response)
           
 
Method Summary
 void addCookie(Cookie cookie)
          Adds a cookie to the response.
 void addDateHeader(java.lang.String name, long date)
          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 name, java.lang.String value)
          Adds a header.
 void addIntHeader(java.lang.String name, int value)
          Adds a header by converting an integer value to a string.
protected  void addServletCookie(WebApp webApp)
           
 void close()
           
 void closeImpl()
           
 boolean containsHeader(java.lang.String name)
          Returns true if the output headers include name
protected  Cookie createServletCookie(WebApp webApp)
           
 void disable()
          Disables the response
 void enable()
          Enables the response
 java.lang.String encodeAbsoluteRedirect(java.lang.String url)
           
 java.lang.String encodeRedirectUrl(java.lang.String string)
          Deprecated.  
 java.lang.String encodeRedirectURL(java.lang.String string)
          Encodes session information in a URL suitable for sendRedirect()
 java.lang.String encodeUrl(java.lang.String string)
          Deprecated.  
 java.lang.String encodeURL(java.lang.String string)
          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.
 AbstractCacheFilterChain getCacheInvocation()
           
 java.lang.String getCharacterEncoding()
          Gets the character encoding.
 java.lang.String getCharacterEncodingImpl()
          Gets the character encoding.
 java.lang.String getContentType()
          Gets the content type.
 java.lang.String getContentTypeImpl()
          Gets the content type.
 Cookie getCookie(java.lang.String name)
           
 java.util.ArrayList<Cookie> getCookies()
           
 boolean getForbidForward()
          Returns true if RequestDispatcher.forward() is disallowed on this stream.
 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.
 boolean getPrivateCache()
          Returns the value of the private cache.
 int getRemaining()
           
 HttpServletRequestImpl getRequest()
           
 ServletResponse getResponse()
          Return wrapped response
 AbstractResponseStream getResponseStream()
           
 java.lang.String getSessionId()
           
 int getStatus()
          Returns the current status code of this response
 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 isCacheControl()
          True if the application has a set a cache-control directive that Resin doesn't understand.
 boolean isCauchoResponseStream()
           
 boolean isCommitted()
          Returns true if some data has actually been send to the client.
 boolean isDisableCache()
           
 boolean isDisabled()
          Returns true if the response is disabled
 boolean isForwardEnclosed()
           
 boolean isNoCache()
          Returns true if the page is non-cacheable
 boolean isNoCacheUnlessVary()
          Return true if no-cache without var.
 boolean isPrivateCache()
          Returns true if the response should contain a Cache-Control: private
 void killCache()
          Set if the page is non-cacheable.
 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 code)
          Sends an HTTP error page based on the status code
 void sendError(int code, java.lang.String value)
          Sends an HTTP error to the browser.
 void sendRedirect(java.lang.String url)
          Sends a redirect to the browser.
 void setBufferSize(int size)
          Sets the output buffer size to size.
 void setCacheControl(boolean isCacheControl)
          True if the application has a set a cache-control directive that Resin doesn't understand.
 void setCacheInvocation(AbstractCacheFilterChain cacheInvocation)
          Sets the cache invocation to indicate that the response might be cacheable.
 void setCharacterEncoding(java.lang.String encoding)
          Sets the character encoding.
 void setContentLength(int len)
          Explicitly sets the length of the result value.
 void setContentType(java.lang.String value)
          Sets the browser content type.
 void setDateHeader(java.lang.String name, long date)
          Sets a header by converting a date to a string.
 void setFooter(java.lang.String key, java.lang.String value)
           
 void setForbidForward(boolean forbid)
          When set to true, RequestDispatcher.forward() is disallowed on this stream.
 void setForwardEnclosed(boolean isForwardEnclosed)
           
 void setHasError(boolean error)
           
 void setHeader(java.lang.String name, java.lang.String value)
          Sets a header.
 void setIntHeader(java.lang.String name, int value)
          Sets a header by converting an integer value to a string.
 void setLocale(java.util.Locale locale)
          Sets the output locale.
 void setNoCache(boolean isNoCache)
          Set if the page is non-cacheable.
 void setNoCacheUnlessVary(boolean isNoCacheUnlessVary)
          Set no cache w/o vary
 void setPrivateCache(boolean isPrivate)
          Sets true if the cache is only for the browser, but not Resin's cache or proxies.
 void setPrivateOrResinCache(boolean isPrivate)
          Sets true if the cache is only for the browser and Resin's cache but not proxies.
 void setResponseStream(AbstractResponseStream responseStream)
           
 void setSessionId(java.lang.String id)
           
 void setStatus(int code)
          Sets the HTTP status
 void setStatus(int code, java.lang.String message)
          Sets the HTTP status
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.server.http.AbstractCauchoResponse
completeCache, writeHeaders
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.server.http.CauchoResponse
completeCache, writeHeaders
 

Constructor Detail

HttpServletResponseImpl

public HttpServletResponseImpl(HttpServletRequestImpl request,
                               AbstractHttpResponse response)
Method Detail

getRequest

public HttpServletRequestImpl getRequest()

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws java.io.IOException
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

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
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

setBufferSize

public void setBufferSize(int size)
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()
Returns the size of the output buffer.

Specified by:
getBufferSize in interface ServletResponse

getRemaining

public int getRemaining()

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Flushes the buffer to the client.

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

isCommitted

public boolean isCommitted()
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()
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
Throws:
java.lang.IllegalStateException - if isCommitted() is true.

resetBuffer

public void resetBuffer()
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
Throws:
java.lang.IllegalStateException - if isCommitted() is true.

setContentLength

public void setContentLength(int len)
Explicitly sets the length of the result value. Normally, the servlet engine will handle this.

Specified by:
setContentLength in interface ServletResponse

disable

public void disable()
Disables the response

Since:
Servlet 3.0

enable

public void enable()
Enables the response

Since:
Servlet 3.0

isDisabled

public boolean isDisabled()
Returns true if the response is disabled

Since:
Servlet 3.0

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

setPrivateCache

public void setPrivateCache(boolean isPrivate)
Sets true if the cache is only for the browser, but not Resin's cache or proxies.

Since proxy caching also caches headers, cached pages with session ids can't be cached in the browser. XXX: but doesn't this just mean that Resin shouldn't send the session information back if the page is cached? Because a second request where everything is identical would see the same response except for the cookies.

Specified by:
setPrivateCache in interface CauchoResponse

setPrivateOrResinCache

public void setPrivateOrResinCache(boolean isPrivate)
Sets true if the cache is only for the browser and Resin's cache but not proxies.


setCacheInvocation

public void setCacheInvocation(AbstractCacheFilterChain cacheInvocation)
Sets the cache invocation to indicate that the response might be cacheable.

Specified by:
setCacheInvocation in interface CauchoResponse

getCacheInvocation

public final AbstractCacheFilterChain getCacheInvocation()

setNoCacheUnlessVary

public void setNoCacheUnlessVary(boolean isNoCacheUnlessVary)
Set no cache w/o vary


isNoCacheUnlessVary

public boolean isNoCacheUnlessVary()
Return true if no-cache without var.

Specified by:
isNoCacheUnlessVary in interface CauchoResponse

getPrivateCache

public boolean getPrivateCache()
Returns the value of the private cache.


isPrivateCache

public boolean isPrivateCache()
Returns true if the response should contain a Cache-Control: private


isCacheControl

public boolean isCacheControl()
True if the application has a set a cache-control directive that Resin doesn't understand.


setCacheControl

public void setCacheControl(boolean isCacheControl)
True if the application has a set a cache-control directive that Resin doesn't understand.


setNoCache

public void setNoCache(boolean isNoCache)
Set if the page is non-cacheable.

Specified by:
setNoCache in interface CauchoResponse

isNoCache

public boolean isNoCache()
Returns true if the page is non-cacheable


killCache

public void killCache()
Set if the page is non-cacheable.

Specified by:
killCache in interface CauchoResponse

isDisableCache

public boolean isDisableCache()

setStatus

public void setStatus(int code)
Sets the HTTP status

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

setStatus

public void setStatus(int code,
                      java.lang.String message)
Sets the HTTP status

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

sendError

public void sendError(int code)
               throws java.io.IOException
Sends an HTTP error page based on the status code

Specified by:
sendError in interface HttpServletResponse
Parameters:
code - the HTTP status code
Throws:
java.io.IOException

sendError

public void sendError(int code,
                      java.lang.String value)
               throws java.io.IOException
Sends an HTTP error to the browser.

Specified by:
sendError in interface HttpServletResponse
Parameters:
code - the HTTP error code
value - a string message
Throws:
java.io.IOException

setContentType

public void setContentType(java.lang.String value)
Sets the browser content type. If the value contains a charset, the output encoding will be changed to match.

For example, to set the output encoding to use UTF-8 instead of the default ISO-8859-1 (Latin-1), use the following:

 setContentType("text/html; charset=UTF-8");
 

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

getContentType

public java.lang.String getContentType()
Gets the content type.

Specified by:
getContentType in interface ServletResponse

getContentTypeImpl

public java.lang.String getContentTypeImpl()
Gets the content type.


getCharacterEncoding

public java.lang.String getCharacterEncoding()
Gets the character encoding.

Specified by:
getCharacterEncoding in interface ServletResponse

getCharacterEncodingImpl

public java.lang.String getCharacterEncodingImpl()
Gets the character encoding.


setCharacterEncoding

public void setCharacterEncoding(java.lang.String encoding)
Sets the character encoding.

Specified by:
setCharacterEncoding in interface ServletResponse

sendRedirect

public void sendRedirect(java.lang.String url)
                  throws java.io.IOException
Sends a redirect to the browser. If the URL is relative, it gets combined with the current url.

Specified by:
sendRedirect in interface HttpServletResponse
Parameters:
url - the possibly relative url to send to the browser
Throws:
java.io.IOException

encodeAbsoluteRedirect

public java.lang.String encodeAbsoluteRedirect(java.lang.String url)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Sets a header. This will override a previous header with the same name.

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

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
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:
name - the header name
value - the header value

containsHeader

public boolean containsHeader(java.lang.String name)
Returns true if the output headers include name

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

setDateHeader

public void setDateHeader(java.lang.String name,
                          long date)
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:
name - name of the header
date - the date in milliseconds since the epoch.

addDateHeader

public void addDateHeader(java.lang.String name,
                          long date)
Adds a header by converting a date to a string.

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

setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Sets a header by converting an integer value to a string.

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

addIntHeader

public void addIntHeader(java.lang.String name,
                         int value)
Adds a header by converting an integer value to a string.

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

addCookie

public void addCookie(Cookie cookie)
Adds a cookie to the response.

Specified by:
addCookie in interface HttpServletResponse
Parameters:
cookie - the response cookie

getCookie

public Cookie getCookie(java.lang.String name)

getCookies

public java.util.ArrayList<Cookie> getCookies()

getSessionId

public java.lang.String getSessionId()

setSessionId

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

addServletCookie

protected void addServletCookie(WebApp webApp)

createServletCookie

protected Cookie createServletCookie(WebApp webApp)

encodeURL

public java.lang.String encodeURL(java.lang.String string)
Encodes session information in a URL. Calling this will enable sessions for users who have disabled cookies.

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

encodeRedirectURL

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

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

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String string)
Deprecated. 

Specified by:
encodeRedirectUrl in interface HttpServletResponse

encodeUrl

public java.lang.String encodeUrl(java.lang.String string)
Deprecated. 

Specified by:
encodeUrl in interface HttpServletResponse

getResponseStream

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

setResponseStream

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

isCauchoResponseStream

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

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:

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

close

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

setForbidForward

public void setForbidForward(boolean forbid)
When set to true, RequestDispatcher.forward() is disallowed on this stream.

Specified by:
setForbidForward in interface CauchoResponse

getForbidForward

public boolean getForbidForward()
Returns true if RequestDispatcher.forward() is disallowed on this stream.

Specified by:
getForbidForward in interface CauchoResponse

hasError

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

setHasError

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

getResponse

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

Specified by:
getResponse in interface CauchoResponse

getAbstractHttpResponse

public AbstractHttpResponse getAbstractHttpResponse()
Specified by:
getAbstractHttpResponse 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:

getStatusMessage

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

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:

setForwardEnclosed

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

isForwardEnclosed

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

closeImpl

public void closeImpl()
               throws java.io.IOException
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class AbstractCauchoResponse