|
|||||||||
| Home >> All >> org >> apache >> cactus >> sample >> servlet >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.cactus.sample.servlet.util
Class GenericResponseWrapper

java.lang.Objectjavax.servlet.ServletResponseWrapper
javax.servlet.http.HttpServletResponseWrapper
org.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 |
|
| 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
HttpServletResponseWrapperdoes 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
HttpServletResponseWrapperdoes 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 beforegetWriteris 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
getWriterhas 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-Typeheader 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
PrintWriterobject that can send character text to the client. ThePrintWriteruses the character encoding returned by ServletResponse.getCharacterEncoding()>ServletResponse.getCharacterEncoding()55 . If the response's character encoding has not been specified as described ingetCharacterEncoding(i.e., the method just returns the default valueISO-8859-1),getWriterupdates it toISO-8859-1.Calling flush() on the
PrintWritercommits the response.Either this method or ServletResponse.getOutputStream()>
ServletResponse.getOutputStream()55 may be called to write the body, not both.
|
|||||||||
| Home >> All >> org >> apache >> cactus >> sample >> servlet >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC