Femto Web Server V1.4-F

dfischer.femtowebserver.httpd
Class HttpRequest

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--dfischer.femtowebserver.httpd.HttpRequest
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class HttpRequest
extends java.util.Hashtable

Allows Weblets and SSSIs to access the HTTP request data (browser request) and (optionally) allows a Filter to modify every HTTP request.

More information about the HTTP protocol is available at http://www.w3.org

See Also:
HttpdWebletInterface, HttpdSssiInterface, HttpUploadFile, HttpdFilter, HttpdSession, Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Method Summary
 void addCookie(java.lang.String name, java.lang.String value)
          Allows to add a cookie to the HTTP request.
 void addHeaderField(java.lang.String headerFieldName, java.lang.String headerFieldValue)
          Allows to add additional HTTP header fields inside the HTTP request header.
 void addParameter(java.lang.String parameterName, java.lang.String parameterValue)
          Allows to add an additional parameter to the HTTP request.
 void clearContent()
          Allows to remove the request content data.
 void dump()
          Dumps the HTTP request header and the request content to the log output.
 java.lang.String getBasicAuthorizationPassword()
          Returns the (basic) authorization password, which has been set by the agent (browser).
 java.lang.String getBasicAuthorizationUsername()
          Returns the (basic) authorization username, which has been set by the agent (browser).
 byte[] getContent()
          Returns the content data of the request.
 java.lang.String getContentSubtype()
          Returns the MIME subtype of the request content data, if this information has been set by the agent (browser).
 java.lang.String getContentType()
          Returns the MIME type of the request content data, if this information has been set by the agent (browser).
 java.lang.String getCookieValue(java.lang.String cookieName)
          Returns the value of a received cookie, selected by its name.
 java.lang.String[] getHeader()
          Returns the whole HTTP request header.
 java.lang.String getHeaderField(java.lang.String headerFieldName)
          Returns the value of a header field name.
 java.lang.String[] getHeaderFieldNames()
          Returns a list of all request header field names (header line 1..n-1).
 java.lang.String getHttpProtocol()
          Returns the HTTP protocol version ("HTTP/1.0", "HTTP/1.1" ...) of the agent (browser).
 java.lang.String getMethod()
          Returns the HTTP request method ("GET", "POST" ...).
 java.lang.String getParameter(java.lang.String parameterName)
          Returns the value of a request parameter.
 java.lang.String getParameter(java.lang.String parameterName, boolean asRawValue)
          Returns the value of a request parameter.
 int getParameterAsInt(java.lang.String parameterName)
          Returns the value of a request parameter as int number.
 long getParameterAsLong(java.lang.String parameterName)
          Returns the value of a request parameter as long number.
 java.lang.String[] getParameterNames()
          Returns a list of all names of the request parameters, nevertheless if there is a "GET" or a "POST" request.
 java.lang.String getParameterString(java.lang.String parameterName)
          Returns the value of a request parameter or an empty string, if no such parameter is available.
 java.lang.String[] getParameterValues(java.lang.String parameterName)
          Returns all values of one request parameter name.
 java.lang.String getProtocol()
          Returns the request network protocol ("http", "https" ...).
 java.lang.String getQueryString()
          Deprecated. Better use getParameterNames() and getParameter()
 HttpCookie[] getReceivedCookies()
          Returns an array[] of all received cookies.
 java.lang.String getRemoteAddress()
          Returns the TCP/IP remote address of the agent (browser).
 java.lang.String getRequest()
          Returns the request file with the full path, but does not include the (optional) CGI parameters.
 java.lang.String getRequestFile()
          Returns the request file without any path.
 java.lang.String getRequestPath()
          Returns the path to the request file (without the request file itself).
 HttpdSession getSession()
          Returns the current HTTP session (only if a session handler is active).
 HttpUploadFile getUploadFile(java.lang.String parameterName)
          Returns an uploaded file with its data, selected by the HTML parameter name.
 HttpUploadFile[] getUploadFiles()
          Returns all uploaded files.
 java.lang.String getURI()
          Deprecated. Better use getRequest(), getParameterNames() and getParameter()
 java.lang.String getUserAgent()
          Returns the browser product name and version (if any).
 java.lang.String getVirtualHost()
          Returns the name of the TCP/IP host (server) to which the agent (browser) has made the request.
 int getVirtualPort()
          Returns the non-standard server port number to which the agent (browser) has made the request.
 boolean hasBasicAuthorization()
          Checks if a base64 (basic) authorization has been set by the agent (browser).
 void removeCookie(java.lang.String name)
          Removes a received cookie from the HTTP request.
 void removeHeaderField(java.lang.String headerFieldName)
          Removes a HTTP header field.
 void removeParameter(java.lang.String parameterName)
          Removes a parameter from the HTTP request.
 void setContent(byte[] content)
          Allows to change the request content data.
 void setContentSubtype(java.lang.String contentSubtype)
          Allows to set a new MIME subtype of the request content data.
 void setContentType(java.lang.String contentType)
          Allows to set a new MIME type of the request content data.
 void setMethod(java.lang.String method)
          Allows to change the HTTP request method ("GET", "POST" ...).
 void setRemoteAddress(java.lang.String remoteAddress)
          Allows to change the TCP/IP remote address of the agent (browser).
 void setRequest(java.lang.String requestFile)
          Allows to set a new request file which must include also the full path, but without (optional) CGI parameters.
 void setSession(HttpdSession httpdSession)
          Allows to set a HTTP session before the request will be processed by the Femto Web Server.
 void setUserAgent(java.lang.String userAgent)
          Allows to set a new browser product name and version.
 void setVirtualHost(java.lang.String hostname)
          Allows to set a new name of the TCP/IP host (server) to which the agent (browser) has made the request.
 void setVirtualPort(int port)
          Allows to set a non-standard server port number to which the agent (browser) has made the request.
 void updateCookie(java.lang.String name, java.lang.String value)
          Allows to update the value of a cookie - or adds a new cookie if it doesn't exist.
 void updateCookieName(java.lang.String oldName, java.lang.String newName)
          Allows to modify the name of a received cookie.
 void updateHeaderField(java.lang.String headerFieldName, java.lang.String headerFieldValue)
          Allows to replace a HTTP header field value inside the HTTP request header.
 void updateParameter(java.lang.String parameterName, java.lang.String parameterValue)
          Allows to replace a parameter of the HTTP request.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

setSession

public void setSession(HttpdSession httpdSession)
Allows to set a HTTP session before the request will be processed by the Femto Web Server. Used in filters.

Parameters:
httpdSession - the HTTP session
See Also:
HttpdFilter, HttpSessionCookieHandler

getSession

public HttpdSession getSession()
Returns the current HTTP session (only if a session handler is active).

Returns:
the current HTTP session, if a session handler is active. Or null, if no session is available.
See Also:
HttpSessionCookieHandler

getRemoteAddress

public java.lang.String getRemoteAddress()
Returns the TCP/IP remote address of the agent (browser).
Returns:
TCP/IP remote address

setRemoteAddress

public void setRemoteAddress(java.lang.String remoteAddress)
                      throws java.net.UnknownHostException
Allows to change the TCP/IP remote address of the agent (browser). Used in filters.
Parameters:
remoteAddress - the TCP/IP remote address of the agent (browser)
See Also:
HttpdFilter

getHeader

public java.lang.String[] getHeader()
Returns the whole HTTP request header.
Returns:
HTTP request header
See Also:
getHeaderFieldNames(), getHeaderField(java.lang.String)

getHeaderFieldNames

public java.lang.String[] getHeaderFieldNames()
Returns a list of all request header field names (header line 1..n-1).
Returns:
list of all request header field names
See Also:
getHeaderField(java.lang.String), getHeader()

getHeaderField

public java.lang.String getHeaderField(java.lang.String headerFieldName)
Returns the value of a header field name.
Parameters:
headerFieldName - name of the header field (upper-/lower-case insensitive).
Returns:
value of a header field or null, if the header field was not found.
See Also:
getHeaderFieldNames(), getHeader()

addHeaderField

public void addHeaderField(java.lang.String headerFieldName,
                           java.lang.String headerFieldValue)
Allows to add additional HTTP header fields inside the HTTP request header. Used in filters.
The field "content-length" can only be modified by the methods setContent() or clearContent() and can not be added here. If it's not sure if the field already exists or not: use the method updateHeaderField().
Parameters:
headerFieldName - the header field name to add
headerFieldValue - the value of the header field
See Also:
updateHeaderField(java.lang.String, java.lang.String), HttpdFilter

updateHeaderField

public void updateHeaderField(java.lang.String headerFieldName,
                              java.lang.String headerFieldValue)
Allows to replace a HTTP header field value inside the HTTP request header. Used in filters.
If the header field name doesn't already exist, the name and value will be added to the header by calling addHeaderField().
The field "content-length" can only be modified by the methods setContent() or clearContent() and can not be updateted here.
Parameters:
headerFieldName - the header field name whose value should be modified
headerFieldValue - the new value of the header field
See Also:
addHeaderField(java.lang.String, java.lang.String), getHeaderField(java.lang.String), HttpdFilter

removeHeaderField

public void removeHeaderField(java.lang.String headerFieldName)
Removes a HTTP header field. Used in filters.

The field "content-length" can only be modified by the methods setContent() or clearContent() and can not be removed here.

Parameters:
headerFieldName - the name of the HTTP header field to remove. If the field name is not found inside the HTTP request header, this method will also complete successful.
See Also:
HttpdFilter

getReceivedCookies

public HttpCookie[] getReceivedCookies()
Returns an array[] of all received cookies.

Returns:
array[] of all received cookies or an empty array, if no cookies have been received.
See Also:
getCookieValue(java.lang.String)

getCookieValue

public java.lang.String getCookieValue(java.lang.String cookieName)
Returns the value of a received cookie, selected by its name.

Parameters:
cookieName - the name of the cookie (case sensitive)
Returns:
the value of the cookie or null, if no cookie with this name has been received. Consider that the value could be an empty string, if a cookie with a name but without a value has been received.
See Also:
getReceivedCookies()

addCookie

public void addCookie(java.lang.String name,
                      java.lang.String value)
Allows to add a cookie to the HTTP request. Used in filters.
Parameters:
name - cookie name (case sensitive)
value - cookie value
See Also:
getCookieValue(java.lang.String), updateCookie(java.lang.String, java.lang.String), updateCookieName(java.lang.String, java.lang.String), removeCookie(java.lang.String), getReceivedCookies(), HttpdFilter

updateCookie

public void updateCookie(java.lang.String name,
                         java.lang.String value)
Allows to update the value of a cookie - or adds a new cookie if it doesn't exist. Used in filters.

Parameters:
name - the name of the cookie to modify or to add (case sensitive).
value - the new cookie value.
See Also:
getCookieValue(java.lang.String), addCookie(java.lang.String, java.lang.String), updateCookieName(java.lang.String, java.lang.String), removeCookie(java.lang.String), getReceivedCookies(), HttpdFilter

updateCookieName

public void updateCookieName(java.lang.String oldName,
                             java.lang.String newName)
Allows to modify the name of a received cookie. Used in filters.

If no cookie with this name has been received, nothing will be done.

Parameters:
oldName - the (old) name of the cookie (case sensitive).
newName - the new name of the cookie.
See Also:
getCookieValue(java.lang.String), addCookie(java.lang.String, java.lang.String), updateCookie(java.lang.String, java.lang.String), removeCookie(java.lang.String), getReceivedCookies(), HttpdFilter

removeCookie

public void removeCookie(java.lang.String name)
Removes a received cookie from the HTTP request. Used in filters.

Parameters:
name - the name of the cookie to remove from the HTTP request (case sensitive). if no cookie with this name has been received, nothing will be done.
See Also:
getCookieValue(java.lang.String), addCookie(java.lang.String, java.lang.String), updateCookie(java.lang.String, java.lang.String), updateCookieName(java.lang.String, java.lang.String), getReceivedCookies(), HttpdFilter

getMethod

public java.lang.String getMethod()
Returns the HTTP request method ("GET", "POST" ...).
Returns:
HTTP request method in UPPERCASE

setMethod

public void setMethod(java.lang.String method)
Allows to change the HTTP request method ("GET", "POST" ...). Used in filters.
Parameters:
method - the HTTP request method, will be converted to UPPERCASE.
See Also:
getMethod(), HttpdFilter

getURI

public java.lang.String getURI()
Deprecated. Better use getRequest(), getParameterNames() and getParameter()

Returns the request URI. This is the request file (inclusive path) and with the optional CGI parameters.
Returns:
the request URI
See Also:
getRequest(), getParameterNames(), getParameter(java.lang.String)

getProtocol

public java.lang.String getProtocol()
Returns the request network protocol ("http", "https" ...).
Returns:
the request network protocol in lowercase letters.

getHttpProtocol

public java.lang.String getHttpProtocol()
Returns the HTTP protocol version ("HTTP/1.0", "HTTP/1.1" ...) of the agent (browser).
Returns:
HTTP protocol version in UPPERCASE

getUserAgent

public java.lang.String getUserAgent()
Returns the browser product name and version (if any).
Returns:
the browser product name and version or null, if no such information has been transfered from the browser

setUserAgent

public void setUserAgent(java.lang.String userAgent)
Allows to set a new browser product name and version. Used in filters.

Updates also the HTTP header.

Parameters:
userAgent - the new browser product name and version
See Also:
getUserAgent(), HttpdFilter

getVirtualHost

public java.lang.String getVirtualHost()
Returns the name of the TCP/IP host (server) to which the agent (browser) has made the request.
Returns:
the name of the TCP/IP host to which the agent (browser) has made the request or null, if no such information has been transferred from the browser
See Also:
getVirtualPort(), HttpdProperties.getServerName()

setVirtualHost

public void setVirtualHost(java.lang.String hostname)
Allows to set a new name of the TCP/IP host (server) to which the agent (browser) has made the request. Used in filters.

Updates also the HTTP header.

Parameters:
hostname - the new name of the TCP/IP host (server) to which the agent (browser) has made the request.
See Also:
getVirtualHost(), setVirtualPort(int), HttpdFilter

getVirtualPort

public int getVirtualPort()
Returns the non-standard server port number to which the agent (browser) has made the request. If the agent has made a request to the standard HTTP port 80, this method returns -1. It returns also -1 if no such information has been transferred from the browser.
Returns:
the non-standard TCP/IP port number or -1
See Also:
getVirtualHost(), HttpdProperties.getServerPort()

setVirtualPort

public void setVirtualPort(int port)
Allows to set a non-standard server port number to which the agent (browser) has made the request. Used in Filters. Updates also the HTTP header if a virtual hostname has already been set
Parameters:
port - the non-standard TCP/IP port number
See Also:
getVirtualPort(), setVirtualHost(java.lang.String), HttpdFilter

getContentType

public java.lang.String getContentType()
Returns the MIME type of the request content data, if this information has been set by the agent (browser).

Returns:
MIME type of the request content data in UPPERCASE or null, if no such information has been set by the agent (browser)
See Also:
getContentSubtype(), getContent()

setContentType

public void setContentType(java.lang.String contentType)
Allows to set a new MIME type of the request content data. Used in filters.

Updates also the HTTP header.

Parameters:
contentType - the new MIME type of the request content data
See Also:
setContentSubtype(java.lang.String), HttpdFilter

getContentSubtype

public java.lang.String getContentSubtype()
Returns the MIME subtype of the request content data, if this information has been set by the agent (browser).
Returns:
MIME subtype of the request content data or null, if no such information has been set by the agent (browser)
See Also:
getContentType()

setContentSubtype

public void setContentSubtype(java.lang.String contentSubtype)
Allows to set a new MIME subtype of the request content data. Used in filters.

Updates also the HTTP header.

Parameters:
contentSubtype - the new MIME subtype of the request content data. By passing null as argument value, the subtype will be deleted.
See Also:
setContentType(java.lang.String), HttpdFilter

getContent

public byte[] getContent()
Returns the content data of the request. Consider that the HTTP request method "GET" never transfer a request content. If the HTTP request method is "POST" there will be in the most cases request content data transfered.
Returns:
the HTTP request content data or null, if no request content data has been transferred.
See Also:
getParameterNames(), getParameter(java.lang.String)

setContent

public void setContent(byte[] content)
Allows to change the request content data. Used in filters.

This also changeds the "Content-Length" field inside the HTTP request header to the new, correct value. Additionaly all GET and POST parameters are first deleted and afterwards recalculated, based on the new content: this means also all GET CGI-Parameters are lost.

Parameters:
content - the new content data
See Also:
HttpdFilter

clearContent

public void clearContent()
Allows to remove the request content data. Used in filters.

The "Content-Length" field inside the HTTP request header will also be removed and all GET and POST parameters are deleted.

See Also:
HttpdFilter

getQueryString

public java.lang.String getQueryString()
Deprecated. Better use getParameterNames() and getParameter()

Returns all request parameter names and values. If the HTTP request type is "GET", this method will return the CGI parameters. IF the HTTP request type is "POST", the request content data will be returned.
Returns:
all request parameter names and values or null, if no such data are available.
See Also:
getParameterNames(), getParameter(java.lang.String)

getRequestPath

public java.lang.String getRequestPath()
Returns the path to the request file (without the request file itself). If there is no path because a file has been requested on the top of the CLASSPATH, an empty string will be returned.
Returns:
the path to the request file or an empty string, if no path is available.
See Also:
getRequestFile(), getRequest()

getRequestFile

public java.lang.String getRequestFile()
Returns the request file without any path. Does not include the (optional) CGI parameters.
Returns:
the request file without any path
See Also:
getRequestPath(), getRequest()

getRequest

public java.lang.String getRequest()
Returns the request file with the full path, but does not include the (optional) CGI parameters.
Returns:
the request file with the full path
See Also:
getRequestPath(), getRequestFile()

setRequest

public void setRequest(java.lang.String requestFile)
Allows to set a new request file which must include also the full path, but without (optional) CGI parameters. Used in filters.

This method automatically changes also the results of getRequestPath() and getRequestFile().

Parameters:
requestFile - the new request file with its full path.
See Also:
getRequest(), getRequestPath(), getRequestFile(), HttpdFilter

getParameterNames

public java.lang.String[] getParameterNames()
Returns a list of all names of the request parameters, nevertheless if there is a "GET" or a "POST" request.
Returns:
a list of all names of the request parameters. If there are no request parameters available, an empty string[] array is returned.
See Also:
getParameter(String), getParameter(String, boolean), getParameterString(java.lang.String), getParameterAsInt(java.lang.String)

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String parameterName)
Returns all values of one request parameter name. This method is useful if more than one parameter with the same name has been transferred.
Parameters:
parameterName - the name of the request parameter (case insensitive)
Returns:
a list of all values of the parameter name, or null if no such parameter name is available.

getParameter

public java.lang.String getParameter(java.lang.String parameterName)
Returns the value of a request parameter.
Parameters:
parameterName - the name of the request parameter (case insensitive)
Returns:
the value of the request parameter or null, if there is no such parameter available.
See Also:
getParameter(String, boolean), getParameterString(java.lang.String), getParameterAsInt(java.lang.String), getParameterNames()

getParameter

public java.lang.String getParameter(java.lang.String parameterName,
                                     boolean asRawValue)
Returns the value of a request parameter.
Parameters:
parameterName - the name of the request parameter (case insensitive)
asRawValue - if true, don't decode the value from the MIME "x-www-form-urlencoded" format
Returns:
the value of the request parameter or null, if there is no such parameter available.
See Also:
getParameter(String), getParameterString(java.lang.String), getParameterAsInt(java.lang.String), getParameterNames()

getParameterString

public java.lang.String getParameterString(java.lang.String parameterName)
Returns the value of a request parameter or an empty string, if no such parameter is available.
Parameters:
parameterName - the name of the request parameter (case insensitive)
Returns:
the value of the request parameter or an empty string, if no such parameter is available.
See Also:
getParameter(String), getParameter(String, boolean), getParameterAsInt(java.lang.String), getParameterNames()

getParameterAsInt

public int getParameterAsInt(java.lang.String parameterName)
Returns the value of a request parameter as int number.
Parameters:
parameterName - the name of the request parameter (case insensitive)
Returns:
the value of the request parameter as int number or -1, if there is no such parameter available - or also -1, if the parameter value can't be converted to an int number.
See Also:
getParameterAsLong(java.lang.String), getParameter(String), getParameter(String, boolean), getParameterString(java.lang.String), getParameterNames()

getParameterAsLong

public long getParameterAsLong(java.lang.String parameterName)
Returns the value of a request parameter as long number.
Parameters:
parameterName - the name of the request parameter (case insensitive)
Returns:
the value of the request parameter as long number or -1, if there is no such parameter available - or also -1, if the parameter value can't be converted to an long number.
See Also:
getParameterAsInt(java.lang.String), getParameter(String), getParameter(String, boolean), getParameterString(java.lang.String), getParameterNames()

addParameter

public void addParameter(java.lang.String parameterName,
                         java.lang.String parameterValue)
Allows to add an additional parameter to the HTTP request. Used in filters.

Does not update the content data and doesn't correct the CGI parameters delivered by the deprecated methods getQueryString() and getURI().

Parameters:
parameterName - the new parameter name to add
parameterValue - the new parameter value to add
See Also:
setContent(byte[]), HttpdFilter

updateParameter

public void updateParameter(java.lang.String parameterName,
                            java.lang.String parameterValue)
Allows to replace a parameter of the HTTP request. Used in filters.

If the parameter does not alreay exist, it will be added by calling addParameter() Does not update the content data and doesn't correct the CGI parameters delivered by the deprecated methods getQueryString() and getURI().

Parameters:
parameterName - the parameter name whose value should be modified (case insensitive)
parameterValue - the new value of the parameter
See Also:
setContent(byte[]), HttpdFilter

removeParameter

public void removeParameter(java.lang.String parameterName)
Removes a parameter from the HTTP request. Used in filters.

If the parameter name was not found, this method still completes sucessful. Does not modify the content data and doesn't correct the CGI parameters delivered by the deprecated methods getQueryString() and getURI().

Parameters:
parameterName - the parameter name to remove (case insensitive)
See Also:
setContent(byte[]), HttpdFilter

getUploadFile

public HttpUploadFile getUploadFile(java.lang.String parameterName)
Returns an uploaded file with its data, selected by the HTML parameter name.
Parameters:
parameterName - HTML parameter name
Returns:
uploaded file or null, if no file has been uploaded with this HTML parameter name.
See Also:
getUploadFiles()

getUploadFiles

public HttpUploadFile[] getUploadFiles()
Returns all uploaded files.
Returns:
uploaded files or an empty array, if no files have been uploaded. The return value will never be null.
See Also:
getUploadFile(java.lang.String)

hasBasicAuthorization

public boolean hasBasicAuthorization()
Checks if a base64 (basic) authorization has been set by the agent (browser). This is typically the agent reaction to a "401 Authorization Required" web server response.
Returns:
true, if the HTTP request contains a base64 (basic) authorization
See Also:
getBasicAuthorizationUsername(), getBasicAuthorizationPassword()

getBasicAuthorizationUsername

public java.lang.String getBasicAuthorizationUsername()
Returns the (basic) authorization username, which has been set by the agent (browser). This is typically the agent reaction to a "401 Authorization Required" web server response.
Returns:
the (basic) authorization username or null, if no authorization username has been set.
See Also:
getBasicAuthorizationPassword(), hasBasicAuthorization()

getBasicAuthorizationPassword

public java.lang.String getBasicAuthorizationPassword()
Returns the (basic) authorization password, which has been set by the agent (browser). This is typically the agent reaction to a "401 Authorization Required" web server response.
Returns:
the (basic) authorization password or null, if no authorization password has been set.
See Also:
getBasicAuthorizationUsername(), hasBasicAuthorization()

dump

public void dump()
Dumps the HTTP request header and the request content to the log output. Or - if the log output has been disabled - to System.out. Commonly used to debug HTTP requests. All non printable ASCII characters and also all characters greater than 126(decimal) of the request content are shown as "[<char-number>(decimal)]"
See Also:
Httpd.setLogStream(java.io.PrintStream)

Femto Web Server V1.4-F

Copyright 2002, 2003, 2006 by Ingenieurbüro David Fischer GmbH, Switzerland. All rights reserved.