public final class SharedHttpClientProvider extends Object implements HttpClientProvider
HTTP
connections. This uses a
thread-safe connection-manager instead of creating a new istance on every call.
This is done for the folowing reasons:
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT_MILLISEC
Allow 10s for a socket to open
|
static int |
DEFAULT_SOCKET_TIMEOUT_MILLISEC
Allow 30s for some sort of response before an error is thrown
|
static int |
DEFAULT_SOCKET_TTL_MILLISEC
Expire connections from the pool after 10 minutes by default
|
Constructor and Description |
---|
SharedHttpClientProvider(int maxNumberOfConnections)
Constructs with
DEFAULT_CONNECTION_TIMEOUT_MILLISEC and
DEFAULT_SOCKET_TIMEOUT_MILLISEC . |
SharedHttpClientProvider(int maxNumberOfConnections,
int connectionTimeoutMs,
int socketTimeoutMs) |
SharedHttpClientProvider(int maxNumberOfConnections,
int connectionTimeoutMs,
int socketTimeoutMs,
int socketTtlMs)
|
Modifier and Type | Method and Description |
---|---|
org.apache.http.client.HttpClient |
getHttpClient() |
org.apache.http.client.HttpClient |
getHttpClient(String username,
String password)
Get a new client using basic authentication
|
public static final int DEFAULT_CONNECTION_TIMEOUT_MILLISEC
public static final int DEFAULT_SOCKET_TIMEOUT_MILLISEC
public static final int DEFAULT_SOCKET_TTL_MILLISEC
public SharedHttpClientProvider(int maxNumberOfConnections)
DEFAULT_CONNECTION_TIMEOUT_MILLISEC
and
DEFAULT_SOCKET_TIMEOUT_MILLISEC
.SharedHttpClientProvider#SharedHttpClientProvider(String, int, int)
public SharedHttpClientProvider(int maxNumberOfConnections, int connectionTimeoutMs, int socketTimeoutMs)
public SharedHttpClientProvider(int maxNumberOfConnections, int connectionTimeoutMs, int socketTimeoutMs, int socketTtlMs)
maxNumberOfConnections
- the maximum number of Http connections in the poolconnectionTimeoutMs
- the time to wait for a connection from the pool before failuresocketTimeoutMs
- the time to wait for data activity on a connection before failuresocketTtlMs
- the time for a socket to remain alive before being forcibly closed (0 for infinite)public org.apache.http.client.HttpClient getHttpClient()
getHttpClient
in interface HttpClientProvider
HttpClient
instance to use for the next HTTP call.public org.apache.http.client.HttpClient getHttpClient(String username, String password)
HttpClientProvider
getHttpClient
in interface HttpClientProvider
username
- the usernamepassword
- the password for the userHttpClient
instance to use for the next HTTP call.Copyright © 2012. All Rights Reserved.