|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.net.HTTP.Request
This class reads a request from a remote client and evaluate it so that the calling program can retrieve the different forms of information contained in the request. Information in a request includes the HTTP header, the request URL used, arguments, cookies and parameters.
Request request = new Request( socket); Header header = request.getHeader(); String accept = header.get( "Accept"); accept = request.getHeader( "Accept"); Properties parameters = request.getParameters(); int iv = parameters.get( "integerValue", 0); boolean bv = parameters.get( "booleanValue", false); if (request.parameterExists( "action")) action( request.getParameter( "action")); // To record a session request.startRecorder(); String tape = request.stopRecorder();
| Constructor Summary | |
Request()
|
|
| Method Summary | |
static String |
decode(String encoded)
Decode a string sent from the browser. |
boolean |
fetch()
Fetch and process a browser request from any source. |
boolean |
fetch(String requestString)
Called ny unit tests to create an artificial request from a string. |
String |
fullURL(String partial)
Given a partial URL, return a fully defined URL (http://server.com/path/url). |
String[] |
getArguments()
Return the query string with special characters processed and split into arguments. |
String |
getCookie(String key)
Get a cookie from the request. |
Header |
getHeader()
Retrieve a pointer to the header sent with this request. |
String |
getHeader(String key)
Retrieve an item from the HTTP header that came as part of the request. |
String |
getHeader(String key,
String defaultValue)
Retrieve an item from the HTTP header that came as part of the request - with a default if the item does not exist. |
String |
getMethod()
Get the method set in the header - usually GET or POST. |
String |
getParameter(String key)
Return the value for a single key. |
String |
getParameter(String key,
String defaultValue)
Return the value for a single key. |
String[] |
getParameterList(String key)
Return the values for a single key. |
Properties |
getParameters()
Divide up the arguments into key/value pairs (name=value&name=value). |
String |
getProtocol()
The protocol os HTTP/1.1 or HTTP/1.0. |
String |
getQueryString()
Retrieve the query string in raw form (with & between name=value pairs). |
String |
getReferer()
Return the page that referred this page. |
String |
getURL()
The URL retrieved is relative to the server root. |
boolean |
parameterExists(String key)
Confirm whether a particular parameter is in the request. |
void |
removeParameter(String key)
Remove a parameter from the list so that it will not show up on a subsequent search or list. |
void |
setQueryString(String queryString)
Set the query string - used to reset after unsuccessfully trying defaults like CGI? |
String |
setQueryString(String[] arguments)
encode and Set the query string given the individual arguments. |
String |
setQueryString(String[] arguments,
int startIndex)
encode and Set the query string given the individual arguments. |
void |
setReader(BufferedReader newReader)
Another data source raw reader (typically socket) |
void |
setReader(Reader newReader)
Another data source raw reader (typically socket) |
void |
setReader(Socket socket)
Before fetching request queries from the browser we will need to tell it which socket to use. |
void |
setReader(String requestString)
Junit tests often provide the request data in a string. |
void |
setURL(String url)
While looking for the file/class to run/serve on the local system we need to change the URL - usually to add bits (like /index.html). |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Request()
| Method Detail |
public boolean fetch()
throws IOException
IOExceptionpublic boolean fetch(String requestString)
requestString - contents of request for testing.
public String fullURL(String partial)
partial - may be relative (url.html), partial (/bin/url.cgi) or
absolute (http://localhost:1958/bin/url.cgi)
public String[] getArguments()
public static String decode(String encoded)
encoded - string from browser or other HTTP source.
public Header getHeader()
public String getHeader(String key)
key - for entry in request header.
public String getReferer()
public String getHeader(String key,
String defaultValue)
key - for entry in request header.defaultValue - if key not in header.
public String getMethod()
public String getParameter(String key)
key - for entry in request header.
parameterExists(String)
public String getParameter(String key,
String defaultValue)
key - for entry in request header.defaultValue - if key not in header.
parameterExists(String)public String[] getParameterList(String key)
key - for entry in request header.
public Properties getParameters()
public void removeParameter(String key)
key - Name of parameter to remove.public String getProtocol()
public String getQueryString()
public String getURL()
public boolean parameterExists(String key)
key - for entry in request header.
public void setQueryString(String queryString)
queryString - value to be set as query string.public String setQueryString(String[] arguments)
arguments - name=value pairs to become http arguments on command line.
public String setQueryString(String[] arguments,
int startIndex)
arguments - name=value pairs to become http arguments on command line.startIndex - the starting index in arguments (used to skip command if
1st in string)
public void setReader(BufferedReader newReader)
newReader - stack another data source (typically socket) to be read from.public void setReader(Reader newReader)
newReader - stack another data source (typically socket) to be read from.public void setReader(Socket socket)
socket - stack a socket data source to be read from.public void setReader(String requestString)
requestString - for testing.public void setURL(String url)
url - to update the URL that made the request.public String getCookie(String key)
key - cookie key.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||