|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectwinterwell.jtwitter.URLConnectionHttpClient
public class URLConnectionHttpClient
A simple http client that uses the built in URLConnection class.
Provides Twitter-focused error-handling, generating the right
TwitterException.
Also has a retry-on-error mode which can help smooth out Twitter's
sometimes intermittent service. See setRetryOnError(boolean).
| Field Summary | |
|---|---|
protected java.lang.String |
name
|
protected int |
timeout
|
| Constructor Summary | |
|---|---|
URLConnectionHttpClient()
|
|
URLConnectionHttpClient(java.lang.String name,
java.lang.String password)
|
|
| Method Summary | |
|---|---|
boolean |
canAuthenticate()
Whether this client is setup to do authentication when contacting the Twitter server. |
protected static void |
close(java.io.Closeable input)
Close a reader/writer/stream, ignoring any exceptions that result. |
java.lang.String |
getPage(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean authenticate)
Send an HTTP GET request and return the response body. |
java.lang.String |
post(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean authenticate)
Send an HTTP POST request and return the response body. |
protected java.lang.String |
post2_getPayload(java.util.Map<java.lang.String,java.lang.String> vars)
|
protected void |
setAuthentication(java.net.URLConnection connection,
java.lang.String name,
java.lang.String password)
Set a header for basic authentication login. |
void |
setRetryOnError(boolean retryOnError)
False by default. |
void |
setTimeout(int millisecs)
Set the timeout for a single get/post request. |
java.lang.String |
toString()
|
protected static java.lang.String |
toString(java.io.InputStream inputStream)
Use a bufferred reader (preferably UTF-8) to extract the contents of the given stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String name
protected int timeout
| Constructor Detail |
|---|
public URLConnectionHttpClient(java.lang.String name,
java.lang.String password)
public URLConnectionHttpClient()
| Method Detail |
|---|
public boolean canAuthenticate()
Twitter.IHttpClientTwitterAccount.verifyCredentials() if you need to check a
login.
canAuthenticate in interface Twitter.IHttpClientpublic void setTimeout(int millisecs)
Twitter.IHttpClient
setTimeout in interface Twitter.IHttpClient
public java.lang.String getPage(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean authenticate)
throws TwitterException
Twitter.IHttpClient
getPage in interface Twitter.IHttpClienturi - The uri to fetchvars - get arguments to add to the uriauthenticate - If true, use authentication. The authentication method
used depends on the implementation (basic-auth, OAuth). It
is an error to use true if no authentication details have
been set.
TwitterException - for a variety of reasons
TwitterException.E404 - for resource-does-not-exist errorspublic java.lang.String toString()
toString in class java.lang.Object
protected void setAuthentication(java.net.URLConnection connection,
java.lang.String name,
java.lang.String password)
public java.lang.String post(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean authenticate)
throws TwitterException
Twitter.IHttpClient
post in interface Twitter.IHttpClienturi - The uri to post to.vars - The form variables to send. These are URL encoded before
sending.authenticate - If true, send user authentication
TwitterException - for a variety of reasons
TwitterException.E404 - for resource-does-not-exist errorsprotected java.lang.String post2_getPayload(java.util.Map<java.lang.String,java.lang.String> vars)
public void setRetryOnError(boolean retryOnError)
protected static java.lang.String toString(java.io.InputStream inputStream)
toString(Reader).
protected static void close(java.io.Closeable input)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||