|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ferris.net.runner.HttpRequestRunner<M>
public class HttpRequestRunner<M>
This class makes it easier to make a GET or POST call to a URL, pass request parameters, and process the results which come back. An instance of this class can be used to make multiple requests to the server and the cookies for the server are automatically manged. This is especially useful if some sort of session cookie must be generated or a non-HTTP BASIC authentication login must be performed before making the request.
Field Summary | |
---|---|
static org.apache.http.auth.AuthScope |
proxyAuthScope
|
static org.apache.http.auth.Credentials |
proxyCredentials
|
Constructor Summary | |
---|---|
HttpRequestRunner(org.apache.http.auth.AuthScope authScope)
This constructor is used if the HTTP resource is NOT protected by BASIC authentication. |
|
HttpRequestRunner(org.apache.http.auth.AuthScope authScope,
org.apache.http.auth.UsernamePasswordCredentials credentials)
This constructor is used if the HTTP resource IS protected by BASIC authentication. |
Method Summary | |
---|---|
void |
addCookie(String name,
String content,
String domain,
String path)
Add the cookie to the request. |
void |
addParameter(File parameter)
Add the File value of a request parameter |
void |
addParameter(String parameter)
Add the String value of a request parameter and URLEncoder is automatically used to make sure special characters are escaped properly. |
void |
addParameters(File[] parameters)
|
void |
addParameters(String[] parameters)
|
List<M> |
get(String request,
HttpResponseHandler<M> handler)
Make the HTTP request using GET |
String |
getCookiePolicy()
Get the cookie policy, if none is set the default is CookiePolicy.RFC_2109 |
protected String |
getHost()
The "localhost" of the URL "http://localhost:8080/some/path/search.php". |
protected int |
getPort()
The "8080" of the URL "http://localhost:8080/some/path/search.php". |
protected String |
getScheme()
The "http" of the URL "http://localhost:8080/some/path/search.php". |
List<M> |
post(String request,
HttpResponseHandler<M> handler)
Make the HTTP request using POST |
void |
setCookiePolicy(String cookiePolicy)
Set the cookie policy using a value from CookiePolicy . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static org.apache.http.auth.AuthScope proxyAuthScope
public static org.apache.http.auth.Credentials proxyCredentials
Constructor Detail |
---|
public HttpRequestRunner(org.apache.http.auth.AuthScope authScope)
authScope
- public HttpRequestRunner(org.apache.http.auth.AuthScope authScope, org.apache.http.auth.UsernamePasswordCredentials credentials)
authScope
- Method Detail |
---|
protected String getScheme()
protected String getHost()
getAuthScope().getHost()
. Override this method
in sub-classes if needed.
protected int getPort()
getAuthScope().getPort()
if the
value is >= 0, otherwise returns -1. Override this
method in sub-classes if needed.
public void setCookiePolicy(String cookiePolicy)
CookiePolicy
.
cookiePolicy
- public String getCookiePolicy()
CookiePolicy.RFC_2109
public void addCookie(String name, String content, String domain, String path)
public void addParameter(String parameter)
public void addParameter(File parameter)
public void addParameters(String[] parameters)
addParameter(String)
public void addParameters(File[] parameters)
addParameter(File)
public List<M> get(String request, HttpResponseHandler<M> handler)
request
- - This value is something like:
/some/kind/of/path/to/resource.jsp?fname=?&lname=? It
must begin with a "/" character. The query parameters
are normal query parameters with the "?" character
in place of the actual value. This class will take
care of replacing and properly encoding the value
of the parameter before replacing the "?" character
with it.handler
- - What to do on each iteration of
the response.public List<M> post(String request, HttpResponseHandler<M> handler)
pathAndResource
- - This value is something like:
/some/kind/of/path/to/resource.jsp?fname=?&lname=? It
must begin with a "/" character. The query parameters
are normal query parameters with the "?" character
in place of the actual value. This class will take
care of replacing and properly encoding the value
of the parameter before replacing the "?" character
with it. If you call addParameter() with a File
object then the contents of the file will be posted
to the http server.handler
- - What to do on each iteration of
the response.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |