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

Quick Search    Search Deep

org.apache.cactus.sample.servlet.util
Class GenericResponseWrapper  view GenericResponseWrapper download GenericResponseWrapper.java

java.lang.Object
  extended byjavax.servlet.ServletResponseWrapper
      extended byjavax.servlet.http.HttpServletResponseWrapper
          extended byorg.apache.cactus.sample.servlet.util.GenericResponseWrapper
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class GenericResponseWrapper
extends javax.servlet.http.HttpServletResponseWrapper

Wrapper around a HttpServletResponse that we use to easily write filters that manipulate the output stream. Indeed, we cannot pass the output stream of our filter direectly to the next filter in the chain because then we won't be able to write to it (the response will have been committed). Instead, we pass this wrapper class and then copy its data to our filter output stream. Note: This code was adapted from the Filter tutorial found here

Version:
$Id: GenericResponseWrapper.java,v 1.3 2004/02/29 16:36:45 vmassol Exp $

Field Summary
private  int contentLength
          Save the content length so that we can query it at a later time (otherwise it would not be possible as HttpServletResponseWrapper does not have a method to get the content length).
private  java.lang.String contentType
          Save the content type so that we can query it at a later time (otherwise it would not be possible as HttpServletResponseWrapper does not have a method to get the content type).
private  java.io.ByteArrayOutputStream output
          Holder for the output data
 
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
GenericResponseWrapper(javax.servlet.http.HttpServletResponse theResponse)
           
 
Method Summary
 int getContentLength()
           
 java.lang.String getContentType()
          Returns the content type used for the MIME body sent in this response.
 byte[] getData()
           
 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.
 void setContentLength(int theLength)
          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 theType)
          Sets the content type of the response being sent to the client, if the response has not been committed yet.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
addCookie, addDateHeader, addHeader, addIntHeader, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendError, sendError, sendRedirect, setDateHeader, setHeader, setIntHeader, setStatus, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
flushBuffer, getBufferSize, getCharacterEncoding, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setLocale, 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
flushBuffer, getBufferSize, getCharacterEncoding, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setLocale
 

Field Detail

output

private java.io.ByteArrayOutputStream output
Holder for the output data


contentLength

private int contentLength
Save the content length so that we can query it at a later time (otherwise it would not be possible as HttpServletResponseWrapper does not have a method to get the content length).


contentType

private java.lang.String contentType
Save the content type so that we can query it at a later time (otherwise it would not be possible as HttpServletResponseWrapper does not have a method to get the content type).

Constructor Detail

GenericResponseWrapper

public GenericResponseWrapper(javax.servlet.http.HttpServletResponse theResponse)
Method Detail

getData

public byte[] getData()

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
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.


setContentLength

public void setContentLength(int theLength)
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.


getContentLength

public int getContentLength()

setContentType

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


getContentType

public java.lang.String getContentType()
Description copied from interface: javax.servlet.ServletResponse
Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using ServletResponse.setContentType(java.lang.String)>ServletResponse.setContentType(java.lang.String) 55 before the response is committed. If no content type has been specified, this method returns null. If a content type has been specified and a character encoding has been explicitly or implicitly specified as described in ServletResponse.getCharacterEncoding()>ServletResponse.getCharacterEncoding() 55 , the charset parameter is included in the string returned. If no character encoding has been specified, the charset parameter is omitted.


getWriter

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