eu.emi.client.security
Class HttpUtils

java.lang.Object
  extended by eu.emi.client.security.HttpUtils

public class HttpUtils
extends Object

Contains helper code to create HttpClient instances. The following settings are always set (depending on configuration passed in Properties object:

Additionally one can use additional methods of this class to:

The returned client can be configured further by using standard HttpClient preferences API. Note that for convenience some of the HttpClientParams are recognized too and can be set through Properties argument in one shot.

Contains some code from XFire's CommonsHttpMessageSender

Author:
schuller, golbi, Dan Diephouse, Tomasz Sztelak

Field Summary
static String CONNECT_TIMEOUT
          timeout for creating new HTTP connections
static String CONNECTION_CLOSE
          If true then connection will be closed immediately after serving the request
static String HTTP_MAX_REDIRECTS
          Maximum number of redirects to take.
static String HTTP_NON_PROXY_HOSTS
          Space delimited list of hosts for which HTTP proxy shouldn't be used
static String HTTP_PROXY_HOST
          HTTP proxy host
static String HTTP_PROXY_PASS
          HTTP proxy password
static String HTTP_PROXY_PORT
          HTTP proxy port
static String HTTP_PROXY_USER
          HTTP proxy user name
static String MAX_HOST_CONNECTIONS
           
static String MAX_TOTAL_CONNECTIONS
           
static String SO_TIMEOUT
          socket read timeout for HTTP
static String USER_AGENT
           
 
Method Summary
static void configureProxy(org.apache.commons.httpclient.HttpClient client, String uri, Properties properties)
          configure the HTTP proxy settings on the given client
static void configureSSL(org.apache.commons.httpclient.HttpClient client, IAuthenticationConfiguration security)
           
static org.apache.commons.httpclient.HttpClient createClient(Properties properties)
          create a HTTP client (code is based on XFire's CommonsHttpMessageSender
static org.apache.commons.httpclient.HttpClient createClient(String uri, IAuthenticationConfiguration security, Properties properties)
          Convenience method for getting a HttpClient configured with HTTP proxy support and SSL setup.
static void setConnectionTimeout(org.apache.commons.httpclient.HttpClient client, int socketTimeout, int connectTimeout)
          Helper method: sets the connection timeout for the HTTP client and the socket timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_AGENT

public static final String USER_AGENT
See Also:
Constant Field Values

CONNECTION_CLOSE

public static final String CONNECTION_CLOSE
If true then connection will be closed immediately after serving the request

See Also:
Constant Field Values

HTTP_MAX_REDIRECTS

public static final String HTTP_MAX_REDIRECTS
Maximum number of redirects to take. Set to a non positive value to disable automatic redirects.

See Also:
Constant Field Values

HTTP_NON_PROXY_HOSTS

public static final String HTTP_NON_PROXY_HOSTS
Space delimited list of hosts for which HTTP proxy shouldn't be used

See Also:
Constant Field Values

HTTP_PROXY_HOST

public static final String HTTP_PROXY_HOST
HTTP proxy host

See Also:
Constant Field Values

HTTP_PROXY_PORT

public static final String HTTP_PROXY_PORT
HTTP proxy port

See Also:
Constant Field Values

HTTP_PROXY_USER

public static final String HTTP_PROXY_USER
HTTP proxy user name

See Also:
Constant Field Values

HTTP_PROXY_PASS

public static final String HTTP_PROXY_PASS
HTTP proxy password

See Also:
Constant Field Values

MAX_HOST_CONNECTIONS

public static final String MAX_HOST_CONNECTIONS
See Also:
Constant Field Values

MAX_TOTAL_CONNECTIONS

public static final String MAX_TOTAL_CONNECTIONS
See Also:
Constant Field Values

SO_TIMEOUT

public static final String SO_TIMEOUT
socket read timeout for HTTP

See Also:
Constant Field Values

CONNECT_TIMEOUT

public static final String CONNECT_TIMEOUT
timeout for creating new HTTP connections

See Also:
Constant Field Values
Method Detail

createClient

public static org.apache.commons.httpclient.HttpClient createClient(String uri,
                                                                    IAuthenticationConfiguration security,
                                                                    Properties properties)
Convenience method for getting a HttpClient configured with HTTP proxy support and SSL setup.

Parameters:
uri - - URI to connect to
security - - security (i.e. SSL) properties
properties - - additional properties used to customize the client
Returns:
a preconfigured http client

createClient

public static org.apache.commons.httpclient.HttpClient createClient(Properties properties)
create a HTTP client (code is based on XFire's CommonsHttpMessageSender


configureSSL

public static void configureSSL(org.apache.commons.httpclient.HttpClient client,
                                IAuthenticationConfiguration security)

configureProxy

public static void configureProxy(org.apache.commons.httpclient.HttpClient client,
                                  String uri,
                                  Properties properties)
configure the HTTP proxy settings on the given client

Parameters:
client - - the HttpClient instance
uri - - the URI to connect to

setConnectionTimeout

public static void setConnectionTimeout(org.apache.commons.httpclient.HttpClient client,
                                        int socketTimeout,
                                        int connectTimeout)
Helper method: sets the connection timeout for the HTTP client and the socket timeout.

Parameters:
client - - the HTTPClient
socketTimeout - socket timeout in milliseconds
connectTimeout - connection timeout in milliseconds


Copyright © 2012 EMI. All Rights Reserved.