com.googlecode.fascinator.common
Class BasicHttpClient

java.lang.Object
  extended by com.googlecode.fascinator.common.BasicHttpClient

public class BasicHttpClient
extends Object

Commons HttpClient wrapper that makes it easier to work with proxies and authentication

Author:
Oliver Lucido

Constructor Summary
BasicHttpClient(String baseUrl)
          Creates an HTTP client for the specified base URL.
 
Method Summary
 void authenticate(String username, String password)
          Sets the authentication credentials for authenticated requests
 int executeMethod(org.apache.commons.httpclient.HttpMethodBase method)
          Sends an HTTP request.
 int executeMethod(org.apache.commons.httpclient.HttpMethodBase method, boolean auth)
          Sends an HTTP request
 String getBaseUrl()
          Gets the base URL
 org.apache.commons.httpclient.HttpClient getHttpClient(boolean auth)
          Gets an HTTP client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicHttpClient

public BasicHttpClient(String baseUrl)
Creates an HTTP client for the specified base URL. The base URL is used in determining proxy usage.

Parameters:
baseUrl - the base URL
Method Detail

authenticate

public void authenticate(String username,
                         String password)
Sets the authentication credentials for authenticated requests

Parameters:
username - a username
password - a password

getHttpClient

public org.apache.commons.httpclient.HttpClient getHttpClient(boolean auth)
Gets an HTTP client. If authentication is required, the authenticate() method must be called prior to this method.

Parameters:
auth - set true to use authentication, false to skip authentication
Returns:
an HTTP client

getBaseUrl

public String getBaseUrl()
Gets the base URL

Returns:
the base URL

executeMethod

public int executeMethod(org.apache.commons.httpclient.HttpMethodBase method)
                  throws IOException
Sends an HTTP request. This method uses authentication for all requests except GET.

Parameters:
method - an HTTP method
Returns:
HTTP status code
Throws:
IOException - if an error occurred during the HTTP request

executeMethod

public int executeMethod(org.apache.commons.httpclient.HttpMethodBase method,
                         boolean auth)
                  throws IOException
Sends an HTTP request

Parameters:
method - an HTTP method
auth - true to request with authentication, false to request without
Returns:
HTTP status code
Throws:
IOException - if an error occurred during the HTTP request


Copyright © 2009-2012. All Rights Reserved.