org.barracudamvc.core.helper.servlet
Class DeferredResponseWrapper

java.lang.Object
  extended byorg.barracudamvc.core.helper.servlet.DeferredResponseWrapper
All Implemented Interfaces:
BarracudaServletResponseWrapper, javax.servlet.http.HttpServletResponse, Pausable, javax.servlet.ServletResponse

public class DeferredResponseWrapper
extends Object
implements BarracudaServletResponseWrapper, Pausable

This class acts as a thin wrapper around a ServletResponse. By using this wrapper, the response is actually "absorbed" or "deferred", so that it can be manually extracted later.


Field Summary
protected static org.apache.log4j.Logger logger
           
protected  int pipeSize
           
protected  int pipeTimeout
           
protected  SimpleDateFormat sdf
           
 
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
DeferredResponseWrapper()
          Create a DeferredResponseWrapper
DeferredResponseWrapper(int ipipeSize, int ipipeTimeout)
          Create a DeferredResponseWrapper, specifying a pipe size and timeout
 
Method Summary
protected  void _resetVars()
           
 void actuallySendResponse(javax.servlet.http.HttpServletResponse resp)
          Go ahead and actually write the response
 void addCookie(javax.servlet.http.Cookie cookie)
          Adds the specified cookie to the response.
 void addDateHeader(String name, long date)
          Adds a response header with the given name and date-value.
 void addHeader(String name, String value)
          Adds a response header with the given name and value.
 void addIntHeader(String name, int value)
          Adds a response header with the given name and integer value.
 boolean containsHeader(String name)
          Returns a boolean indicating whether the named response header has already been set.
 String encodeRedirectUrl(String url)
          Deprecated.
 String encodeRedirectURL(String url)
          Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
 String encodeUrl(String url)
          Deprecated.
 String encodeURL(String url)
          Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
 void flushBuffer()
          Forces any content in the buffer to be written to the client.
 int getBufferSize()
          Returns the actual buffer size used for the response.
 String getCharacterEncoding()
          Returns the name of the charset used for the MIME body sent in this response.
 Locale getLocale()
          Returns the locale assigned to the response.
 LongRunning getLongRunning()
           
 Thread getLongRunningThread()
           
 javax.servlet.ServletOutputStream getOutputStream()
          Return the servlet output stream associated with this Response.
static String getStatusMessage(int isc)
          Returns a default status message for the specified HTTP status code.
 javax.servlet.http.HttpServletResponse getUnderlyingResponse()
           
 PrintWriter getWriter()
          Return the print writer associated with this Response (this method may be called multiple times).
 void interrupt()
           
 boolean isCommitted()
          Returns a boolean indicating if the response has been committed.
 boolean isInterrupted()
           
 boolean isPaused()
          Returns true if the object is paused
 boolean isReady()
           
static void main(String[] args)
          simply for testing purposes
 void pause()
           
 void reset()
          Clears any data that exists in the buffer as well as the status code and headers.
 void resetBuffer()
          Clears the content of the underlying buffer in the response without clearing headers or status code.
 void resume()
           
 void sendError(int sc)
          Sends an error response to the client using the specified status code and clearing the buffer.
 void sendError(int sc, String msg)
          Sends an error response to the client using the specified status clearing the buffer.
 void sendRedirect(String location)
          Sends a temporary redirect response to the client using the specified redirect location URL.
 void setBufferSize(int size)
          Sets the preferred buffer size for the body of the response.
 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(String type)
          Sets the content type of the response being sent to the client.
 void setDateHeader(String name, long date)
          Sets a response header with the given name and date-value.
 void setHeader(String name, String value)
          Sets a response header with the given name and value.
 void setIntHeader(String name, int value)
          Sets a response header with the given name and integer value.
 void setLocale(Locale loc)
          Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
 void setLongRunning(LongRunning ilr)
           
 void setLongRunningThread(Thread ith)
           
 void setPipeSize(int ipipeSize)
           
 void setPipeTimeout(int ipipeTimeout)
           
 void setStatus(int isc)
          Sets the status code for this response.
 void setStatus(int isc, String ism)
          Sets the status code for this response.
 void setUnderlyingResponse(javax.servlet.http.HttpServletResponse iuresp, String ilrid)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

sdf

protected final SimpleDateFormat sdf

pipeSize

protected int pipeSize

pipeTimeout

protected int pipeTimeout
Constructor Detail

DeferredResponseWrapper

public DeferredResponseWrapper()
Create a DeferredResponseWrapper


DeferredResponseWrapper

public DeferredResponseWrapper(int ipipeSize,
                               int ipipeTimeout)
Create a DeferredResponseWrapper, specifying a pipe size and timeout

Method Detail

_resetVars

protected void _resetVars()

isReady

public boolean isReady()
                throws IOException
Throws:
IOException

actuallySendResponse

public void actuallySendResponse(javax.servlet.http.HttpServletResponse resp)
                          throws IOException
Go ahead and actually write the response

Throws:
IOException

setUnderlyingResponse

public void setUnderlyingResponse(javax.servlet.http.HttpServletResponse iuresp,
                                  String ilrid)

getUnderlyingResponse

public javax.servlet.http.HttpServletResponse getUnderlyingResponse()

setLongRunning

public void setLongRunning(LongRunning ilr)

getLongRunning

public LongRunning getLongRunning()

setLongRunningThread

public void setLongRunningThread(Thread ith)

getLongRunningThread

public Thread getLongRunningThread()

setPipeSize

public void setPipeSize(int ipipeSize)

setPipeTimeout

public void setPipeTimeout(int ipipeTimeout)

interrupt

public void interrupt()

isInterrupted

public boolean isInterrupted()

pause

public void pause()

resume

public void resume()

isPaused

public boolean isPaused()
Description copied from interface: Pausable
Returns true if the object is paused

Specified by:
isPaused in interface Pausable

flushBuffer

public void flushBuffer()
Forces any content in the buffer to be written to the client. This implementation doesn't do aything.

Specified by:
flushBuffer in interface javax.servlet.ServletResponse

getBufferSize

public int getBufferSize()
Returns the actual buffer size used for the response.

Specified by:
getBufferSize in interface javax.servlet.ServletResponse

getCharacterEncoding

public String getCharacterEncoding()
Returns the name of the charset used for the MIME body sent in this response. This implementation is hardcoded to return "ISO-8859-1"

Specified by:
getCharacterEncoding in interface javax.servlet.ServletResponse

getLocale

public Locale getLocale()
Returns the locale assigned to the response.

Specified by:
getLocale in interface javax.servlet.ServletResponse

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws IOException
Return the servlet output stream associated with this Response.

Specified by:
getOutputStream in interface javax.servlet.ServletResponse
Throws:
IllegalStateException - if getWriter has already been called for this response, or if the response wrapper writer has been overridden (in that case you ust use getWriter)
IOException - if an input/output error occurs

getWriter

public PrintWriter getWriter()
                      throws IOException
Return the print writer associated with this Response (this method may be called multiple times).

Specified by:
getWriter in interface javax.servlet.ServletResponse
Throws:
IllegalStateException - if getOutputStream has already been called for this response
IOException - if an input/output error occurs

isCommitted

public boolean isCommitted()
Returns a boolean indicating if the response has been committed.

Specified by:
isCommitted in interface javax.servlet.ServletResponse

reset

public void reset()
Clears any data that exists in the buffer as well as the status code and headers.

Specified by:
reset in interface javax.servlet.ServletResponse

resetBuffer

public void resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.

Specified by:
resetBuffer in interface javax.servlet.ServletResponse

setBufferSize

public void setBufferSize(int size)
Sets the preferred buffer size for the body of the response. Doesn't do anything in this implementation

Specified by:
setBufferSize in interface javax.servlet.ServletResponse

setContentLength

public 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.

Specified by:
setContentLength in interface javax.servlet.ServletResponse

setContentType

public void setContentType(String type)
Sets the content type of the response being sent to the client.

Specified by:
setContentType in interface javax.servlet.ServletResponse

setLocale

public void setLocale(Locale loc)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.

Specified by:
setLocale in interface javax.servlet.ServletResponse

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response.

Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse

addDateHeader

public void addDateHeader(String name,
                          long date)
Adds a response header with the given name and date-value.

Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse

addHeader

public void addHeader(String name,
                      String value)
Adds a response header with the given name and value.

Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse

addIntHeader

public void addIntHeader(String name,
                         int value)
Adds a response header with the given name and integer value.

Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse

containsHeader

public boolean containsHeader(String name)
Returns a boolean indicating whether the named response header has already been set.

Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse

encodeRedirectUrl

public String encodeRedirectUrl(String url)
Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead

Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse

encodeRedirectURL

public String encodeRedirectURL(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

encodeUrl

public String encodeUrl(String url)
Deprecated. As of version 2.1, use encodeURL(String url) instead

Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse

encodeURL

public String encodeURL(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

sendError

public void sendError(int sc)
Sends an error response to the client using the specified status code and clearing the buffer.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse

sendError

public void sendError(int sc,
                      String msg)
Sends an error response to the client using the specified status clearing the buffer.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse

sendRedirect

public void sendRedirect(String location)
Sends a temporary redirect response to the client using the specified redirect location URL.

Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse

setDateHeader

public void setDateHeader(String name,
                          long date)
Sets a response header with the given name and date-value.

Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse

setHeader

public void setHeader(String name,
                      String value)
Sets a response header with the given name and value.

Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse

setIntHeader

public void setIntHeader(String name,
                         int value)
Sets a response header with the given name and integer value.

Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse

setStatus

public void setStatus(int isc)
Sets the status code for this response.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse

setStatus

public void setStatus(int isc,
                      String ism)
Sets the status code for this response.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse

getStatusMessage

public static String getStatusMessage(int isc)
Returns a default status message for the specified HTTP status code.


main

public static void main(String[] args)
simply for testing purposes



Copyright © 2004 BarracudaMVC.org All Rights Reserved.