com.caucho.server.http
Class AbstractHttpResponse

java.lang.Object
  extended by com.caucho.server.http.AbstractHttpResponse
Direct Known Subclasses:
FastCgiResponse, HmuxResponse, HttpResponse

public abstract class AbstractHttpResponse
extends java.lang.Object

Encapsulates the servlet response, controlling response headers and the response stream.


Field Summary
protected  java.util.ArrayList<java.lang.String> _headerKeys
           
protected  java.util.ArrayList<java.lang.String> _headerValues
           
protected  AbstractHttpRequest _request
           
 
Constructor Summary
protected AbstractHttpResponse(AbstractHttpRequest request)
           
 
Method Summary
 void addDateHeader(java.lang.String key, long value)
          Convenience for adding a date header.
 void addFooter(java.lang.String key, java.lang.String value)
          Adds a new footer.
 void addHeader(java.lang.String key, java.lang.String value)
          Adds a new header.
 void addHeaderImpl(java.lang.String key, java.lang.String value)
          Adds a new header.
 void addIntHeader(java.lang.String key, int value)
          Convenience for adding an integer header.
 void clientDisconnect()
          Called when the client has disconnected
 void close()
          Closes the request, called from web-app for early close.
 boolean containsHeader(java.lang.String name)
          Returns true if the response already contains the named header.
protected abstract  AbstractResponseStream createResponseStream()
           
 boolean fillCookie(CharBuffer cb, Cookie cookie, long date, int version, boolean isCookie2)
          Fills the response for a cookie
 byte[] fillDateBuffer(long now)
           
 byte[] fillLogDateBuffer(long now, java.lang.String timeFormat)
           
 void finishInvocation()
          Complete the invocation.
 void finishRequest()
          Complete the invocation.
protected  void free()
           
protected  QDate getCalendar()
           
 int getContentLength()
          Returns the number of bytes sent to the output.
 long getContentLengthHeader()
          Returns the value of the content-length header.
 int getDateBufferLength()
           
 java.util.ArrayList<java.lang.String> getFooterKeys()
           
 java.util.ArrayList<java.lang.String> getFooterValues()
           
 java.lang.String getHeader(java.lang.String name)
          Returns the value of an already set output header.
 java.util.ArrayList<java.lang.String> getHeaderKeys()
           
 java.util.Collection<java.lang.String> getHeaderNames()
           
 java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
           
 java.util.ArrayList<java.lang.String> getHeaderValues()
           
 LogBuffer getLogBuffer()
           
 int getLogDateBufferLength()
           
 int getRawDateBufferLength()
           
 int getRawDateBufferOffset()
           
 AbstractHttpRequest getRequest()
          Returns the corresponding request.
 ServletResponse getResponse()
          Returns the next response.
protected  ServletOutputStreamImpl getResponseOutputStream()
           
protected  ResponseWriter getResponsePrintWriter()
           
protected  AbstractResponseStream getResponseStream()
          Gets the response stream.
 java.lang.String getServerHeader()
           
protected  boolean hasFooter()
           
 boolean isClosed()
          Returns true for closed requests.
 boolean isCommitted()
          Returns true if some data has been sent to the browser.
 boolean isConnectionClosed()
          Return true if the connection has disconnected
protected  boolean isHead()
          For a HEAD request, the response stream should write no data.
 boolean isHeaderWritten()
          Returns true if the headers have been written.
 boolean isIgnoreClientDisconnect()
          If set true, client disconnect exceptions are no propagated to the server code.
protected static com.caucho.server.http.ContentType parseContentType(java.lang.String contentType)
           
 void removeHeader(java.lang.String key)
           
protected  void reset()
           
 void setContentLength(long length)
          Sets the content length of the result.
 void setDateHeader(java.lang.String name, long value)
          Convenience for setting a date header.
 void setFooter(java.lang.String key, java.lang.String value)
          Sets a footer, replacing an already-existing footer
protected  void setHead()
          For a HEAD request, the response stream should write no data.
 void setHeader(java.lang.String key, java.lang.String value)
          Sets a header, replacing an already-existing header.
protected  void setHeaderImpl(java.lang.String key, java.lang.String value)
          Sets a header, replacing an already-existing header.
 void setHeaderWritten(boolean isWritten)
          Returns true if the headers have been written.
 void setIntHeader(java.lang.String name, int value)
          Convenience for setting an integer header.
protected  boolean setSpecial(java.lang.String key, java.lang.String value)
          Special processing for a special value.
 void startInvocation()
           
 void startRequest()
          Initializes the Response at the beginning of the request.
protected  void writeContinueInt()
          Writes the continue
 boolean writeHeaders(int length)
          Writes the headers to the stream.
protected abstract  boolean writeHeadersInt(int length, boolean isHead)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_request

protected final AbstractHttpRequest _request

_headerKeys

protected final java.util.ArrayList<java.lang.String> _headerKeys

_headerValues

protected final java.util.ArrayList<java.lang.String> _headerValues
Constructor Detail

AbstractHttpResponse

protected AbstractHttpResponse(AbstractHttpRequest request)
Method Detail

getCalendar

protected final QDate getCalendar()

isIgnoreClientDisconnect

public boolean isIgnoreClientDisconnect()
If set true, client disconnect exceptions are no propagated to the server code.


isConnectionClosed

public boolean isConnectionClosed()
Return true if the connection has disconnected


clientDisconnect

public void clientDisconnect()
Called when the client has disconnected


getResponse

public ServletResponse getResponse()
Returns the next response.


getRequest

public AbstractHttpRequest getRequest()
Returns the corresponding request.


isClosed

public boolean isClosed()
Returns true for closed requests.


startRequest

public void startRequest()
                  throws java.io.IOException
Initializes the Response at the beginning of the request.

Throws:
java.io.IOException

startInvocation

public void startInvocation()

createResponseStream

protected abstract AbstractResponseStream createResponseStream()

setHead

protected void setHead()
For a HEAD request, the response stream should write no data.


isHead

protected final boolean isHead()
For a HEAD request, the response stream should write no data.


containsHeader

public boolean containsHeader(java.lang.String name)
Returns true if the response already contains the named header.

Parameters:
name - name of the header to test.

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the value of an already set output header.

Parameters:
name - name of the header to get.

setHeader

public void setHeader(java.lang.String key,
                      java.lang.String value)
Sets a header, replacing an already-existing header.

Parameters:
key - the header key to set.
value - the header value to set.

setHeaderImpl

protected void setHeaderImpl(java.lang.String key,
                             java.lang.String value)
Sets a header, replacing an already-existing header.

Parameters:
key - the header key to set.
value - the header value to set.

addHeader

public void addHeader(java.lang.String key,
                      java.lang.String value)
Adds a new header. If an old header with that name exists, both headers are output.

Parameters:
key - the header key.
value - the header value.

addHeaderImpl

public void addHeaderImpl(java.lang.String key,
                          java.lang.String value)
Adds a new header. If an old header with that name exists, both headers are output.

Parameters:
key - the header key.
value - the header value.

parseContentType

protected static com.caucho.server.http.ContentType parseContentType(java.lang.String contentType)

setSpecial

protected boolean setSpecial(java.lang.String key,
                             java.lang.String value)
Special processing for a special value.


removeHeader

public void removeHeader(java.lang.String key)

setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Convenience for setting an integer header. An old header with the same name will be replaced.

Parameters:
name - the header name.
value - an integer to be converted to a string for the header.

addIntHeader

public void addIntHeader(java.lang.String key,
                         int value)
Convenience for adding an integer header. If an old header already exists, both will be sent to the browser.

Parameters:
key - the header name.
value - an integer to be converted to a string for the header.

setDateHeader

public void setDateHeader(java.lang.String name,
                          long value)
Convenience for setting a date header. An old header with the same name will be replaced.

Parameters:
name - the header name.
value - an time in milliseconds to be converted to a date string.

addDateHeader

public void addDateHeader(java.lang.String key,
                          long value)
Convenience for adding a date header. If an old header with the same name exists, both will be displayed.

Parameters:
key - the header name.
value - an time in milliseconds to be converted to a date string.

getHeaderKeys

public java.util.ArrayList<java.lang.String> getHeaderKeys()

getHeaderValues

public java.util.ArrayList<java.lang.String> getHeaderValues()

getHeaders

public java.util.Collection<java.lang.String> getHeaders(java.lang.String name)

getHeaderNames

public java.util.Collection<java.lang.String> getHeaderNames()

getFooterKeys

public java.util.ArrayList<java.lang.String> getFooterKeys()

getFooterValues

public java.util.ArrayList<java.lang.String> getFooterValues()

setContentLength

public void setContentLength(long length)
Sets the content length of the result. In general, Resin will handle the content length, but for things like long downloads adding the length will give a valuable hint to the browser.

Parameters:
length - the length of the content.

getContentLengthHeader

public final long getContentLengthHeader()
Returns the value of the content-length header.


getServerHeader

public java.lang.String getServerHeader()

setFooter

public void setFooter(java.lang.String key,
                      java.lang.String value)
Sets a footer, replacing an already-existing footer

Parameters:
key - the header key to set.
value - the header value to set.

addFooter

public void addFooter(java.lang.String key,
                      java.lang.String value)
Adds a new footer. If an old footer with that name exists, both footers are output.

Parameters:
key - the footer key.
value - the footer value.

hasFooter

protected boolean hasFooter()

getResponseStream

protected AbstractResponseStream getResponseStream()
Gets the response stream.


getResponseOutputStream

protected ServletOutputStreamImpl getResponseOutputStream()

getResponsePrintWriter

protected ResponseWriter getResponsePrintWriter()

isCommitted

public boolean isCommitted()
Returns true if some data has been sent to the browser.


reset

protected void reset()

getContentLength

public int getContentLength()
Returns the number of bytes sent to the output.


isHeaderWritten

public boolean isHeaderWritten()
Returns true if the headers have been written.


setHeaderWritten

public void setHeaderWritten(boolean isWritten)
Returns true if the headers have been written.


writeContinueInt

protected void writeContinueInt()
                         throws java.io.IOException
Writes the continue

Throws:
java.io.IOException

writeHeaders

public final boolean writeHeaders(int length)
                           throws java.io.IOException
Writes the headers to the stream. Called prior to the first flush of data.

Parameters:
os - browser stream.
length - length of the response if known, or -1 is unknown.
Returns:
true if the content is chunked.
Throws:
java.io.IOException

writeHeadersInt

protected abstract boolean writeHeadersInt(int length,
                                           boolean isHead)
                                    throws java.io.IOException
Throws:
java.io.IOException

fillCookie

public boolean fillCookie(CharBuffer cb,
                          Cookie cookie,
                          long date,
                          int version,
                          boolean isCookie2)
Fills the response for a cookie

Parameters:
cb - result buffer to contain the generated string
cookie - the cookie
date - the current date
version - the cookies version

getLogBuffer

public final LogBuffer getLogBuffer()

fillDateBuffer

public final byte[] fillDateBuffer(long now)

getDateBufferLength

public final int getDateBufferLength()

getRawDateBufferOffset

public final int getRawDateBufferOffset()

getRawDateBufferLength

public final int getRawDateBufferLength()

fillLogDateBuffer

public final byte[] fillLogDateBuffer(long now,
                                      java.lang.String timeFormat)

getLogDateBufferLength

public final int getLogDateBufferLength()

close

public void close()
           throws java.io.IOException
Closes the request, called from web-app for early close.

Throws:
java.io.IOException

finishInvocation

public void finishInvocation()
                      throws java.io.IOException
Complete the invocation. Flushes the streams, completes caching and writes the appropriate logs.

Throws:
java.io.IOException

finishRequest

public void finishRequest()
                   throws java.io.IOException
Complete the invocation. Flushes the streams, completes caching and writes the appropriate logs.

Throws:
java.io.IOException

free

protected void free()