Enhydra 5.1 API

org.enhydra.servlet.debug
Class ResponseRecord

java.lang.Object
  |
  +--org.enhydra.servlet.filter.ResponseFilter
        |
        +--org.enhydra.servlet.debug.ResponseRecord
All Implemented Interfaces:
DebugResponse, javax.servlet.http.HttpServletResponse, org.apache.tomcat.core.ResponseAdapter, javax.servlet.ServletResponse

public class ResponseRecord
extends ResponseFilter
implements javax.servlet.http.HttpServletResponse, DebugResponse

HttpServletResponse filter that generate a record of the response that was made. Once the transaction is complete, this object contains the information.

Version:
$Revision: 1.1 $
Author:
Mark Diekhans
See Also:
com.lutris.filter.ransactionFilter, ServletResponse, HttpServletResponse

Field Summary
protected  java.lang.StringBuffer responseData
          If we are to capture the data written to the socket, save it here.
protected  ServletTransactionRecord transactionRecord
          Transaction record that this object is associated with.
 
Fields inherited from class org.enhydra.servlet.filter.ResponseFilter
myResponse
 
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_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
protected ResponseRecord(javax.servlet.http.HttpServletResponse originalResponse, boolean saveResponseData)
          Constructor.
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
          Adds the specified cookie to the response.
 void addDateHeader(java.lang.String name, long value)
           
 void addHeader(java.lang.String name, java.lang.String value)
           
 void addIntHeader(java.lang.String name, int value)
           
protected  void addTrace(java.lang.String str)
          Add a string to the trace buffer.
protected  void completed()
          Flag the response as completed.
 boolean containsHeader(java.lang.String name)
          Record call and pass on to actual response object..
 java.lang.String encodeRedirectUrl(java.lang.String url)
          Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
 java.lang.String encodeRedirectURL(java.lang.String url)
           
 java.lang.String encodeUrl(java.lang.String url)
          Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
 java.lang.String encodeURL(java.lang.String url)
           
 void flushBuffer()
           
 int getBufferSize()
           
 java.lang.String getCharacterEncoding()
          Returns the character set encoding for the input of this request.
 int getContentLength()
          Returns the size of the response entity data, or -1 if not known.
 java.lang.String getContentType()
          Returns the Internet Media Type of the response entity data, or null if not known.
 javax.servlet.http.Cookie[] getCookies()
          Returns an array of cookies to be set by this response.
 java.lang.String getHeader(java.lang.String name)
          Returns the values of the specified header for the response as an array of strings, or a 0 length array if the named header does not exist.
 java.util.Enumeration getHeaderNames()
          Returns an array of strings representing the header names for this response.
 java.util.Locale getLocale()
           
 javax.servlet.ServletOutputStream getOutputStream()
          Returns a wrapper around the real output stream.
 java.lang.String getResponseData()
          Returns the data written to the net, or null if this feature was not enabled (see the constructor).
 int getStatusCode()
          Returns the status code for the response, or -1 if not set.
 java.lang.String getStatusMessage()
          Returns the status message for the response.
 int getTotalBytes()
          Returns the number of bytes associated with the response.
 java.io.PrintWriter getWriter()
          Returns a wrapper around the real PrintWriter.
 boolean isCommitted()
           
 void reset()
           
 void sendError(int sc)
          Record call and pass on to actual response object.
 void sendError(int sc, java.lang.String msg)
          Record call and pass on to actual response object.
 void sendRedirect(java.lang.String location)
          Record call and pass on to actual response object.
 void setBufferSize(int size)
           
 void setContentLength(int len)
          Record call and pass on to actual response object..
 void setContentType(java.lang.String type)
          Record call and pass on to actual response object..
 void setDateHeader(java.lang.String name, long date)
          Record call and pass on to actual response object.
 void setHeader(java.lang.String name, java.lang.String value)
          Record call and pass on to actual response object.
 void setIntHeader(java.lang.String name, int value)
          Record call and pass on to actual response object.
 void setLocale(java.util.Locale locale)
           
 void setStatus(int sc)
          Record call and pass on to actual response object.
 void setStatus(int sc, java.lang.String sm)
          Record call and pass on to actual response object..
 
Methods inherited from class org.enhydra.servlet.filter.ResponseFilter
addMimeHeaders, doWrite, endHeaders, endResponse, getServletOutputStream, recycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

responseData

protected java.lang.StringBuffer responseData
If we are to capture the data written to the socket, save it here. An OutputStreamRecord will call append() on this.


transactionRecord

protected ServletTransactionRecord transactionRecord
Transaction record that this object is associated with.

Constructor Detail

ResponseRecord

protected ResponseRecord(javax.servlet.http.HttpServletResponse originalResponse,
                         boolean saveResponseData)
Constructor. Wrap the object around a single response and record infomation about it. The information is stored in this object for future access.

Parameters:
originalResponse - The real HttpServletResponse, which all calls will be passed on to.
See Also:
ServletResponse, HttpServletResponse
Method Detail

completed

protected void completed()
Flag the response as completed. This any summarization to occur and the object to disassociated with the original response object to help catch errors.


addTrace

protected void addTrace(java.lang.String str)
Add a string to the trace buffer.


setContentLength

public void setContentLength(int len)
Record call and pass on to actual response object..

Specified by:
setContentLength in interface javax.servlet.ServletResponse
Overrides:
setContentLength in class ResponseFilter
See Also:
ServletResponse.setContentLength(int)

setContentType

public void setContentType(java.lang.String type)
Record call and pass on to actual response object..

Specified by:
setContentType in interface javax.servlet.ServletResponse
Overrides:
setContentType in class ResponseFilter
See Also:
ServletResponse.setContentType(java.lang.String)

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Returns a wrapper around the real output stream. This wrapper traces the calls to print(), println(), and write(). Also, if saveResponseData was true when passed to the constructor, and setContentType() has been called with a mime type that starts with "text/", then a copy of the actuall data written to the output stream will be saved in this object's responseData StringBuffer. The decision of whether or not to save a copy of the data is made the first time this function is called.

Specified by:
getOutputStream in interface javax.servlet.ServletResponse
Overrides:
getOutputStream in class ResponseFilter
Throws:
java.io.IOException - See ServletResponse documentation
See Also:
ServletResponse.getOutputStream(), OutputStreamRecord

containsHeader

public boolean containsHeader(java.lang.String name)
Record call and pass on to actual response object..

Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
containsHeader in class ResponseFilter
See Also:
HttpServletResponse.containsHeader(java.lang.String)

setStatus

public void setStatus(int sc,
                      java.lang.String sm)
Record call and pass on to actual response object..

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Overrides:
setStatus in class ResponseFilter
See Also:
HttpServletResponse.setStatus(int)

setStatus

public void setStatus(int sc)
Record call and pass on to actual response object.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Overrides:
setStatus in class ResponseFilter
See Also:
HttpServletResponse.setStatus(int)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Record call and pass on to actual response object.

Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
setHeader in class ResponseFilter
See Also:
HttpServletResponse.setHeader(java.lang.String, java.lang.String)

setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Record call and pass on to actual response object.

Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
setIntHeader in class ResponseFilter
See Also:
HttpServletResponse.setIntHeader(java.lang.String, int)

setDateHeader

public void setDateHeader(java.lang.String name,
                          long date)
Record call and pass on to actual response object.

Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
setDateHeader in class ResponseFilter
See Also:
HttpServletResponse.setDateHeader(java.lang.String, long)

sendError

public void sendError(int sc,
                      java.lang.String msg)
               throws java.io.IOException
Record call and pass on to actual response object.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Overrides:
sendError in class ResponseFilter
Throws:
java.io.IOException - See HttpServletResponse documentation
See Also:
HttpServletResponse.sendError(int)

sendError

public void sendError(int sc)
               throws java.io.IOException
Record call and pass on to actual response object.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Overrides:
sendError in class ResponseFilter
Throws:
java.io.IOException - See HttpServletResponse documentation
See Also:
HttpServletResponse.sendError(int)

sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Record call and pass on to actual response object.

Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Overrides:
sendRedirect in class ResponseFilter
Throws:
java.io.IOException - See HttpServletResponse documentation
See Also:
HttpServletResponse.sendRedirect(java.lang.String)

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response. It can be called multiple times to set more than one cookie.

Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse
Overrides:
addCookie in class ResponseFilter
See Also:
HttpServletResponse.addCookie(javax.servlet.http.Cookie)

getContentLength

public int getContentLength()
Returns the size of the response entity data, or -1 if not known.

Specified by:
getContentLength in interface DebugResponse

getContentType

public java.lang.String getContentType()
Returns the Internet Media Type of the response entity data, or null if not known.

Specified by:
getContentType in interface DebugResponse

getStatusCode

public int getStatusCode()
Returns the status code for the response, or -1 if not set.

Specified by:
getStatusCode in interface DebugResponse

getStatusMessage

public java.lang.String getStatusMessage()
Returns the status message for the response.

Specified by:
getStatusMessage in interface DebugResponse

getCookies

public javax.servlet.http.Cookie[] getCookies()
Returns an array of cookies to be set by this response.

Specified by:
getCookies in interface DebugResponse
Returns:
The array of cookies found in this response.

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the values of the specified header for the response as an array of strings, or a 0 length array if the named header does not exist.

Specified by:
getHeader in interface DebugResponse
Parameters:
name - the case-insensitive header field name

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns an array of strings representing the header names for this response. This does not have return cookies - use getCookies().

Specified by:
getHeaderNames in interface DebugResponse

getTotalBytes

public int getTotalBytes()
Returns the number of bytes associated with the response.

Specified by:
getTotalBytes in interface DebugResponse

encodeUrl

public java.lang.String encodeUrl(java.lang.String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.

Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse
Overrides:
encodeUrl in class ResponseFilter
Parameters:
url - The url to be encoded.
Returns:
The encoded URL if encoding is needed; the unchanged URL otherwise.
See Also:
HttpServletResponse.encodeUrl(java.lang.String)

encodeRedirectUrl

public java.lang.String encodeRedirectUrl(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.

Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse
Overrides:
encodeRedirectUrl in class ResponseFilter
Parameters:
url - The url to be encoded.
Returns:
The encoded URL if encoding is needed; the unchanged URL otherwise.
See Also:
HttpServletResponse.encodeRedirectUrl(java.lang.String)

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Returns a wrapper around the real PrintWriter. This wrapper traces the calls to the output methods. If saveResponseData was true when passed to the constructor, and setContentType() has been called with a mime type that starts with "text/", then a copy of the actual data written to the PprintWriter will be saved in this object's responseData StringBuffer. The decision of whether or not to save a copy of the data is made the first time this function is called.

Specified by:
getWriter in interface javax.servlet.ServletResponse
Overrides:
getWriter in class ResponseFilter
Throws:
java.io.IOException - See ServletResponse documentation
See Also:
javax.servlet.ServletResponse#getPrintWriter, PrintWriterRecord

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the character set encoding for the input of this request.

Specified by:
getCharacterEncoding in interface javax.servlet.ServletResponse
Overrides:
getCharacterEncoding in class ResponseFilter
See Also:
ServletRequest.getCharacterEncoding()

getResponseData

public java.lang.String getResponseData()
Returns the data written to the net, or null if this feature was not enabled (see the constructor).

Specified by:
getResponseData in interface DebugResponse

getLocale

public java.util.Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletResponse
Overrides:
getLocale in class ResponseFilter

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Specified by:
flushBuffer in interface javax.servlet.ServletResponse
Overrides:
flushBuffer in class ResponseFilter
java.io.IOException

encodeURL

public java.lang.String encodeURL(java.lang.String url)
Specified by:
encodeURL in interface javax.servlet.http.HttpServletResponse
Overrides:
encodeURL in class ResponseFilter

isCommitted

public boolean isCommitted()
Specified by:
isCommitted in interface javax.servlet.ServletResponse
Overrides:
isCommitted in class ResponseFilter

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface javax.servlet.ServletResponse
Overrides:
getBufferSize in class ResponseFilter

reset

public void reset()
Specified by:
reset in interface javax.servlet.ServletResponse
Overrides:
reset in class ResponseFilter

encodeRedirectURL

public java.lang.String encodeRedirectURL(java.lang.String url)
Specified by:
encodeRedirectURL in interface javax.servlet.http.HttpServletResponse
Overrides:
encodeRedirectURL in class ResponseFilter

addIntHeader

public void addIntHeader(java.lang.String name,
                         int value)
Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
addIntHeader in class ResponseFilter

addDateHeader

public void addDateHeader(java.lang.String name,
                          long value)
Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
addDateHeader in class ResponseFilter

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
addHeader in class ResponseFilter

setBufferSize

public void setBufferSize(int size)
Specified by:
setBufferSize in interface javax.servlet.ServletResponse
Overrides:
setBufferSize in class ResponseFilter

setLocale

public void setLocale(java.util.Locale locale)
Specified by:
setLocale in interface javax.servlet.ServletResponse
Overrides:
setLocale in class ResponseFilter

Enhydra 5.1 API