winterwell.jtwitter
Class URLConnectionHttpClient

java.lang.Object
  extended by winterwell.jtwitter.URLConnectionHttpClient
All Implemented Interfaces:
Twitter.IHttpClient

public class URLConnectionHttpClient
extends java.lang.Object
implements Twitter.IHttpClient

A simple http client that uses the built in URLConnection class.

Author:
Daniel Winterstein

Constructor Summary
URLConnectionHttpClient()
           
URLConnectionHttpClient(java.lang.String name, java.lang.String password)
           
 
Method Summary
 boolean canAuthenticate()
          Whether this client can authenticate to the server.
 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.
 void setRetryOnError(boolean retryOnError)
          False by default.
 void setTimeout(int millisecs)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URLConnectionHttpClient

public URLConnectionHttpClient()

URLConnectionHttpClient

public URLConnectionHttpClient(java.lang.String name,
                               java.lang.String password)
Method Detail

canAuthenticate

public boolean canAuthenticate()
Description copied from interface: Twitter.IHttpClient
Whether this client can authenticate to the server.

Specified by:
canAuthenticate in interface Twitter.IHttpClient

getPage

public java.lang.String getPage(java.lang.String uri,
                                java.util.Map<java.lang.String,java.lang.String> vars,
                                boolean authenticate)
                         throws TwitterException
Description copied from interface: Twitter.IHttpClient
Send an HTTP GET request and return the response body. Note that this will change all line breaks into system line breaks!

Specified by:
getPage in interface Twitter.IHttpClient
Parameters:
uri - The uri to fetch
vars - get arguments to add to the uri
authenticate - 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.
Throws:
TwitterException - for a variety of reasons
TwitterException.E404 - for resource-does-not-exist errors

post

public java.lang.String post(java.lang.String uri,
                             java.util.Map<java.lang.String,java.lang.String> vars,
                             boolean authenticate)
                      throws TwitterException
Description copied from interface: Twitter.IHttpClient
Send an HTTP POST request and return the response body.

Specified by:
post in interface Twitter.IHttpClient
Parameters:
uri - The uri to post to.
vars - The form variables to send. These are URL encoded before sending.
authenticate - If true, send user authentication
Returns:
The response from the server.
Throws:
TwitterException - for a variety of reasons
TwitterException.E404 - for resource-does-not-exist errors

setRetryOnError

public void setRetryOnError(boolean retryOnError)
False by default. Setting this to true switches on a robustness workaround: when presented with a 50X server error, the system will wait 1 second and make a second attempt.


setTimeout

public void setTimeout(int millisecs)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2014 gvSIG Association. All Rights Reserved.