|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bowstreet.util.HTTPRequest
public class HTTPRequest
API for calling out to a specified URL
Field Summary | |
---|---|
static int |
DELETE_REQUEST
Indicator for setRequestType . |
static int |
GET_REQUEST
Indicator for setRequestType . |
static int |
POST_REQUEST
Indicator for setRequestType . |
static int |
PUT_REQUEST
Indicator for setRequestType . |
static java.lang.String |
ROOT_TAG
This is the root level tag we place around the HTTP response. |
Constructor Summary | |
---|---|
HTTPRequest()
|
Method Summary | |
---|---|
void |
addCookie(java.lang.String cookie)
Add a cookie to be sent. |
void |
addParam(java.lang.String name,
IXml value)
Add an IXml parameter to the request to be sent. |
void |
addParam(java.lang.String name,
java.lang.String value)
Add a String parameter to the request to be sent. |
static void |
callMethod(java.lang.reflect.Method method,
java.lang.Object instance,
int value)
Calls the specified method using reflection. |
void |
clear()
Clears out and initializes the HTTPRequest object so it can be safely reused in another request, thereby avoiding the need to instantiate another HTTPRequest object. |
java.lang.String |
getBodyContentType()
Gets the HTTP Body content type. |
static java.lang.reflect.Method |
getConnectTimeoutMethod()
Gets the setConnectTimeout Method on the HttpURLConnection if Java 1.5 or higher. |
java.util.Vector |
getCookies()
Get the cookies that were sent back in the reply. |
java.lang.String |
getEncoding()
Get the encoding of the response stream |
java.util.HashMap |
getHeaders()
Retrieve the Headers that were sent back in the reply. |
static java.lang.String |
getHTTPOperationString(int requestType)
Gets the HTTP Operation String for the specified request type. |
static int |
getHTTPOperationType(java.lang.String operationType)
Gets the HTTP request type for the specified operation String. |
static java.lang.reflect.Method |
getMethod(java.lang.Class sourceClass,
java.lang.String name)
Gets the method from the class for the specified name. |
java.lang.String |
getMimeType()
Return the MIME type of the response. |
java.lang.String |
getProxyHost()
|
java.lang.String |
getProxyPassword()
|
int |
getProxyPort()
|
java.lang.String |
getProxyUser()
|
static java.lang.reflect.Method |
getReadTimeoutMethod()
Gets the setReadTimeout Method on the HttpURLConnection if Java 1.5 or higher. |
int |
getResponseCode()
|
java.lang.String |
getResponseError()
|
java.lang.String |
getResponseMessage()
Gets the HTTP response message from the server. |
IXml |
invoke()
Issues the HTTP request based on values set in the HTTPRequest object. |
static void |
main(java.lang.String[] args)
|
void |
overrideHost(java.lang.String host)
Overrides the hostname in the target URL. |
void |
overridePort(java.lang.String port)
Overrides the port in the target URL. |
void |
setBodyContent(java.lang.Object o)
Passing this method a String or IXml argument will set it as the body content to be sent if the submission style is POST. |
void |
setBodyContentType(java.lang.String bodyContentType)
Sets the HTTP Body content type used when performing a POST or PUT. |
void |
setContentType(java.lang.String s)
Optional, override the content type of the response. |
void |
setDoStats(boolean b)
Enable/disable the internal stats (timing) logging around the invoke . |
void |
setEncoding(java.lang.String encoding)
Set the encoding (eg, "iso-8859-1") to be used to read the response. |
void |
setFollowRedirect(boolean b)
Allows connection to follow HTTP redirect. |
void |
setHeader(java.lang.String name,
java.lang.String value)
Set a HTTP header to be sent. |
void |
setHttpURLConnectionFactory(com.bowstreet.util.HttpURLConnectionFactory httpURLConnectionFactory)
|
void |
setLogRequest(boolean b)
Sets an indicator to enable/disable logging of the request and response. |
void |
setOutputStreamEncoding(java.lang.String encoding)
Set the encoding (eg, "UTF-8") to be used to send POST content. |
void |
setParseAll(boolean b)
Enables/Disables parsing of all tags in the document response. |
void |
setPassword(java.lang.String password)
Set the password for HTTP Basic Auth. |
void |
setProxyHost(java.lang.String proxyHost)
|
void |
setProxyPassword(java.lang.String proxyPassword)
|
void |
setProxyPort(java.lang.String proxyPort)
|
void |
setProxyUser(java.lang.String proxyUser)
|
void |
setRequestType(int type)
Specify the request type as HTTP GET or POST. |
void |
setTimeout(int nSecs)
Set a timeout value for the request. |
void |
setTimeout(java.lang.String nSecs)
Set a timeout value for the request. |
void |
setURL(java.net.URL url)
Sets the target URL for the HTTP request. |
void |
setUsername(java.lang.String username)
Username for HTTP Basic Auth. |
void |
setWebAppAccess(WebAppAccess webAppAccess)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DELETE_REQUEST
setRequestType
. Sets up the
invoke
to be a HTTP DELETE.
public static final int GET_REQUEST
setRequestType
. Sets up the
invoke
to be a HTTP GET. This is the default for
a new or cleared
HTTPRequest object.
public static final int POST_REQUEST
setRequestType
. Sets up the
invoke
to be a HTTP POST.
public static final int PUT_REQUEST
setRequestType
. Sets up the
invoke
to be a HTTP PUT.
public static final java.lang.String ROOT_TAG
Constructor Detail |
---|
public HTTPRequest()
Method Detail |
---|
public void addCookie(java.lang.String cookie)
cookie
- the cookie to be addedpublic void addParam(java.lang.String name, IXml value)
name
- name of the argvalue
- value of the argpublic void addParam(java.lang.String name, java.lang.String value)
name
- name of the argvalue
- value of the argpublic static void callMethod(java.lang.reflect.Method method, java.lang.Object instance, int value)
method
- The class Method to call.instance
- The class instance to call the method on.value
- The value to pass the method.public void clear()
public java.lang.String getBodyContentType()
public static java.lang.reflect.Method getConnectTimeoutMethod()
public java.util.Vector getCookies()
public java.lang.String getEncoding()
public java.util.HashMap getHeaders()
public static final java.lang.String getHTTPOperationString(int requestType)
requestType
- The HTTP request type (GET_REQUEST, PUT_REQUEST, DELETE_REQUEST, POST_REQUEST)
public static final int getHTTPOperationType(java.lang.String operationType)
operationType
- The HTTP operation ("GET", "PUT", "DELETE", "POST")
public static java.lang.reflect.Method getMethod(java.lang.Class sourceClass, java.lang.String name)
sourceClass
- The class to get the method from.name
- The name of the method.
public java.lang.String getMimeType()
public java.lang.String getProxyHost()
public java.lang.String getProxyPassword()
public int getProxyPort()
public java.lang.String getProxyUser()
public static java.lang.reflect.Method getReadTimeoutMethod()
public int getResponseCode()
public java.lang.String getResponseError()
public java.lang.String getResponseMessage()
public IXml invoke() throws java.net.UnknownHostException, java.io.IOException, com.bowstreet.util.parser.ParserException
HTTPRequest h = new HTTPRequest();
h.setURL(new URL("http://homie.codebump.com:8080/services/zipcodes/zipcodelookup.asmx/GetZipCodesWithin"));
h.setRequestType(HTTPRequest.GET_REQUEST);
h.addParam("zip", "03801");
h.addParam("distance", "10");
h.setTimeout(10);
IXml doc = h.invoke();
System.out.println("mime type =" + h.getMimeType());
if (doc != null)
System.out.println("htmlDoc = " + doc.toString());
java.net.UnknownHostException
- if the URL given is invalid
java.io.IOException
- if there's a communication error
com.bowstreet.util.parser.ParserException
- if the response could not be interpretedpublic static void main(java.lang.String[] args)
public void overrideHost(java.lang.String host)
http.setURL(new URL("http://www.xmethods.net/aservice/s.asmx"));
http.overrideHost("localhost");
http.overridePort("9090");
IXml x = http.invoke();
host
- the hostname, eg, www.xmethods.net, or localhostpublic void overridePort(java.lang.String port)
overrideHost
and setURL
.
port
- the port number, eg 9090public void setBodyContent(java.lang.Object o)
o
- the String or IXml data that is to be sent in the Body of the HTTP POSTpublic void setBodyContentType(java.lang.String bodyContentType)
bodyContentType
- The HTTP Body content type to set (e.g. application/atom+xml)public void setContentType(java.lang.String s)
s
- a valid content type string, eg "text/xml"public void setDoStats(boolean b)
invoke
. Default is false
(disabled).
b
- true/false to enable/disable tracingpublic void setEncoding(java.lang.String encoding)
encoding
- stringpublic void setFollowRedirect(boolean b)
b
- boolean to enable/disablepublic void setHeader(java.lang.String name, java.lang.String value)
name
- name of the HTTP headervalue
- value of the HTTP headerpublic void setHttpURLConnectionFactory(com.bowstreet.util.HttpURLConnectionFactory httpURLConnectionFactory)
httpURLConnectionFactory
- the httpURLConnectionFactory to setpublic void setLogRequest(boolean b)
b
- true/false indicator to enable/disable logging of request and
response.public void setOutputStreamEncoding(java.lang.String encoding)
encoding
- desired encoding, eg "iso-8859-1"public void setParseAll(boolean b)
b
- boolean to enable/disable all tag parsingpublic void setPassword(java.lang.String password)
password
- passwordpublic void setProxyHost(java.lang.String proxyHost)
proxyHost
- the proxyHost to setpublic void setProxyPassword(java.lang.String proxyPassword)
proxyPassword
- the proxyPassword to setpublic void setProxyPort(java.lang.String proxyPort)
proxyPort
- the proxyPort to setpublic void setProxyUser(java.lang.String proxyUser)
proxyUser
- the proxyUser to setpublic void setRequestType(int type)
type
- Must be either GET_REQUEST
or POST_REQUEST
as defined in this class.public void setTimeout(int nSecs)
nSecs
- timeout value in secondspublic void setTimeout(java.lang.String nSecs)
nSecs
- timeout value string in secondspublic void setURL(java.net.URL url)
overrideHost
and
overridePort
can be subsequently used to
override those components of the URL (eg, for redirecting via TcpTunnel).
url
- the target URL (endpoint URL) of the HTTP requestpublic void setUsername(java.lang.String username)
username
- usernamepublic void setWebAppAccess(WebAppAccess webAppAccess)
servletRequest
- the servletRequest to set
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |