com.caucho.server.http
Class ResponseWrapper

java.lang.Object
  extended by com.caucho.server.http.ResponseWrapper
All Implemented Interfaces:
ServletResponse
Direct Known Subclasses:
CauchoResponseWrapper, ResponseAdapter

public class ResponseWrapper
extends java.lang.Object
implements ServletResponse

Wraps a servlet response in another response. Filters may use ServletResponseWrapper to grab results from the servlet.

The default methods just call the wrapped response methods.

Since:
servlet 2.3

Field Summary
protected  HttpServletResponse _response
           
 
Constructor Summary
ResponseWrapper()
          Create a new ServletResponseWrapper, wrapping a specified response.
ResponseWrapper(HttpServletResponse response)
          Create a new ServletResponseWrapper, wrapping a specified response.
 
Method Summary
 void addCookie(Cookie cookie)
          Sends a new cookie to the client.
 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.
 boolean containsHeader(java.lang.String name)
          Returns true if the output headers include name
 void disable()
          Disables the response
 void enable()
          Enables the response
 java.lang.String encodeRedirectUrl(java.lang.String url)
          Deprecated.  
 java.lang.String encodeRedirectURL(java.lang.String name)
          Encodes session information in a URL suitable for sendRedirect()
 java.lang.String encodeUrl(java.lang.String url)
          Deprecated.  
 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
 java.util.Locale getLocale()
          Returns the output locale.
 ServletOutputStream getOutputStream()
          Returns an output stream for writing to the client.
 ServletResponse getResponse()
          Gets the wrapped response
 java.io.PrintWriter getWriter()
          Returns a PrintWriter with the proper character encoding for writing text data to the client.
 boolean isCommitted()
          Returns true if some data has actually been send to the client.
 boolean isDisabled()
          Returns true if the response is disabled
 void reset()
          Resets the output stream, clearing headers and the output buffer.
 void resetBuffer()
          Resets the output stream without clearing headers and the output buffer.
 void sendError(int sc)
          Sends an HTTP error page based on the status code
 void sendError(int sc, java.lang.String msg)
          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 encoding)
          Sets the character encoding the response is using for output.
 void setContentLength(int len)
          Deprecated.  
 void setContentType(java.lang.String type)
          Sets the response 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 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 setMatchCacheEntry(AbstractCacheEntry cacheEntry)
           
 void setResponse(HttpServletResponse response)
          Sets the response to be wrapped.
 void setStatus(int sc)
          Sets the HTTP status
 void setStatus(int sc, java.lang.String msg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_response

protected HttpServletResponse _response
Constructor Detail

ResponseWrapper

public ResponseWrapper()
Create a new ServletResponseWrapper, wrapping a specified response.


ResponseWrapper

public ResponseWrapper(HttpServletResponse response)
Create a new ServletResponseWrapper, wrapping a specified response.

Parameters:
response - the response to wrap.
Method Detail

setResponse

public void setResponse(HttpServletResponse response)
Sets the response to be wrapped.

Parameters:
response - the response to wrap.

getResponse

public ServletResponse getResponse()
Gets the wrapped response

Returns:
the wrapped response

getAbstractHttpResponse

public AbstractHttpResponse getAbstractHttpResponse()

setContentType

public void setContentType(java.lang.String type)
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

getContentType

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

Specified by:
getContentType in interface ServletResponse
Since:
2.4

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the character encoding the response is using for output.

Specified by:
getCharacterEncoding in interface ServletResponse

setCharacterEncoding

public void setCharacterEncoding(java.lang.String encoding)
Sets the character encoding the response is using for output.

Specified by:
setCharacterEncoding in interface ServletResponse
Since:
2.4

setLocale

public void setLocale(java.util.Locale locale)
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()
Returns the output locale.

Specified by:
getLocale in interface ServletResponse

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

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 without clearing headers and the output buffer. Calling resetBuffer() 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)
Deprecated. 

Resin automatically handles output content length and chunking. This method is ignored.

Specified by:
setContentLength in interface ServletResponse

setStatus

public void setStatus(int sc)
Sets the HTTP status

Parameters:
sc - the HTTP status code

sendError

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

Parameters:
sc - the HTTP status code
Throws:
java.io.IOException

sendError

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

Parameters:
sc - the HTTP status code
Throws:
java.io.IOException

sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Redirects the client to another page.

Parameters:
location - the location to redirect to.
Throws:
java.io.IOException

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.

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.

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

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);
 

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.

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.

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.

Parameters:
name - name of the header
value - the value as an integer

addCookie

public void addCookie(Cookie cookie)
Sends a new cookie to the client.


encodeURL

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

Parameters:
url - the url to encode
Returns:
a url with session information encoded

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String name)
Encodes session information in a URL suitable for sendRedirect()

Parameters:
url - the url to encode
Returns:
a url with session information encoded

setStatus

public void setStatus(int sc,
                      java.lang.String msg)

encodeUrl

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


encodeRedirectUrl

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


setFooter

public void setFooter(java.lang.String key,
                      java.lang.String value)

addFooter

public void addFooter(java.lang.String key,
                      java.lang.String value)

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

setCacheInvocation

public void setCacheInvocation(AbstractCacheFilterChain cacheFilterChain)

setMatchCacheEntry

public void setMatchCacheEntry(AbstractCacheEntry cacheEntry)