net.sf.bvalid.util
Class WebClient

java.lang.Object
  extended by net.sf.bvalid.util.WebClient

public class WebClient
extends java.lang.Object

A general-purpose, connection-pooling HTTP Client. All methods are thread-safe. Provides option for client to handle HTTP redirects


Field Summary
 boolean FOLLOW_REDIRECTS
          Whether to automatically follow HTTP redirects.
 int MAX_CONNECTIONS_PER_HOST
          Maxiumum http connections per host
 int MAX_REDIRECTS
          Maximum number of redirects to follow per request if FOLLOW_REDIRECTS is true.
 int MAX_TOTAL_CONNECTIONS
          Maxiumum total http connections
 int SOCKET_TIMEOUT_SECONDS
          Seconds to wait while waiting for data over the socket (SO_TIMEOUT).
 int TIMEOUT_SECONDS
          Seconds to wait before a connection is established.
 java.lang.String USER_AGENT
          What the "User-Agent" request header should say.
 
Constructor Summary
WebClient()
           
 
Method Summary
 HttpInputStream get(java.lang.String url, boolean failIfNotOK)
           
 HttpInputStream get(java.lang.String url, boolean failIfNotOK, java.lang.String user, java.lang.String pass)
           
 HttpInputStream get(java.lang.String url, boolean failIfNotOK, org.apache.commons.httpclient.UsernamePasswordCredentials creds)
          Get an HTTP resource with the response as an InputStream, given a URL.
 org.apache.commons.httpclient.HttpClient getHttpClient()
           
 org.apache.commons.httpclient.HttpClient getHttpClient(java.lang.String hostOrURL, org.apache.commons.httpclient.UsernamePasswordCredentials creds)
           
 java.lang.String getResponseAsString(java.lang.String url, boolean failIfNotOK)
           
 java.lang.String getResponseAsString(java.lang.String url, boolean failIfNotOK, org.apache.commons.httpclient.UsernamePasswordCredentials creds)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT_SECONDS

public int TIMEOUT_SECONDS
Seconds to wait before a connection is established.


SOCKET_TIMEOUT_SECONDS

public int SOCKET_TIMEOUT_SECONDS
Seconds to wait while waiting for data over the socket (SO_TIMEOUT).


MAX_CONNECTIONS_PER_HOST

public int MAX_CONNECTIONS_PER_HOST
Maxiumum http connections per host


MAX_TOTAL_CONNECTIONS

public int MAX_TOTAL_CONNECTIONS
Maxiumum total http connections


FOLLOW_REDIRECTS

public boolean FOLLOW_REDIRECTS
Whether to automatically follow HTTP redirects.


MAX_REDIRECTS

public int MAX_REDIRECTS
Maximum number of redirects to follow per request if FOLLOW_REDIRECTS is true.


USER_AGENT

public java.lang.String USER_AGENT
What the "User-Agent" request header should say. Default is null, which indicates that the header should not be provided.

Constructor Detail

WebClient

public WebClient()
Method Detail

getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient()
                                                       throws java.io.IOException
Throws:
java.io.IOException

getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient(java.lang.String hostOrURL,
                                                              org.apache.commons.httpclient.UsernamePasswordCredentials creds)
                                                       throws java.io.IOException
Throws:
java.io.IOException

get

public HttpInputStream get(java.lang.String url,
                           boolean failIfNotOK)
                    throws java.io.IOException
Throws:
java.io.IOException

get

public HttpInputStream get(java.lang.String url,
                           boolean failIfNotOK,
                           java.lang.String user,
                           java.lang.String pass)
                    throws java.io.IOException
Throws:
java.io.IOException

get

public HttpInputStream get(java.lang.String url,
                           boolean failIfNotOK,
                           org.apache.commons.httpclient.UsernamePasswordCredentials creds)
                    throws java.io.IOException
Get an HTTP resource with the response as an InputStream, given a URL. If FOLLOW_REDIRECTS is true, up to MAX_REDIRECTS redirects will be followed. Note that if credentials are provided, for security reasons they will only be provided to the FIRST url in a chain of redirects. Note that if the HTTP response has no body, the InputStream will be empty. The success of a request can be checked with getResponseCode(). Usually you'll want to see a 200. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for other codes.

Parameters:
url - A URL that we want to do an HTTP GET upon
failIfNotOK - boolean value indicating if an exception should be thrown if we do NOT receive an HTTP 200 response (OK)
Returns:
HttpInputStream the HTTP response
Throws:
java.io.IOException

getResponseAsString

public java.lang.String getResponseAsString(java.lang.String url,
                                            boolean failIfNotOK)
                                     throws java.io.IOException
Throws:
java.io.IOException

getResponseAsString

public java.lang.String getResponseAsString(java.lang.String url,
                                            boolean failIfNotOK,
                                            org.apache.commons.httpclient.UsernamePasswordCredentials creds)
                                     throws java.io.IOException
Throws:
java.io.IOException