com.jalios.util
Class HttpClientUtils

java.lang.Object
  extended by com.jalios.util.HttpClientUtils

public class HttpClientUtils
extends Object

Utility class for the jakarta common HttpClient

Version:
$Revision: 24727 $

Field Summary
static String REVISION
           
 
Constructor Summary
HttpClientUtils()
           
 
Method Summary
static String getContent(String url)
          Retrieves the content of the specified url as a string.
static void getContent(String url, File file)
          Save the content of the specified url in the given file.
static void getContent(String url, File file, int timeout)
          Save the content of the specified url in the given file.
static void getContent(String url, File file, int timeout, String userAgent)
          Save the content of the specified url in the given file.
static String getContent(String url, int timeout, String userAgent)
          Retrieves the content of the specified url.
static String getContent(String url, String userAgent)
          Retrieves the content of the specified url.
static org.apache.commons.httpclient.HttpClient getNewHttpClient(String url, int timeout)
          Retrieve a new configured HttpClient instance.
static String postAndGetContent(String url, int timeout, String userAgent, org.apache.commons.httpclient.NameValuePair[] data)
          Post the specified data to the specified url and retrieve the content as a string.
static String postAndGetContent(String url, int timeout, String userAgent, org.apache.commons.httpclient.NameValuePair[] data, String charset)
          Post the specified data to the specified url and retrieve the content as a string.
static void setProxyParams(org.apache.commons.httpclient.HttpClient client, String remoteHostName)
          Set HttpClient proxy parameters based on Java Properties.
static void setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client, String remoteUrl)
          Set HttpClient proxy parameters based on Java Properties.
static void setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client, URL remoteURL)
          Set HttpClient proxy parameters based on Java Properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

HttpClientUtils

public HttpClientUtils()
Method Detail

getNewHttpClient

public static org.apache.commons.httpclient.HttpClient getNewHttpClient(String url,
                                                                        int timeout)
                                                                 throws MalformedURLException
Retrieve a new configured HttpClient instance. The following configuration are performed : - socket and http timeout value are set - proxy param will be configured if required for the specified URL.

Parameters:
url - the url that will be accessed with this client
timeout - the timeout value to use
Returns:
a new HttpClient instance
Throws:
MalformedURLException

setProxyParams

public static void setProxyParams(org.apache.commons.httpclient.HttpClient client,
                                  String remoteHostName)
Set HttpClient proxy parameters based on Java Properties.

Parameters:
client - the HttpClient instance of which proxy parameters
remoteHostName - the remote URL for which the HttpClient is being used it is required in order to be able to apply the rules specified in the system property "http.nonProxyHosts"

setProxyParamsForUrl

public static void setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client,
                                        String remoteUrl)
                                 throws MalformedURLException
Set HttpClient proxy parameters based on Java Properties.

Parameters:
client - the HttpClient instance of which proxy parameters
remoteUrl - the remote url for which the HttpClient is being used. It is required in order to be able to apply the rules specified in the system property "http.nonProxyHosts"
Throws:
MalformedURLException

setProxyParamsForUrl

public static void setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client,
                                        URL remoteURL)
Set HttpClient proxy parameters based on Java Properties.

Parameters:
client - the HttpClient instance of which proxy parameters
remoteURL - the remote URL for which the HttpClient is being used. It is required in order to be able to apply the rules specified in the system property "http.nonProxyHosts"

getContent

public static String getContent(String url)
                         throws org.apache.commons.httpclient.HttpException,
                                IOException
Retrieves the content of the specified url as a string.

Warning: The size of the response body is not controlled and may consume a lot of memory.

Parameters:
url - the url to access
Returns:
the content retrieved as a string
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.2

getContent

public static String getContent(String url,
                                String userAgent)
                         throws org.apache.commons.httpclient.HttpException,
                                IOException
Retrieves the content of the specified url.

Warning: The size of the response body is not controlled and may consume a lot of memory.

Parameters:
url - the url to access
userAgent - the User-Agent
Returns:
the content retrieved as a string
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.2

getContent

public static String getContent(String url,
                                int timeout,
                                String userAgent)
                         throws org.apache.commons.httpclient.HttpException,
                                IOException
Retrieves the content of the specified url.

Warning: The size of the response body is not controlled and may consume a lot of memory.

Parameters:
url - the url to access
timeout - the time (in milliseconds) to wait for a connection to become available. Default value is 3000 (3 seconds). Default value will be used if zero or a negative value is specified.
userAgent - the User-Agent
Returns:
the content retrieved as a string
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.2

getContent

public static void getContent(String url,
                              File file)
                       throws org.apache.commons.httpclient.HttpException,
                              IOException
Save the content of the specified url in the given file.

Parameters:
url - the url to access
file - the output file
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.2

getContent

public static void getContent(String url,
                              File file,
                              int timeout)
                       throws org.apache.commons.httpclient.HttpException,
                              IOException
Save the content of the specified url in the given file.

Parameters:
url - the url to access
file - the output file
timeout - the time (in milliseconds) to wait for a connection to become available. Default value is 3000 (3 seconds). Default value will be used if zero or a negative value is specified.
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.2

getContent

public static void getContent(String url,
                              File file,
                              int timeout,
                              String userAgent)
                       throws org.apache.commons.httpclient.HttpException,
                              IOException
Save the content of the specified url in the given file.

Parameters:
url - the url to access
userAgent - the User-Agent
file - the output file
timeout - the connection timeout
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.2

postAndGetContent

public static String postAndGetContent(String url,
                                       int timeout,
                                       String userAgent,
                                       org.apache.commons.httpclient.NameValuePair[] data)
                                throws org.apache.commons.httpclient.HttpException,
                                       IOException
Post the specified data to the specified url and retrieve the content as a string.

Warning: The size of the response body is not controlled and may consume a lot of memory. Charset encoding used is the default one in HTTP : ISO-8859-1

Parameters:
url - the url to access
timeout - the time (in milliseconds) to wait for a connection to become available. Default value is 3000 (3 seconds). Default value will be used if zero or a negative value is specified.
userAgent - the User-Agent
data - the parameters to be posted to the remote url
Returns:
the content retrieved as a string
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.5

postAndGetContent

public static String postAndGetContent(String url,
                                       int timeout,
                                       String userAgent,
                                       org.apache.commons.httpclient.NameValuePair[] data,
                                       String charset)
                                throws org.apache.commons.httpclient.HttpException,
                                       IOException
Post the specified data to the specified url and retrieve the content as a string.

Warning: The size of the response body is not controlled and may consume a lot of memory.

Parameters:
url - the url to access
timeout - the time (in milliseconds) to wait for a connection to become available. Default value is 3000 (3 seconds). Default value will be used if zero or a negative value is specified.
userAgent - the User-Agent
data - the parameters to be posted to the remote url
charset - the charset encoding to use. If null, uses the default one in HTTP : ISO-8859-1
Returns:
the content retrieved as a string
Throws:
org.apache.commons.httpclient.HttpException
IOException
Since:
jcms-5.7.5


Copyright © 2001-2007 Jalios SA. All Rights Reserved.