com.quadrique.jbuildingblocks.core.io.http.client
Class JbbHttpClient

java.lang.Object
  extended by com.quadrique.jbuildingblocks.core.io.http.client.JbbHttpClient

public class JbbHttpClient
extends Object

This class provides convenience routines to simplify and streamline the request/response handling HTTP communications. The actual HTTP layer is based on the Apache HttpClient package.

Author:
dkumbham

Method Summary
 JbbHttpResponse authenticate(String urlStr, String username, String password, HashMap<String,String> headers, HashMap<String,String> params, boolean followRedirects, int timeout)
          This method automatically handles authentication.
 JbbHttpResponse get(String url, HashMap<String,String> headers, HashMap<String,String> params, boolean followRedirects, int timeout)
          http get method sent to server url.
static JbbHttpClient getInstance()
           
 JbbHttpResponse head(String url, HashMap<String,String> headers, HashMap<String,String> params, boolean followRedirects, int timeout)
          http get method sent to server url.
 JbbHttpResponse login(String url, HashMap<String,String> headers, HashMap<String,String> params, boolean followRedirects, int timeout)
          http login method will post username and password (required identity parameters) and will automatically takes care of the url redirectng which is the case for most of the sites that require login.
 JbbHttpResponse multipartRequest(String url, HashMap<String,String> headers, HashMap<String,String> params, File[] files, boolean followRedirects, int timeout)
          posts multiple files to the specified url.
 JbbHttpResponse post(String url, HashMap<String,String> headers, HashMap<String,String> params, boolean followRedirects, int timeout)
          http post method sent to server url.
 JbbHttpResponse postFile(String url, HashMap<String,String> headers, String fileName, boolean followRedirects, int timeout)
          posts given file to the server url.
 JbbHttpResponse postXml(String url, HashMap<String,String> headers, String serializedXmlDocument, boolean followRedirects, int timeout)
          posts xml to the server url.
 JbbHttpResponse postXml(String url, HashMap<String,String> headers, String serializedXmlDocument, boolean followRedirects, int timeout, String postEncoding)
          posts xml to the server url using the given encoding (e.g.
 void setMaxConnections(int maxConnections)
           
 void setRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler retryHandler)
          setter methods **
 void setTimeout(int timeout)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static JbbHttpClient getInstance()
Returns:
an instance of the HttpClientHandler class. If there has been already one instantiation, the same instance is returned so that it can be shared accross the application. A typical usage would be: HttpClientHandler.getInstance(). The max connections per host is set to 20.

setRetryHandler

public void setRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler retryHandler)
setter methods **


setTimeout

public void setTimeout(int timeout)

setMaxConnections

public void setMaxConnections(int maxConnections)

login

public JbbHttpResponse login(String url,
                             HashMap<String,String> headers,
                             HashMap<String,String> params,
                             boolean followRedirects,
                             int timeout)
                      throws Exception
http login method will post username and password (required identity parameters) and will automatically takes care of the url redirectng which is the case for most of the sites that require login.

Parameters:
url -
headers -
params -
followRedirects -
timeout -
Returns:
HttpResponse
Throws:
Exception

head

public JbbHttpResponse head(String url,
                            HashMap<String,String> headers,
                            HashMap<String,String> params,
                            boolean followRedirects,
                            int timeout)
                     throws Exception
http get method sent to server url.

Parameters:
url -
headers -
params -
followRedirects -
timeout -
Returns:
response
Throws:
Exception

get

public JbbHttpResponse get(String url,
                           HashMap<String,String> headers,
                           HashMap<String,String> params,
                           boolean followRedirects,
                           int timeout)
                    throws Exception
http get method sent to server url.

Parameters:
url -
headers -
params -
followRedirects -
timeout -
Returns:
response
Throws:
Exception

authenticate

public JbbHttpResponse authenticate(String urlStr,
                                    String username,
                                    String password,
                                    HashMap<String,String> headers,
                                    HashMap<String,String> params,
                                    boolean followRedirects,
                                    int timeout)
                             throws Exception
This method automatically handles authentication. The method will use given credentials to handle basic authentication requests..picks the Basic authentication scheme over NTLM & Digest.

Parameters:
urlStr -
username -
password -
headers -
params -
followRedirects -
timeout -
Returns:
HttpResponse
Throws:
Exception

post

public JbbHttpResponse post(String url,
                            HashMap<String,String> headers,
                            HashMap<String,String> params,
                            boolean followRedirects,
                            int timeout)
                     throws Exception
http post method sent to server url. The given parameters are url-encoded.

Parameters:
url -
headers -
params -
followRedirects -
timeout -
Returns:
HttpResponse
Throws:
Exception

postXml

public JbbHttpResponse postXml(String url,
                               HashMap<String,String> headers,
                               String serializedXmlDocument,
                               boolean followRedirects,
                               int timeout)
                        throws Exception
posts xml to the server url. Content encoding is set to UTF-8.

Parameters:
url -
headers -
serializedXmlDocument -
followRedirects -
timeout -
Returns:
HttpResponse
Throws:
Exception

postXml

public JbbHttpResponse postXml(String url,
                               HashMap<String,String> headers,
                               String serializedXmlDocument,
                               boolean followRedirects,
                               int timeout,
                               String postEncoding)
                        throws Exception
posts xml to the server url using the given encoding (e.g. "UTF-16"...)

Parameters:
url -
headers -
serializedXmlDocument -
followRedirects -
timeout -
postEncoding - the encoding to use for the serializedXmlDocument in the POST body
Returns:
HttpResponse
Throws:
Exception

postFile

public JbbHttpResponse postFile(String url,
                                HashMap<String,String> headers,
                                String fileName,
                                boolean followRedirects,
                                int timeout)
                         throws Exception
posts given file to the server url. If the filename extension is .xml then it posts with contentype as text/xml.

Parameters:
url -
headers -
fileName -
followRedirects -
timeout -
Returns:
HttpResponse
Throws:
Exception

multipartRequest

public JbbHttpResponse multipartRequest(String url,
                                        HashMap<String,String> headers,
                                        HashMap<String,String> params,
                                        File[] files,
                                        boolean followRedirects,
                                        int timeout)
                                 throws Exception
posts multiple files to the specified url. The files contenttype nor the charset is set.

Parameters:
url -
headers -
params -
files -
followRedirects -
timeout -
Returns:
HttpResponse
Throws:
Exception


Copyright © 2001-2008 Quadrique Corporation. All Rights Reserved.