public class HTTPConnectionPool
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SSL_HANDSHAKE_TIMEOUT_MILLIS
The default SSL/TLS handshake timeout of the connection pool in milliseconds = 8000.
|
static int |
DEFAULT_TCP_CONNECT_TIMEOUT_MILLIS
The default TCP connect timeout of the connection pool in milliseconds = 10000.
|
Constructor and Description |
---|
HTTPConnectionPool()
Create a new connection pool for a HTTP/S client.
|
Modifier and Type | Method and Description |
---|---|
void |
addClientAuthKeyManagers(java.lang.String serverHost,
int serverPort,
javax.net.ssl.KeyManager[] clientAuthKeyManagers)
Add SSL key managers for client authentication to the pool, for a particular HTTPS host and port.
|
HTTPConnection |
getConnectionFromPool(java.lang.String protocol,
java.lang.String serverHost,
int serverPort)
Get a connection from the pool: Reuse an existing connection or create a new connection if needed.
|
HTTPConnection[] |
getConnections()
Get all connections of the pool.
|
int |
getPoolSize()
Get the number of connections in the pool.
|
boolean |
returnConnectionToPool(HTTPConnection httpConnection,
boolean closeConnection)
Return a connection to the pool.
|
void |
setLimitSSLVersion(java.lang.String limitSSLVersion)
Set/limit the maximal SSL version used by the connection pool.
|
void |
setLocalOutboundAddress(java.net.InetAddress localOutboundAddress)
Set a specific outbound IP address for the connection pool.
|
void |
setSSLHandshakeTimeoutMillis(int sslHandshakeTimeoutMillis)
Set the SSL handshake timeout for the connection pool.
|
void |
setTCPConnectTimeoutMillis(int tcpConnectTimeoutMillis)
Set the TCP connect timeout for the connection pool.
|
void |
setTrustManager(javax.net.ssl.TrustManager[] trustManagers)
Set a specific SSL X509 trust manager for the connection pool, used to validate certificate chains received from an HTTPS server during the SSL handshake.
|
public static final int DEFAULT_TCP_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_SSL_HANDSHAKE_TIMEOUT_MILLIS
public HTTPConnectionPool()
public void setTCPConnectTimeoutMillis(int tcpConnectTimeoutMillis)
tcpConnectTimeoutMillis
- the TCP connect timeout in millisecondsDEFAULT_TCP_CONNECT_TIMEOUT_MILLIS
public void setSSLHandshakeTimeoutMillis(int sslHandshakeTimeoutMillis)
sslHandshakeTimeoutMillis
- the SSL handshake timeout in millisecondsDEFAULT_SSL_HANDSHAKE_TIMEOUT_MILLIS
public void setLocalOutboundAddress(java.net.InetAddress localOutboundAddress)
localOutboundAddress
- the specific outbound IP addresspublic void setLimitSSLVersion(java.lang.String limitSSLVersion)
limitSSLVersion
- the maximal SSL version used by the connection poolpublic void setTrustManager(javax.net.ssl.TrustManager[] trustManagers)
trustManagers
- the specific X509 trust manager for the connection poolpublic void addClientAuthKeyManagers(java.lang.String serverHost, int serverPort, javax.net.ssl.KeyManager[] clientAuthKeyManagers)
serverHost
- the server name or IP addressserverPort
- the server TCP/IP portclientAuthKeyManagers
- the key managers for SSL client authenticationLoadPKCS12Certificate
,
LoadPKCS12Certificate.getKeyManagers()
public HTTPConnection getConnectionFromPool(java.lang.String protocol, java.lang.String serverHost, int serverPort) throws java.lang.Exception
protocol
- the protocol: 'http' or 'https'serverHost
- the server name or IP addressserverPort
- the server TCP/IP portjava.lang.Exception
- if somewhat failsHTTPConnection.getReuseCount()
public boolean returnConnectionToPool(HTTPConnection httpConnection, boolean closeConnection) throws java.io.IOException
httpConnection
- the connection to return to the poolcloseConnection
- if true = close the connection and remove it from the pooljava.io.IOException
- if somewhat failspublic int getPoolSize()
public HTTPConnection[] getConnections()