Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.infohazard.maverick.util
Class FakeHttpServletResponse  view FakeHttpServletResponse download FakeHttpServletResponse.java

java.lang.Object
  extended byjavax.servlet.ServletResponseWrapper
      extended byjavax.servlet.http.HttpServletResponseWrapper
          extended byorg.infohazard.maverick.util.FakeHttpServletResponse
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class FakeHttpServletResponse
extends javax.servlet.http.HttpServletResponseWrapper

Stores data written to the response and allows it to be obtained later.


Field Summary
protected  Buffer buffer
          Actually holds all the output data.
protected  java.lang.String charset
          We need to track the charset which is applied to the response using setContentType so that we can intelligently convert between streams and readers.
private static org.apache.commons.logging.Log log
          Logger.
protected static java.lang.String NO_BUFFER_MSG
           
 
Fields inherited from class javax.servlet.ServletResponseWrapper
 
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
FakeHttpServletResponse(javax.servlet.http.HttpServletResponse wrapMe)
          Creates a response wrapper which buffers the output.
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
          The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.
 void addDateHeader(java.lang.String name, long date)
          The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object.
 void addHeader(java.lang.String name, java.lang.String value)
          The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.
 void addIntHeader(java.lang.String name, int value)
          The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.
 void flushBuffer()
          Forces any content in the buffer to be written to the client.
protected  javax.servlet.http.HttpServletResponse getHttpResponse()
           
 java.io.Reader getOutputAsReader()
          Provides the buffered output as a Reader.
 java.lang.String getOutputAsString()
          Provides the buffered output as a String.
 javax.servlet.ServletOutputStream getOutputStream()
          Returns a javax.servlet.ServletOutputStream suitable for writing binary data in the response.
 java.io.PrintWriter getWriter()
          Returns a PrintWriter object that can send character text to the client.
 int outputSize()
           
 boolean prefersReader()
           
 void sendError(int sc)
          This actually sends to the real response and flags an error condition.
 void sendError(int sc, java.lang.String msg)
          This actually sends to the real response and flags an error condition.
 void setContentLength(int len)
          Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
 void setContentType(java.lang.String type)
          Sets the content type of the response being sent to the client, if the response has not been committed yet.
 void setDateHeader(java.lang.String name, long date)
          The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.
 void setHeader(java.lang.String name, java.lang.String value)
          The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.
 void setIntHeader(java.lang.String name, int value)
          The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.
 void setLocale(java.util.Locale loc)
          Sets the locale of the response, if the response has not been committed yet.
 void setStatus(int sc)
          The default behavior of this method is to call setStatus(int sc) on the wrapped response object.
 void setStatus(int sc, java.lang.String sm)
          The default behavior of this method is to call setStatus(int sc, String sm) on the wrapped response object.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendRedirect
 
Methods inherited from class javax.servlet.ServletResponseWrapper
getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletResponse
getBufferSize, getCharacterEncoding, getContentType, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding
 

Field Detail

log

private static org.apache.commons.logging.Log log
Logger.


NO_BUFFER_MSG

protected static final java.lang.String NO_BUFFER_MSG
See Also:
Constant Field Values

charset

protected java.lang.String charset
We need to track the charset which is applied to the response using setContentType so that we can intelligently convert between streams and readers. If null, the default encoding is assumed.


buffer

protected Buffer buffer
Actually holds all the output data.

Constructor Detail

FakeHttpServletResponse

public FakeHttpServletResponse(javax.servlet.http.HttpServletResponse wrapMe)
Creates a response wrapper which buffers the output.

Method Detail

prefersReader

public boolean prefersReader()

getOutputAsReader

public java.io.Reader getOutputAsReader()
                                 throws java.io.UnsupportedEncodingException
Provides the buffered output as a Reader. If output was written using a ServletOutputStream, the charset defined in the content-type is used to decode the data. If no charset is set, the default encoding is assumed.


getOutputAsString

public java.lang.String getOutputAsString()
                                   throws java.io.UnsupportedEncodingException
Provides the buffered output as a String. If output was written using a ServletOutputStream, the charset defined in the content-type is used to decode the data. If no charset is set, the default encoding is assumed.


outputSize

public int outputSize()

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Description copied from interface: javax.servlet.ServletResponse
Returns a javax.servlet.ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.

Calling flush() on the ServletOutputStream commits the response. Either this method or ServletResponse.getWriter()>ServletResponse.getWriter() 55 may be called to write the body, not both.


getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Description copied from interface: javax.servlet.ServletResponse
Returns a PrintWriter object that can send character text to the client. The PrintWriter uses the character encoding returned by ServletResponse.getCharacterEncoding()>ServletResponse.getCharacterEncoding() 55 . If the response's character encoding has not been specified as described in getCharacterEncoding (i.e., the method just returns the default value ISO-8859-1), getWriter updates it to ISO-8859-1.

Calling flush() on the PrintWriter commits the response.

Either this method or ServletResponse.getOutputStream()>ServletResponse.getOutputStream() 55 may be called to write the body, not both.


setContentType

public void setContentType(java.lang.String type)
Description copied from interface: javax.servlet.ServletResponse
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called before getWriter is called.

This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the Content-Type header is used.


setContentLength

public void setContentLength(int len)
Description copied from interface: javax.servlet.ServletResponse
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.


flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Description copied from interface: javax.servlet.ServletResponse
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.


setLocale

public void setLocale(java.util.Locale loc)
Description copied from interface: javax.servlet.ServletResponse
Sets the locale of the response, if the response has not been committed yet. It also sets the response's character encoding appropriately for the locale, if the character encoding has not been explicitly set using ServletResponse.setContentType(java.lang.String)>ServletResponse.setContentType(java.lang.String) 55 or ServletResponse.setCharacterEncoding(java.lang.String)>ServletResponse.setCharacterEncoding(java.lang.String) 55 , getWriter hasn't been called yet, and the response hasn't been committed yet. If the deployment descriptor contains a locale-encoding-mapping-list element, and that element provides a mapping for the given locale, that mapping is used. Otherwise, the mapping from locale to character encoding is container dependent.

This method may be called repeatedly to change locale and character encoding. The method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after ServletResponse.setContentType(java.lang.String)>ServletResponse.setContentType(java.lang.String) 55 has been called with a charset specification, after ServletResponse.setCharacterEncoding(java.lang.String)>ServletResponse.setCharacterEncoding(java.lang.String) 55 has been called, after getWriter has been called, or after the response has been committed.

Containers must communicate the locale and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the locale is communicated via the Content-Language header, the character encoding as part of the Content-Type header for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.


addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.


setDateHeader

public void setDateHeader(java.lang.String name,
                          long date)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.


addDateHeader

public void addDateHeader(java.lang.String name,
                          long date)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object.


setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.


addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.


setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.


addIntHeader

public void addIntHeader(java.lang.String name,
                         int value)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.


sendError

public void sendError(int sc)
               throws java.io.IOException
This actually sends to the real response and flags an error condition.


sendError

public void sendError(int sc,
                      java.lang.String msg)
               throws java.io.IOException
This actually sends to the real response and flags an error condition.


setStatus

public void setStatus(int sc)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call setStatus(int sc) on the wrapped response object.


setStatus

public void setStatus(int sc,
                      java.lang.String sm)
Description copied from class: javax.servlet.http.HttpServletResponseWrapper
The default behavior of this method is to call setStatus(int sc, String sm) on the wrapped response object.


getHttpResponse

protected javax.servlet.http.HttpServletResponse getHttpResponse()