|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory
public class DefaultHTTPClientFactory
A default implementation of the HTTPClientFactory
interface that uses
a ConnectionInstanceData
to configure an HttpClient
. This
implementation is intended to be subclassed and provides a number of hooks
that subclasses may override.
HTTPClientFactory
,
HttpClient
Field Summary | |
---|---|
static int |
CONNECT_TIMEOUT_SECONDS_DEFAULT
|
static java.lang.String |
CONNECT_TIMEOUT_SECONDS_PROPERTY
|
static java.lang.String |
DISABLE_HTTP_CANCEL_THREAD_PROPERTY
|
static java.lang.String |
ECLIPSE_GROUP_NAME
|
static int |
MAX_CONNECTIONS_PER_HOST_DEFAULT
|
static java.lang.String |
MAX_CONNECTIONS_PER_HOST_PROPERTY
|
static int |
MAX_TOTAL_CONNECTIONS_DEFAULT
|
static java.lang.String |
MAX_TOTAL_CONNECTIONS_PROPERTY
|
static int |
SOCKET_TIMEOUT_SECONDS_DEFAULT
|
static java.lang.String |
SOCKET_TIMEOUT_SECONDS_PROPERTY
|
static int |
USER_AGENT_EXTRA_TEXT_MAX_CHARS
The maximum length in characters of the extra user agent text part. |
static int |
USER_AGENT_OS_INFO_MAX_CHARS
The maximum length in characters of the operating system info part. |
Constructor Summary | |
---|---|
DefaultHTTPClientFactory(ConnectionInstanceData connectionInstanceData)
Creates a new DefaultHTTPClientFactory that will data contained
in the specified instance data to configure HttpClient s. |
Method Summary | |
---|---|
protected void |
addClientToCloserThread(HttpClient httpClient)
Called to add the specified HttpClient instance to a static
thread that will handle idle connection closing. |
void |
configureClient(HttpClient httpClient,
ConnectionInstanceData connectionInstanceData)
Called from HTTPClientFactory.newHTTPClient() to perform final configuration of a
new HttpClient instance before it is returned to the caller of
that method. |
void |
configureClientCredentials(HttpClient httpClient,
HttpState state,
ConnectionInstanceData connectionInstanceData)
Called from HTTPClientFactory.newHTTPClient() to configure credentials for a new
HttpClient instance. |
void |
configureClientParams(HttpClient httpClient,
HttpClientParams params,
ConnectionInstanceData connectionInstanceData)
Called from HTTPClientFactory.newHTTPClient() to configure a new
HttpClient 's HttpClientParams . |
void |
configureClientProxy(HttpClient httpClient,
HostConfiguration hostConfiguration,
HttpState httpState,
ConnectionInstanceData connectionInstanceData)
Called from HTTPClientFactory.newHTTPClient() to configure proxy settings for a
new HttpClient instance. |
HttpConnectionManager |
createConnectionManager(ConnectionInstanceData connectionInstanceData)
Called from HTTPClientFactory.newHTTPClient() to create and configure a new
HttpConnectionManager as part of creating a new
HttpClient instance. |
protected Credentials |
createCredentials(ConnectionInstanceData connectionInstanceData)
Called from configureClientCredentials(HttpClient, HttpState, ConnectionInstanceData)
to create a new Credentials instance for the specified
ConnectionInstanceData . |
HttpClient |
createHTTPClient(HttpConnectionManager connectionManager,
ConnectionInstanceData connectionInstanceData)
Called from HTTPClientFactory.newHTTPClient() to create a new HttpClient . |
protected Credentials |
createProxyCredentials(ConnectionInstanceData connectionInstanceData)
|
void |
dispose(HttpClient httpClient)
Called to dispose an HttpClient that was previously obtained from
a call to HTTPClientFactory.newHTTPClient() . |
java.lang.String |
getUserAgent(HttpClient httpClient,
ConnectionInstanceData connectionInstanceData)
Called from ConfigurableHTTPClientFactory.configureClientParams(HttpClient, HttpClientParams, ConnectionInstanceData)
to obtain a user-agent string to configure a new HttpClient with. |
protected java.lang.String |
getUserAgentExtraString(HttpClient httpClient,
ConnectionInstanceData connectionInstanceData)
Subclasses can override to provide extra text that gets appended to the parenthetical part of the user agent HTTP header. |
HttpClient |
newHTTPClient()
Called to obtain a new HttpClient instance. |
protected boolean |
shouldAcceptUntrustedCertificates(ConnectionInstanceData connectionInstanceData)
Called from createHTTPClient(HttpConnectionManager, ConnectionInstanceData)
to test whether an HttpClient created for the specified
connection should be configured to accept untrusted SSL certificates. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String CONNECT_TIMEOUT_SECONDS_PROPERTY
"com.microsoft.tfs.core.connectTimeoutSeconds"
public static final int CONNECT_TIMEOUT_SECONDS_DEFAULT
30
public static final java.lang.String SOCKET_TIMEOUT_SECONDS_PROPERTY
"com.microsoft.tfs.core.socketTimeoutSeconds"
public static final int SOCKET_TIMEOUT_SECONDS_DEFAULT
1800
public static final java.lang.String MAX_TOTAL_CONNECTIONS_PROPERTY
"com.microsoft.tfs.core.maxTotalConnections"
public static final int MAX_TOTAL_CONNECTIONS_DEFAULT
40
public static final java.lang.String MAX_CONNECTIONS_PER_HOST_PROPERTY
"com.microsoft.tfs.core.maxConnectionsPerHost"
public static final int MAX_CONNECTIONS_PER_HOST_DEFAULT
10
public static final java.lang.String DISABLE_HTTP_CANCEL_THREAD_PROPERTY
"com.microsoft.tfs.core.disableCancelThread"
public static final java.lang.String ECLIPSE_GROUP_NAME
"Eclipse Platform"
public static final int USER_AGENT_EXTRA_TEXT_MAX_CHARS
30
public static final int USER_AGENT_OS_INFO_MAX_CHARS
30
Constructor Detail |
---|
public DefaultHTTPClientFactory(ConnectionInstanceData connectionInstanceData)
DefaultHTTPClientFactory
that will data contained
in the specified instance data to configure HttpClient
s.
serverURI
- the URI
that will be connected to (must not be
null
)Method Detail |
---|
public HttpClient newHTTPClient()
HTTPClientFactory
HttpClient
instance.
newHTTPClient
in interface HTTPClientFactory
HttpClient
(must not be null
)public void dispose(HttpClient httpClient)
Called to dispose an HttpClient
that was previously obtained from
a call to HTTPClientFactory.newHTTPClient()
.
This method is called by TFSConnection.close()
to
clean up any http client resources. It can be assumed that the specified
HttpClient
instance will no longer be used after calling this
method.
dispose
in interface HTTPClientFactory
httpClient
- an HttpClient
instance to dispose (must not be
null
)public HttpConnectionManager createConnectionManager(ConnectionInstanceData connectionInstanceData)
HTTPClientFactory.newHTTPClient()
to create and configure a new
HttpConnectionManager
as part of creating a new
HttpClient
instance. Subclasses may override. The default
behavior is to instantiate a MultiThreadedHttpConnectionManager
and configure it with some default parameters.
createConnectionManager
in interface ConfigurableHTTPClientFactory
HttpConnectionManager
(must not be
null
)public HttpClient createHTTPClient(HttpConnectionManager connectionManager, ConnectionInstanceData connectionInstanceData)
HTTPClientFactory.newHTTPClient()
to create a new HttpClient
.
Most of the configuration should be done by other methods - see the
javadoc on those methods for details. This method is called after
ConfigurableHTTPClientFactory.createConnectionManager(ConnectionInstanceData)
and is passed
the HttpConnectionManager
returned from that method. Subclasses
may override.
This method will modify the HTTPClient Protocol
registration for
"https" protocols to use a custom SecureProtocolSocketFactory
that will allow users to accept untrusted certificates.
createHTTPClient
in interface ConfigurableHTTPClientFactory
connectionManager
- the HttpConnectionManager
returned from
ConfigurableHTTPClientFactory.createConnectionManager(ConnectionInstanceData)
(never
null
)connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)
HttpClient
instance (must not be null
)protected boolean shouldAcceptUntrustedCertificates(ConnectionInstanceData connectionInstanceData)
createHTTPClient(HttpConnectionManager, ConnectionInstanceData)
to test whether an HttpClient
created for the specified
connection should be configured to accept untrusted SSL certificates.
Subclasses may override. The default behavior is to check an environment
variable. If the value of the environment variable
EnvironmentVariables.ACCEPT_UNTRUSTED_CERTIFICATES
is set,
true
is returned. Otherwise, false
is returned.
connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)
true
to configure the new HttpClient
instance to accept untrusted SSL certificatespublic void configureClientParams(HttpClient httpClient, HttpClientParams params, ConnectionInstanceData connectionInstanceData)
HTTPClientFactory.newHTTPClient()
to configure a new
HttpClient
's HttpClientParams
. Subclasses may override.
The default behavior is to configure the
http.protocol.expect-continue
parameter to
false
and set a custom user agent string.
configureClientParams
in interface ConfigurableHTTPClientFactory
httpClient
- the HttpClient
being configured (never null
)params
- the HttpClientParams
to configure (never null
)connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)public final java.lang.String getUserAgent(HttpClient httpClient, ConnectionInstanceData connectionInstanceData)
ConfigurableHTTPClientFactory.configureClientParams(HttpClient, HttpClientParams, ConnectionInstanceData)
to obtain a user-agent string to configure a new HttpClient
with.
Use getUserAgentExtraString(HttpClient, ConnectionInstanceData)
to customize thet user agent string.
getUserAgent
in interface ConfigurableHTTPClientFactory
httpClient
- the HttpClient
being configured (never null
)connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)
null
to not
configure a user-agentprotected java.lang.String getUserAgentExtraString(HttpClient httpClient, ConnectionInstanceData connectionInstanceData)
Subclasses can override to provide extra text that gets appended to the
parenthetical part of the user agent HTTP header. If null
or
empty string is returned no extra text is appended. The returned string
should be 30 characters or less
(it will be truncated if it exceeds this limit).
The user agent header is formatted like:
ProductFamily, SKU:XX (ProductName 1.2.3.4567890; OS Arch Version; extra text goes here if present)
httpClient
- the HttpClient
being configured (must not be
null
)connectionInstanceData
- the connection instance data (must not be null
)
null
or the emptry string
to omit the extra partpublic void configureClientCredentials(HttpClient httpClient, HttpState state, ConnectionInstanceData connectionInstanceData)
HTTPClientFactory.newHTTPClient()
to configure credentials for a new
HttpClient
instance. Subclasses may override. The default
behavior is to call #createCredentials(ConnectionInstanceData)
.
If that method returns a non-null
Credentials
object, then that object is set as the credentials for the
HttpState
.
configureClientCredentials
in interface ConfigurableHTTPClientFactory
httpClient
- the HttpClient
being configured (never null
)state
- the HttpState
to configure credentials on (never
null
)connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)protected Credentials createCredentials(ConnectionInstanceData connectionInstanceData)
configureClientCredentials(HttpClient, HttpState, ConnectionInstanceData)
to create a new Credentials
instance for the specified
ConnectionInstanceData
. Subclasses may override. The default
behavior is to simply return default credentials.
connectionInstanceData
- the ConnectionInstanceData
to get configuration data from
(never null
)
Credentials
object or null
to not use
Credentials
protected Credentials createProxyCredentials(ConnectionInstanceData connectionInstanceData)
public void configureClientProxy(HttpClient httpClient, HostConfiguration hostConfiguration, HttpState httpState, ConnectionInstanceData connectionInstanceData)
HTTPClientFactory.newHTTPClient()
to configure proxy settings for a
new HttpClient
instance. Subclasses may override.
configureClientProxy
in interface ConfigurableHTTPClientFactory
httpClient
- the HttpClient
being configured (never null
)hostConfiguration
- the HostConfiguration
of the new HttpClient
instance (never null
)httpState
- the HttpState
of the new HttpClient
instance
(never null
)connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)public void configureClient(HttpClient httpClient, ConnectionInstanceData connectionInstanceData)
HTTPClientFactory.newHTTPClient()
to perform final configuration of a
new HttpClient
instance before it is returned to the caller of
that method. Subclasses may override. The default behavior is to call
#addClientToCloserThread(HttpClient)
with the new client
instance.
configureClient
in interface ConfigurableHTTPClientFactory
httpClient
- the new HttpClient
instance (never null
)connectionInstanceData
- the ConnectionInstanceData
being used to supply
configuration data (never null
)protected final void addClientToCloserThread(HttpClient httpClient)
HttpClient
instance to a static
thread that will handle idle connection closing.
httpClient
- the HttpClient
instance to add (must not be
null
)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |