|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.enhydra.barracuda.core.util.http.HttpRequester
This class encapsulates access to/from a URL via both POST and GET methods. To use, simply set the URL, the method (POST/GET), and the params. If you're using get, the params are optional (they can be included as part of the URL). Also note that you can pass a username and password if you need to do basic authentication Refer to the source for this class (main method) to see an example of how you would use this class for both POST and GET methods:
Field Summary | |
protected boolean |
authenticate
|
static java.lang.String |
GET
|
protected java.io.BufferedReader |
in
|
protected java.io.InputStream |
inStream
|
protected java.lang.String |
method
|
protected HttpOutputWriter |
outputWriter
|
protected java.io.OutputStream |
outStream
|
protected java.lang.String |
password
|
static java.lang.String |
POST
|
protected java.util.Map |
props
|
protected java.net.URL |
url
|
protected java.lang.String |
user
|
Constructor Summary | |
HttpRequester()
|
Method Summary | |
void |
connect()
Connect to the URL |
void |
disconnect()
Disconnect from the URL. |
java.io.InputStream |
getInputStream()
Get the underlying input stream |
java.lang.String |
getMethod()
Get the method we're using for this HttpRequest object |
java.io.OutputStream |
getOutputStream()
Get the underlying output stream |
HttpOutputWriter |
getOutputWriter()
Return the output writer. |
java.util.Map |
getParams()
Return the HashMap object for this HttpRequest. |
protected java.lang.String |
getPassword()
Get the password |
java.net.URL |
getUrl()
Get the URL for the HttpRequest object |
java.lang.String |
getUser()
Get the user name |
static void |
main(java.lang.String[] args)
|
java.lang.String |
readLine()
Read responses from the URL |
void |
setMethod(java.lang.String imethod)
Set the method we wish to use. |
void |
setOutputWriter(HttpOutputWriter ioutputWriter)
Set the output writer to be used for posting data |
void |
setParams(java.util.Map iprops)
Set the parmeters we wish to pass to the URL as name-value pairs. |
void |
setPassword(java.lang.String ipassword)
Set the password (if we need to authenticate in order to make the connection) |
void |
setRequest(java.lang.String iurl,
java.lang.String imethod,
java.util.Map iprops)
Set the Request. |
void |
setRequest(java.lang.String iurl,
java.lang.String imethod,
java.util.Map iprops,
HttpOutputWriter ioutputWriter)
Set the Request. |
void |
setRequest(java.lang.String iurl,
java.lang.String imethod,
java.util.Map iprops,
java.lang.String iuser,
java.lang.String ipwd,
HttpOutputWriter ioutputWriter)
Set the Request. |
void |
setRequest(java.net.URL iurl,
java.lang.String imethod,
java.util.Map iprops)
Set the Request. |
void |
setRequest(java.net.URL iurl,
java.lang.String imethod,
java.util.Map iprops,
HttpOutputWriter ioutputWriter)
Set the Request. |
void |
setRequest(java.net.URL iurl,
java.lang.String imethod,
java.util.Map iprops,
java.lang.String iuser,
java.lang.String ipwd,
HttpOutputWriter ioutputWriter)
Set the Request. |
void |
setUrl(java.lang.String iurl)
Set the URL we wish to access |
void |
setUrl(java.net.URL iurl)
Set the URL we wish to access |
void |
setUser(java.lang.String iuser)
Set the user (if we need to authenticate in order to make the connection) |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String POST
public static final java.lang.String GET
protected java.net.URL url
protected java.lang.String method
protected java.util.Map props
protected HttpOutputWriter outputWriter
protected java.lang.String user
protected java.lang.String password
protected boolean authenticate
protected java.io.OutputStream outStream
protected java.io.InputStream inStream
protected java.io.BufferedReader in
Constructor Detail |
public HttpRequester()
Method Detail |
public void setRequest(java.lang.String iurl, java.lang.String imethod, java.util.Map iprops) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setRequest(java.net.URL iurl, java.lang.String imethod, java.util.Map iprops) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setRequest(java.lang.String iurl, java.lang.String imethod, java.util.Map iprops, HttpOutputWriter ioutputWriter) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setRequest(java.net.URL iurl, java.lang.String imethod, java.util.Map iprops, HttpOutputWriter ioutputWriter) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setRequest(java.lang.String iurl, java.lang.String imethod, java.util.Map iprops, java.lang.String iuser, java.lang.String ipwd, HttpOutputWriter ioutputWriter) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setRequest(java.net.URL iurl, java.lang.String imethod, java.util.Map iprops, java.lang.String iuser, java.lang.String ipwd, HttpOutputWriter ioutputWriter) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setUrl(java.lang.String iurl) throws java.net.MalformedURLException
java.net.MalformedURLException
public void setUrl(java.net.URL iurl)
public java.net.URL getUrl()
public void setMethod(java.lang.String imethod)
public java.lang.String getMethod()
public void setParams(java.util.Map iprops)
public java.util.Map getParams()
public void setUser(java.lang.String iuser)
public java.lang.String getUser()
public void setPassword(java.lang.String ipassword)
protected java.lang.String getPassword()
public void setOutputWriter(HttpOutputWriter ioutputWriter)
ioutputWriter
- the HttpOutputWriterpublic HttpOutputWriter getOutputWriter()
public void connect() throws java.net.ConnectException, java.io.IOException
java.net.ConnectException
java.io.IOException
public java.lang.String readLine() throws java.net.ConnectException, java.io.IOException
java.net.ConnectException
java.io.IOException
public java.io.OutputStream getOutputStream() throws java.net.ConnectException
java.net.ConnectException
public java.io.InputStream getInputStream() throws java.net.ConnectException
java.net.ConnectException
public void disconnect()
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |