org.locomotive.loco
Class Response

java.lang.Object
  |
  +--org.locomotive.loco.Response
Direct Known Subclasses:
LocoServletResponse

public class Response
extends java.lang.Object

This object encapsulates a response from the Locomotive back to the browser. Typically one would call addString() to add something to the response, then call flush() to send it off to the browser. Alternatively, one can cast this to a ServletResponse and use getOutputStream to write to the response.


Inner Class Summary
protected  class Response.ResponseOutputStream
          our little ServletOutputStream.
 
Field Summary
protected  java.lang.String char_encoding
           
protected  java.lang.String content_type
           
protected  boolean header_was_flushed
           
protected  java.io.OutputStream os
           
protected  int reply_type
           
static int REPLY_TYPE_CGI
           
static int REPLY_TYPE_ISAPI
           
static int REPLY_TYPE_NSAPI
           
protected  int request_id
           
protected  Response.ResponseOutputStream resos
           
 
Constructor Summary
Response(java.io.OutputStream theos, int rid, int reply_type_in)
          constructs a new response.
 
Method Summary
 void addBytes(byte[] addme)
          adds the input byte array to the Response.
 void addCookie(javax.servlet.http.Cookie cookie)
          Adds a cookie to the headers for this response
 void addHTTPHeader(java.lang.String name, java.lang.String value)
          adds an HTTP protocol header to the response.
 void addString(java.lang.String s)
          appends to the output of the Response.
 void clearBody()
          clears whatever data is currently resident in the Response body.
 void clearHeaders()
          wipes all headers for this response.
 boolean containsHeader(java.lang.String name)
          Returns true if a header with the specified name has been set.
 void flush()
          Flushes the contents of the Response with no logging.
 void flush(Log server_log)
          flushes the contents of the response to the OutputStream.
 java.lang.String getCharacterEncoding()
          returns the character encoding, if it was included in the content type.
 int getCurrentResponseLength()
          gets the current length of the data in the response buffer.
 int getHeaderCount()
          returns the number of items currently scheduled to be sent in the HTTP header
 void setAutoflush(boolean bol)
          setting this to true will cause the Response to flush automatically during every addString() or addBytes ()
 void setContentType(java.lang.String t)
          sets the content type HTTP header to the the input string.
protected  void writeHeader(Log server_log)
          This writes the headers to the OutputStream in correct protocol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPLY_TYPE_CGI

public static int REPLY_TYPE_CGI

REPLY_TYPE_NSAPI

public static int REPLY_TYPE_NSAPI

REPLY_TYPE_ISAPI

public static int REPLY_TYPE_ISAPI

content_type

protected java.lang.String content_type

char_encoding

protected java.lang.String char_encoding

header_was_flushed

protected boolean header_was_flushed

resos

protected Response.ResponseOutputStream resos

os

protected java.io.OutputStream os

request_id

protected int request_id

reply_type

protected int reply_type
Constructor Detail

Response

public Response(java.io.OutputStream theos,
                int rid,
                int reply_type_in)
constructs a new response. Package friendly but not public. Responses are instantiated by the Request Manager for each response. Request Manger is responsible for picking the correct protocol, which is determined by the protocol version sent to it via the tunnel.
Method Detail

addHTTPHeader

public void addHTTPHeader(java.lang.String name,
                          java.lang.String value)
adds an HTTP protocol header to the response. Adding any headers after the first flush() will be ineffective, since the HTTP header has already been sent off to the webserver/client. The values will be formatted in a manner appropriate for HTTP - similar to RFC 822 - " Name: Value "
An example might be "Pragma: no-cache"
Parameters:
name - - the name
value - - the value associated with name.

getHeaderCount

public int getHeaderCount()
returns the number of items currently scheduled to be sent in the HTTP header

containsHeader

public boolean containsHeader(java.lang.String name)
Returns true if a header with the specified name has been set.

setContentType

public void setContentType(java.lang.String t)
sets the content type HTTP header to the the input string. The input should be of the form "major/minor" If left unset the Response will default to type "text/html"
Parameters:
t - the MIME type of the response data

getCharacterEncoding

public java.lang.String getCharacterEncoding()
returns the character encoding, if it was included in the content type. If no character encoding was included, this will return 'ISO-8859-1'.

clearHeaders

public void clearHeaders()
wipes all headers for this response. Content-Type is unaffected, as it is required by the CGI spec and by Loco native webserver connectivity modules.

setAutoflush

public void setAutoflush(boolean bol)
setting this to true will cause the Response to flush automatically during every addString() or addBytes ()
Parameters:
bol - - true if Response should autoflush

clearBody

public void clearBody()
clears whatever data is currently resident in the Response body. If set to autoflush, calling this will be next to useless.

flush

public void flush()
Flushes the contents of the Response with no logging.

flush

public void flush(Log server_log)
flushes the contents of the response to the OutputStream. If the header has already been written, it is not written again, only the body buffers are emptied. Flush can be called multiple times during the life of the response, each time flushing whatever has been added since the last flush.

getCurrentResponseLength

public int getCurrentResponseLength()
gets the current length of the data in the response buffer. The length returned does not include the length of the header variables, only the response body.

addString

public void addString(java.lang.String s)
appends to the output of the Response. If autoflush is true, the call will block until the data has been written or fails. Given that the typically write is destined for a locolink or webserver module, this will
Parameters:
s - - the data to be written to the client

addBytes

public void addBytes(byte[] addme)
adds the input byte array to the Response. If autoflush is true, the Response will immediately flush the data.

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Adds a cookie to the headers for this response

writeHeader

protected void writeHeader(Log server_log)
                    throws java.io.IOException
This writes the headers to the OutputStream in correct protocol. This get's called automatically when either of the two inner stream flush, so we don't have to worry about calling it explicitly.