com.ibm.wbi.http.request
Class DocumentInfo

com.ibm.wbi.http.request.DocumentInfo

public class DocumentInfo

A document info object represents a request that is in the HTTP 1.0 format. The document info encapsulates a request header (the request from the browser) and a response header (the response from the generator). This class is designed to allow access to the MIME data associated with an HTTP request/response stream.


Field Summary
static java.lang.String COPYRIGHT
          IBM copyright information.
static int REQUESTTYPE_PROXY
          The request type is proxy.
static int REQUESTTYPE_SERVER
          The request type is server.
static int REQUESTTYPE_UNKNOWN
          The request type is unknown.
static int UNIQUE_ID
          Unique number of the this type (DocumentInfo) request info object.
 
Constructor Summary
DocumentInfo()
          Constructs a new document info object.
 
Method Summary
 RequestInfo createInstance()
          Create an empty instance of this document info class.
 java.util.Vector getAllByKey(java.lang.String key, int whichHeader)
          Returns a Vector containing all values associated with the specified key.
 boolean getBrowserNoCache()
          Returns the browserNoCache field from this DocumentInfo object.
 java.lang.String getByKey(java.lang.String key, int whichHeader)
          Returns a String representing the first occurrence of a value associated with the specified key.
 java.lang.String getClient()
          Returns the client field from this object.
 java.net.InetAddress getClientAddress()
          Returns the client InetAddress from this object.
 java.lang.String getClientName()
          Returns the client name from this object.
 java.lang.String getClientNumber()
          Returns the client number from this object.
 java.lang.String getData()
          Returns the data field from this object.
 java.lang.String getHost()
          Returns the host (or server) used when the request was made.
 int getIdentifier()
          Get the unique number of the document info class.
 int getLocalPort()
          Determine the actual local port this request came from, instead of using the port value specified in the HTTP request (which may not exist).
 java.lang.String getMethod()
          Returns the current method associated with the latest request.
 java.lang.String getPath()
          Returns the path used when the request was made.
 int getPort()
          Returns the port used when the request was made.
 java.lang.String getProtocol()
          Returns the protocol used when the request was made.
 java.lang.String getQuery()
          Returns any query data found on the requested URL.
 java.lang.String getRequestContentLength()
          Get the request content length.
 java.lang.String getRequestContentType()
          Get the request content type.
 java.lang.String getRequestContentTypeParameters()
          Get the request content type parameters.
 java.lang.String getRequestHeader()
          Returns the current request header (including MIME data) from the DocumentInfo object.
 int getRequestType()
          Returns the request type associated with this DocumentInfo object.
 int getResponseCode()
          Returns the response code from the response header.
 java.lang.String getResponseContentLength()
          Returns the content length data from the response header.
 java.lang.String getResponseContentType()
          Returns the content type data associated with the response header.
 java.lang.String getResponseContentTypeParameters()
          Get the response content type parameters.
 java.lang.String getResponseHeader()
          Returns the current response header (including MIME data) from the DocumentInfo object.
 java.lang.String getServer()
          Returns the host (or server) used when the request was made.
 java.lang.String getUrl()
          Returns the URL used when the request was made.
 java.lang.String getUserAgent()
          Returns the user agent data from the response header.
 void populateInstance(RequestInfo toCopy)
          Populate the object from the passed in request info (make this object a copy of the passed in one).
 void removeByKey(java.lang.String key, int whichHeader)
          Removes the specified key (and all values) from the header.
 void setBrowserNoCache()
          Sets the browserNoCache field in this DocumentInfo object to true.
 void setCached()
          Sets the cached flag to true.
 void setClient(java.net.InetAddress addr)
          Sets the client address field within this DocumentInfo object to the passed InetAddress object.
 void setClient(java.lang.String s)
          Sets the client field within this DocumentInfo object to the passed string.
 void setData(java.lang.String s)
          Sets the data field within this DocumentInfo object to the passed string.
 void setLocalPort(int localport)
          Set the actual local port this request came from; instead of using the port value specified in the HTTP request (which may not exist).
 void setRequestHeader(java.lang.String s)
          Sets the request header field in this DocumentInfo object to the passed string.
 void setRequestHeader(java.lang.StringBuffer s)
          Sets the request header field in this DocumentInfo object to the passed StringBuffer.
 void setResponseHeader(HttpHeader header)
          Sets the response header field in this DocumentInfo object.
 void setResponseHeader(java.lang.String s)
          Sets the response header field in this DocumentInfo object to the passed String.
 void setResponseHeader(java.lang.StringBuffer s)
          Sets the response header field in this DocumentInfo object to the passed StringBuffer.
 boolean wasCached()
          Queries the cached flag.
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
IBM copyright information.

UNIQUE_ID

public static final int UNIQUE_ID
Unique number of the this type (DocumentInfo) request info object.

REQUESTTYPE_UNKNOWN

public static final int REQUESTTYPE_UNKNOWN
The request type is unknown.

REQUESTTYPE_PROXY

public static final int REQUESTTYPE_PROXY
The request type is proxy.

REQUESTTYPE_SERVER

public static final int REQUESTTYPE_SERVER
The request type is server.
Constructor Detail

DocumentInfo

public DocumentInfo()
Constructs a new document info object.
Method Detail

getIdentifier

public int getIdentifier()
Get the unique number of the document info class.
Returns:
The unique identifier for the request info object.
See Also:
com.ibm.wbi.request.RequestDescriptor

createInstance

public RequestInfo createInstance()
Create an empty instance of this document info class.
Returns:
The document info object.
See Also:
com.ibm.wbi.request.RequestDescriptor

populateInstance

public void populateInstance(RequestInfo toCopy)
Populate the object from the passed in request info (make this object a copy of the passed in one).
Parameters:
toCopy - The request info to populate from.
See Also:
com.ibm.wbi.request.RequestDescriptor

setRequestHeader

public void setRequestHeader(java.lang.StringBuffer s)
Sets the request header field in this DocumentInfo object to the passed StringBuffer. This represents the raw, unparsed request header string (HTTP protocol, including MIME data). Methods that return portions of the request header (i.e. specific MIME fields for example) use this string as a source of data.
Parameters:
s - The inbound StringBuffer representing the raw request header.

setRequestHeader

public void setRequestHeader(java.lang.String s)
Sets the request header field in this DocumentInfo object to the passed string. This represents the raw, unparsed request header string (HTTP protocol, including MIME data). Methods that return portions of the request header (i.e. specific MIME fields for example) use this string as a source of data.
Parameters:
s - The inbound String representing the raw request header.

getRequestHeader

public java.lang.String getRequestHeader()
Returns the current request header (including MIME data) from the DocumentInfo object.
Returns:
"" if the request header field has not been set; else a string representing the request header.

setResponseHeader

public void setResponseHeader(java.lang.String s)
Sets the response header field in this DocumentInfo object to the passed String. This represents the raw, unparsed response header string (HTTP protocol, including MIME data). Methods that return portions of the response header (i.e. specific MIME fields for example) use this String as a source of data.
Parameters:
s - The inbound String representing the raw response header.

setResponseHeader

public void setResponseHeader(HttpHeader header)
Sets the response header field in this DocumentInfo object. The new header is obtained from the passed HttpHeader object. This represents the raw, unparsed response header string (HTTP protocol, including MIME data).
Parameters:
header - The inbound HTTPHeader object representing the raw response header.

setResponseHeader

public void setResponseHeader(java.lang.StringBuffer s)
Sets the response header field in this DocumentInfo object to the passed StringBuffer. This represents the raw, unparsed response header string (HTTP protocol, including MIME data). Methods that return portions of the response header (i.e. specific MIME fields for example) use this StringBuffer as a source of data.
Parameters:
s - The inbound StringBuffer representing the raw response header.

getResponseHeader

public java.lang.String getResponseHeader()
Returns the current response header (including MIME data) from the DocumentInfo object.
Returns:
"" if the request header field has not been set; else a string representing the response header.

setClient

public void setClient(java.lang.String s)
Sets the client field within this DocumentInfo object to the passed string. The client field normally consists of a two token field. The first token represents the host name (client name) of the requesting browser. The second token represents the IP address (client number) of the requesting browser.
Parameters:
s - The inbound string that will become the client.

setClient

public void setClient(java.net.InetAddress addr)
Sets the client address field within this DocumentInfo object to the passed InetAddress object.
Parameters:
addr - The inbound InetAddress that will become the client address.

getClient

public java.lang.String getClient()
Returns the client field from this object. The client field normally consists of a two token field. The first token represents the host name (client name) of the requesting browser. The second token represents the IP address (client number) of the requesting browser.
Returns:
A String representing the current client setting.

getClientNumber

public java.lang.String getClientNumber()
Returns the client number from this object. The client number is obtained from the client field within the DocumentInfo object. The value returned typically represents the IP address of the requesting browser.
Returns:
"" if the field has not been set; else a string representing the current client number.

getClientName

public java.lang.String getClientName()
Returns the client name from this object. The client name is obtained from the client field within the DocumentInfo object. The value returned typically represents the host name of the requesting browser.
Returns:
"" if the field has not been set; else a string representing the current client name.

getClientAddress

public java.net.InetAddress getClientAddress()
Returns the client InetAddress from this object.
Returns:
null if the field has not been set; else the client InetAddress.

setData

public void setData(java.lang.String s)
Sets the data field within this DocumentInfo object to the passed string. This field represents any data that was sent on the request (i.e. POST or PUT may have associated data).
Parameters:
s - The inbound string that will become the data.

getData

public java.lang.String getData()
Returns the data field from this object. The data field is used to represent any data sent during the request. Most useful for POST and PUT requests.
Returns:
A string representing the current data setting.

setLocalPort

public void setLocalPort(int localport)
Set the actual local port this request came from; instead of using the port value specified in the HTTP request (which may not exist).
Parameters:
localPort - The actual port the request came in from.

getLocalPort

public int getLocalPort()
Determine the actual local port this request came from, instead of using the port value specified in the HTTP request (which may not exist).
Returns:
localPort The actual port the request came in from; -1 if not specified.

getMethod

public java.lang.String getMethod()
Returns the current method associated with the latest request. The method represents the HTTP method used to obtain the data. Examples include 'GET', 'POST', etc.
Returns:
"" if the request header field has not been set; else a string representing the method in the request header.

getProtocol

public java.lang.String getProtocol()
Returns the protocol used when the request was made. The protocol represents the HTTP protocol used to obtain the data. Examples include 'http', 'ftp', etc. The value is obtained from the URL used when the request was made.
Returns:
"" if the field has not been set; else a string representing the protocol.

getHost

public java.lang.String getHost()
Returns the host (or server) used when the request was made. The host is obtained from the requested URL.
Returns:
"" if the header field has not been set; else a string representing the host.

getServer

public java.lang.String getServer()
Returns the host (or server) used when the request was made. The host is obtained from the requested URL.
Returns:
"" if the header field has not been set; else a string representing the host.

getPort

public int getPort()
Returns the port used when the request was made. The port is obtained from the URL used during the request.
Returns:
Since the port is optional in a URL, 0 is returned if the request header has been set but the port was not specified in the request; -1 if the request header has not been set; An int representing the port used when the request was made.

getPath

public java.lang.String getPath()
Returns the path used when the request was made. The path is obtained from the requested URL.
Returns:
If the request header has been set but no path was specified in the URL, the default path ("/") is returned; else "" if the request header field has not been set; else a string representing the path.

getQuery

public java.lang.String getQuery()
Returns any query data found on the requested URL. Query data is that data that is found after the path data and separated from the path by a "?" character. Note that the leading "?" is included in the returned value if any query data is found.
Returns:
"" if the request header has been set but no query information was used in the URL; null if the request header field has not been set; else a string representing the query data.

getUrl

public java.lang.String getUrl()
Returns the URL used when the request was made.
Returns:
"" if the request header field has not been set; else a string representing the URL.

getResponseCode

public int getResponseCode()
Returns the response code from the response header. The response code represents the result of the request. In general, a response code of 2xx indicates that the request was successful. Consult the appropriate HTTP specification information for a complete list of result codes.
Returns:
-1 if the response header field has not been set; 0 if the response header field has been set but the response code was not able to be parsed correctly for some reason; else an int representing the response code.

setBrowserNoCache

public void setBrowserNoCache()
Sets the browserNoCache field in this DocumentInfo object to true. Use of this method is a request that the response sent back to the browser have specific no-cache MIME data attached. This MIME data requests that the browser avoid caching the returned page. Actual implementation of this feature is browser dependent and beyond the Proxy's control.

getBrowserNoCache

public boolean getBrowserNoCache()
Returns the browserNoCache field from this DocumentInfo object.
Returns:
true if browserNoCache field is true; else false.

getRequestContentType

public java.lang.String getRequestContentType()
Get the request content type.
Returns:
The request content type (i.e. text/html); "" if not specified.

getRequestContentTypeParameters

public java.lang.String getRequestContentTypeParameters()
Get the request content type parameters. This is the portion of the content type that appears after the semi-colon in the HTTP header
Returns:
The request content type parameters (i.e. "charset=ISO-8859-1"); "" if not specified.

getRequestContentLength

public java.lang.String getRequestContentLength()
Get the request content length.
Returns:
The request content length; if not specified.

getResponseContentType

public java.lang.String getResponseContentType()
Returns the content type data associated with the response header. The Content-Type: field in the MIME header is used to specify the media type of the entity body being sent. An example of this would be text/html. For a discussion of what values are allowed in this field, consult the appropriate HTTP specification documentation.
Returns:
"" if the response header field has not been set, or if the content type was not specified in the returned MIME data; else a string representing the content type of the response.

getResponseContentTypeParameters

public java.lang.String getResponseContentTypeParameters()
Get the response content type parameters. This is the portion of the content type that appears after the semi-colon in the HTTP header
Returns:
The response content type parameters (i.e. "charset=ISO-8859-1"); "" if not specified.

getResponseContentLength

public java.lang.String getResponseContentLength()
Returns the content length data from the response header. The Content-Length: field in the MIME header indicates the size of the message body (a decimal number) being sent. This field is not always specified.
Returns:
"" if the response header field has not been set, or if the content length was not specified in the returned MIME data; else a string representing the content length of the response.

getUserAgent

public java.lang.String getUserAgent()
Returns the user agent data from the response header. When a request is made by a browser (or other source), it often provides information on exactly which browser (or other user agent) made the request. This allows servers to customize their return with respect to who issued the request. The information (if provided) is contained on the User-Agent: MIME header tag. This method allows this value to be obtained.
Returns:
"" if the response header field has not been set or if the user agent was not specified in the returned MIME data; else a string representing the user agent of the response.

getRequestType

public int getRequestType()
Returns the request type associated with this DocumentInfo object.
Returns:
REQUESTTYPE_UNKNOWN if the request header field has not been set; else REQUESTTYPE_PROXY if the request is a proxy type request. REQUESTTYPE_SERVER the request is a server type request.

setCached

public void setCached()
Sets the cached flag to true. The cached flag indicates the data being presented in this stream is the result of a cache read.

wasCached

public boolean wasCached()
Queries the cached flag. The cached flag indicates the data being presented in this stream is the result of a cache read.
Returns:
true if cache page was cached; else false.

getByKey

public java.lang.String getByKey(java.lang.String key,
                                 int whichHeader)
Returns a String representing the first occurrence of a value associated with the specified key. Multiple values are possible (some MIME keys can repeat values. An example is Accept:). If no values are found associated with the passed key, an empty String is returned.
Parameters:
key - A MIME data key used when consulting the header string.
whichHeader - Selects which header to search; One of REQUEST_HEADER, RESPONSE_HEADER
Returns:
A String containing all values associated with the passed key.

getAllByKey

public java.util.Vector getAllByKey(java.lang.String key,
                                    int whichHeader)
Returns a Vector containing all values associated with the specified key. Multiple values are possible within the Vector (some MIME keys can repeat values. An example is Accept:). If no values are found associated with the passed key, an empty Vector is returned.
Parameters:
key - A MIME data key used when consulting the header string.
whichHeader - Selects which header to search; One of REQUEST_HEADER, RESPONSE_HEADER
Returns:
A Vector containing all values associated with the passed key.

removeByKey

public void removeByKey(java.lang.String key,
                        int whichHeader)
Removes the specified key (and all values) from the header.
Parameters:
key - A MIME data key used when consulting the header string.
whichHeader - Selects which header to search; One of REQUEST_HEADER, RESPONSE_HEADER