com.cometway.httpd
Class HTTPAgentRequest

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.AgentMessage
          extended by com.cometway.ak.AgentRequest
              extended by com.cometway.httpd.HTTPAgentRequest

public class HTTPAgentRequest
extends AgentRequest

This file is an extension of the com.cometway.ak.AgentRequest class. This class prints an HTTP response in the case that an agent which was requested by a browser does not return a proper HTTP/1.1 response header.public class HTTPAgentRequest extends AgentRequest.


Field Summary
protected  java.io.InputStream browserIn
           
 boolean bufferOutput
          This flag tells the HTTPAgentRequest whether or not to buffer all the output that is to be sent to the browser.
 boolean byteWiseWriting
          For some slower internet connections or under heavy traffic, this flag set to true will help ensure the TCP connection doesn't get cut off.
protected  Props clientCookies
           
protected  java.util.Vector cookies
           
protected  java.lang.StringBuffer dataBuffer
           
 java.lang.String defaultResponse
           
 boolean headerSending
           
 boolean headerSent
           
protected  boolean headRequest
           
protected  java.lang.String returnVal
           
protected  java.lang.String sessionID
           
 
Fields inherited from class com.cometway.ak.AgentRequest
err, out, writer
 
Fields inherited from class com.cometway.ak.AgentMessage
props
 
Constructor Summary
HTTPAgentRequest(Props p, java.io.OutputStream out, java.io.OutputStream err)
           
HTTPAgentRequest(Props p, java.io.OutputStream out, java.io.OutputStream err, java.io.InputStream in)
           
HTTPAgentRequest(Props p, java.io.OutputStream out, java.io.OutputStream err, java.io.Reader in)
           
 
Method Summary
 void addCookie(java.lang.String cookieData)
          This method adds a Cookie to the portion of the HTTP response header, when the header is sent.
 void close()
           
 void detectBrowsers()
          Tests the User-Agent value and stores the results as properties of this request.
 java.io.InputStream getClientInputStream()
          If an input stream to the client was provided, this method will return that stream.
 int getContentLength()
          Returns a content length of the request if one exists.
 Props getCookies()
          This method will return a Props of the cookie name=value pairs from the client's request.
 java.util.Date getIfModifiedSince()
          This method returns a Date Object that corresponds to the request's If-Modifed-Since field.
 java.lang.String getRequestBody()
          This method returns the body of the client's request
 java.lang.String getRequestHeaders()
          This method returns the headers of the client's request
 java.lang.String getSessionID()
          This method will automatically fetch the session ID of the requesting client's cookies.
 java.lang.String getSessionID(java.lang.String cookieName)
          This method will automatically fetch the session ID of the requesting client's cookies.
 java.lang.String getUserAgent()
          Returns the value of the "User-Agent" header parameter.
static java.lang.String getUserAgent(AgentRequest request)
          Returns the User-Agent header parameter value from the specified AgentRequest.
protected static java.lang.String getUserAgent(java.lang.String s)
          Returns the User-Agent header parameter value from the specified String.
protected  void handleResponseHeader(java.lang.String s)
          deals with checking for header and sending it if needed
 boolean isHeadRequest()
          Returns true if the request is a headers only request
 void print(java.lang.String s)
          Prints String input and header information (content-type, etc.).
 void println()
          Prints a newline to the agent's standard OutputStream using a PrintWriter.
 void println(java.lang.String s)
          Prints String and header information to HTML output.
 boolean setSessionCookie(SessionManagerInterface sessionManager)
          This method will automatically set a cookie to be written to the client when the response header is to be written.
 boolean setSessionCookie(SessionManagerInterface sessionManager, java.lang.String cookieName)
          This method will automatically set a cookie to be written to the client when the response header is to be written.
protected  void updateFlags(java.lang.String s)
          Updates the state flags after a print() or println()
 
Methods inherited from class com.cometway.ak.AgentRequest
getErrorStream, getOutputStream, getRequestType, getWriter, isRequestType, setContentType
 
Methods inherited from class com.cometway.ak.AgentMessage
getProps
 
Methods inherited from class com.cometway.props.Props
addListener, append, copy, copyFrom, copyTo, decrementInteger, dump, enableListeners, enumerateKeys, format, getBoolean, getByteArray, getCharacter, getDate, getDate, getDateString, getDouble, getFloat, getHexString, getInteger, getKeys, getLong, getNextKey, getProperty, getProperty, getPropsContainer, getSize, getString, getString, getTokens, getTokens, getTrimmedString, getVector, hasProperty, incrementInteger, insertProps, loadProps, notifyPropsChanged, notifyPropsChangedIgnore, notifyPropsChangedIgnore, parse, propertyMatchesRegEx, readFromFile, regExPropertyMatches, removeAll, removeListener, removeProperty, resumeNotify, saveProps, set, setBoolean, setCharacter, setDefault, setDouble, setFloat, setInteger, setLong, setProperty, setProperty, setProperty, setPropsContainer, suspendNotify, toString, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

byteWiseWriting

public boolean byteWiseWriting
For some slower internet connections or under heavy traffic, this flag set to true will help ensure the TCP connection doesn't get cut off. For faster blocks for writing data to the browser, set this to false.


bufferOutput

public boolean bufferOutput
This flag tells the HTTPAgentRequest whether or not to buffer all the output that is to be sent to the browser. When the HTTPAgentRequest.close() method is called, the entire buffer will be sent to the browser. If this flag is set to false, the output will be sent to the browser immediately when a print() method is called.


dataBuffer

protected java.lang.StringBuffer dataBuffer

defaultResponse

public java.lang.String defaultResponse

headerSending

public boolean headerSending

headerSent

public boolean headerSent

browserIn

protected java.io.InputStream browserIn

cookies

protected java.util.Vector cookies

clientCookies

protected Props clientCookies

sessionID

protected java.lang.String sessionID

headRequest

protected boolean headRequest

returnVal

protected java.lang.String returnVal
Constructor Detail

HTTPAgentRequest

public HTTPAgentRequest(Props p,
                        java.io.OutputStream out,
                        java.io.OutputStream err)

HTTPAgentRequest

public HTTPAgentRequest(Props p,
                        java.io.OutputStream out,
                        java.io.OutputStream err,
                        java.io.Reader in)

HTTPAgentRequest

public HTTPAgentRequest(Props p,
                        java.io.OutputStream out,
                        java.io.OutputStream err,
                        java.io.InputStream in)
Method Detail

isHeadRequest

public boolean isHeadRequest()
Returns true if the request is a headers only request


getUserAgent

public java.lang.String getUserAgent()
Returns the value of the "User-Agent" header parameter.


getUserAgent

public static java.lang.String getUserAgent(AgentRequest request)
Returns the User-Agent header parameter value from the specified AgentRequest.


getUserAgent

protected static java.lang.String getUserAgent(java.lang.String s)
Returns the User-Agent header parameter value from the specified String.


getClientInputStream

public java.io.InputStream getClientInputStream()
If an input stream to the client was provided, this method will return that stream.


getRequestBody

public java.lang.String getRequestBody()
This method returns the body of the client's request


getRequestHeaders

public java.lang.String getRequestHeaders()
This method returns the headers of the client's request


getContentLength

public int getContentLength()
Returns a content length of the request if one exists. If the content length was not specified, it returns a -1


detectBrowsers

public void detectBrowsers()
Tests the User-Agent value and stores the results as properties of this request.


handleResponseHeader

protected void handleResponseHeader(java.lang.String s)
deals with checking for header and sending it if needed


updateFlags

protected void updateFlags(java.lang.String s)
Updates the state flags after a print() or println()


print

public void print(java.lang.String s)
Prints String input and header information (content-type, etc.).

Overrides:
print in class AgentRequest

println

public void println(java.lang.String s)
Prints String and header information to HTML output.

Overrides:
println in class AgentRequest

println

public void println()
Description copied from class: AgentRequest
Prints a newline to the agent's standard OutputStream using a PrintWriter.

Overrides:
println in class AgentRequest

getCookies

public Props getCookies()
This method will return a Props of the cookie name=value pairs from the client's request. If there are no cookies, the props is empty. Duplicate names are ignored. Note that although all the cookies in the returned Props are directed toward a single handler, those cookie values may not have originated from the same cookie; the 'expires', 'path', etc are not included in the client's response header and are not part of the returned value.


addCookie

public void addCookie(java.lang.String cookieData)
This method adds a Cookie to the portion of the HTTP response header, when the header is sent. The cookie will not be added unless the header is sent automatically; if the header is printed by the caller using the println() methods, cookies added will not be sent. Note: The server sets cookies via the Set-Cookie header, each cookie is set with its own Set-Cookie, here is the syntax: Set-Cookie: session_id=6a4ffea80df889bd7bfe6a592c0789d8; path=/ Set-Cookie: member_id=67; expires=Thu, 26-Aug-04 10:27:18 GMT; path=/ Set-Cookie: pass_hash=4b8e908578ba4bc4ef26740b39bb8831; expires=Thu, 26-Aug-04 10:27:18 GMT; path=/ These cookies are sent from the client to the server via the Cookie: header, all the cookies are sent in one Cookie header, only the data prior to the ';' symbol is sent. Here is the syntax of a client sending the server cookie data for the above example: Cookie: session_id=6a4ffea80df889bd7bfe6a592c0789d8; member_id=67; pass_hash=4b8e908578ba4bc4ef26740b39bb8831 It is up to the client to determine what cookies need to be sent to what servers depending on the URI path, and whether to send them or not depending on the expiration of the cookie. Therefore, an example of the cookieData parameter is: member_id=67; expires=Thu, 26-Aug-04 10:27:18 GMT; path=/


getSessionID

public java.lang.String getSessionID()
This method will automatically fetch the session ID of the requesting client's cookies. The name of the cookie is assumed to be 'session_id' If no session ID was found in the client cookies, null is returned.


getSessionID

public java.lang.String getSessionID(java.lang.String cookieName)
This method will automatically fetch the session ID of the requesting client's cookies. The name of the cookie is provided as a parameter If no session ID was found in the client cookies, null is returned.


setSessionCookie

public boolean setSessionCookie(SessionManagerInterface sessionManager)
This method will automatically set a cookie to be written to the client when the response header is to be written. The session ID cookie name will be assumed 'session_id', the path cookie name will be assumed 'path', and the expires cookie name will be assumed 'expires'. If a path and/or expires name is not found in the session props for this session ID, they will not be included in the cookie. If no session ID was found in the client cookies, no cookie will be sent.


setSessionCookie

public boolean setSessionCookie(SessionManagerInterface sessionManager,
                                java.lang.String cookieName)
This method will automatically set a cookie to be written to the client when the response header is to be written. The session ID cookie name will provided via the parameter 'cookieName', the path cookie name will be assumed 'path', and the expires cookie name will be assumed 'expires'. If a path and/or expires name is not found in the session props for this session ID, they will not be included in the cookie. If no session ID was found in the client cookies, no cookie will be sent.


getIfModifiedSince

public java.util.Date getIfModifiedSince()
This method returns a Date Object that corresponds to the request's If-Modifed-Since field. This date can be used to determine if the data requested has been changed and needs to be resent. If not, a 304 response should be returned. In the event that this field doesn't exist, null is returned.


close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException