下面列出了org.apache.http.conn.ConnectionPoolTimeoutException#com.ibm.cloud.objectstorage.ClientConfiguration 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private AmazonHttpClient(ClientConfiguration clientConfig,
RetryPolicy retryPolicy,
RequestMetricCollector requestMetricCollector,
HttpClientSettings httpClientSettings) {
this.config = clientConfig;
this.retryPolicy =
retryPolicy == null ? new RetryPolicyAdapter(clientConfig.getRetryPolicy(), clientConfig) : retryPolicy;
this.httpClientSettings = httpClientSettings;
this.requestMetricCollector = requestMetricCollector;
this.responseMetadataCache =
clientConfig.getCacheResponseMetadata() ?
new ResponseMetadataCache(clientConfig.getResponseMetadataCacheSize()) :
new NullResponseMetadataCache();
this.httpRequestTimer = new HttpRequestTimer();
this.clientExecutionTimer = new ClientExecutionTimer();
// When enabled, total retry capacity is computed based on retry cost
// and desired number of retries.
int throttledRetryMaxCapacity = clientConfig.useThrottledRetries()
? THROTTLED_RETRY_COST * config.getMaxConsecutiveRetriesBeforeThrottling() : -1;
this.retryCapacity = new CapacityManager(throttledRetryMaxCapacity);
}
/**
* Ensure proxy settings are NOT applied to http client
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Test
public void shouldNotAddProxyToClient() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
HttpClientBuilder builder = HttpClientBuilder.create();
ClientConfiguration config = new ClientConfiguration();
HttpClientSettings settings = HttpClientSettings.adapt(config);
DefaultTokenManager.addProxyConfig(builder, settings);
builder.build();
Field field = builder.getClass().getDeclaredField("routePlanner");
field.setAccessible(true);
HttpRoutePlanner httpRoutePlanner = (HttpRoutePlanner) field.get(builder);
assertNull(httpRoutePlanner);
}
/**
* If a custom executor is set then the Max Connections in Client Configuration should be
* ignored and the executor should be used as is.
*/
@Test
public void customMaxConnsAndExplicitExecutor_UsesExplicitExecutor() throws Exception {
final int clientConfigMaxConns = 10;
final int customExecutorThreadCount = 15;
final ExecutorService customExecutor = Executors
.newFixedThreadPool(customExecutorThreadCount);
ExecutorService actualExecutor = builderWithRegion().withClientConfiguration(
new ClientConfiguration().withMaxConnections(clientConfigMaxConns))
.withExecutorFactory(new StaticExecutorFactory(customExecutor)).build()
.getAsyncParams().getExecutor();
assertThat(actualExecutor, instanceOf(ThreadPoolExecutor.class));
assertEquals(customExecutor, actualExecutor);
assertEquals(customExecutorThreadCount,
((ThreadPoolExecutor) actualExecutor).getMaximumPoolSize());
}
public static String getUserAgent(final ClientConfiguration config, final String userAgentMarker) {
String userDefinedPrefix = config != null ? config.getUserAgentPrefix() : "";
String userDefinedSuffix = config != null ? config.getUserAgentSuffix() : "";
String awsExecutionEnvironment = getEnvironmentVariable(AWS_EXECUTION_ENV_NAME);
StringBuilder userAgent = new StringBuilder(userDefinedPrefix.trim());
if(!ClientConfiguration.DEFAULT_USER_AGENT.equals(userDefinedPrefix)) {
userAgent.append(COMMA).append(ClientConfiguration.DEFAULT_USER_AGENT);
}
if(StringUtils.hasValue(userDefinedSuffix)) {
userAgent.append(COMMA).append(userDefinedSuffix.trim());
}
if(StringUtils.hasValue(awsExecutionEnvironment)) {
userAgent.append(SPACE).append(AWS_EXECUTION_ENV_PREFIX).append(awsExecutionEnvironment.trim());
}
if(StringUtils.hasValue(userAgentMarker)) {
userAgent.append(SPACE).append(userAgentMarker.trim());
}
return userAgent.toString();
}
@Test(timeout = 60 * 1000)
public void testSslHandshakeTimeout() {
AmazonHttpClient httpClient = new AmazonHttpClient(new ClientConfiguration()
.withSocketTimeout(CLIENT_SOCKET_TO).withMaxErrorRetry(0));
System.out.println("Sending request to localhost...");
try {
httpClient.requestExecutionBuilder()
.request(new EmptyHttpRequest(server.getHttpsEndpoint(), HttpMethodName.GET))
.execute();
fail("Client-side socket read timeout is expected!");
} catch (AmazonClientException e) {
/**
* Http client catches the SocketTimeoutException and throws a
* ConnectTimeoutException.
* {@link org.apache.http.impl.conn.DefaultHttpClientConnectionOperator#connect(ManagedHttpClientConnection, HttpHost, InetSocketAddress, int, SocketConfig, HttpContext)}
*/
Assert.assertTrue(e.getCause() instanceof ConnectTimeoutException);
ConnectTimeoutException cte = (ConnectTimeoutException) e.getCause();
Assert.assertThat(cte.getMessage(), org.hamcrest.Matchers
.containsString("Read timed out"));
}
}
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutEnabled_HonorsRetryPolicy() throws IOException {
int maxRetries = 2;
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(1 * 1000)
.withMaxErrorRetry(maxRetries);
HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory();
ConnectionManagerAwareHttpClient rawHttpClient = spy(httpClientFactory.create(HttpClientSettings.adapt(config)));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, newGetRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
/* the expected exception and number of requests. */
assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class));
int expectedNumberOfRequests = 1 + maxRetries;
assertNumberOfRetries(rawHttpClient, expectedNumberOfRequests);
assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), expectedNumberOfRequests);
}
}
/**
* Response to HEAD requests don't have an entity so we shouldn't try to wrap the response in a
* {@link BufferedHttpEntity}.
*/
@Test
public void requestTimeoutEnabled_HeadRequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpHeadResponseProxy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpHead.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, createMockHeadRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
NullResponseHandler.assertIsUnmarshallingException(e);
}
assertNull(responseProxy.getEntity());
}
@Test
public void requestTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(0);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, createMockGetRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
@Test
public void requestTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse()
throws Exception {
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
httpClient.requestExecutionBuilder().request(createMockGetRequest()).execute(new ErrorDuringUnmarshallingResponseHandler().leaveConnectionOpen());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutSetInRequestObject_TakesPrecedenceOverClientConfiguration() {
// Client configuration is set arbitrarily high so that the test will timeout if the
// client configuration is incorrectly honored over the request config
httpClient = new AmazonHttpClient(new ClientConfiguration().withSocketTimeout(LONGER_SOCKET_TIMEOUT)
.withRequestTimeout(REQUEST_TIMEOUT * 1000).withMaxErrorRetry(0));
try {
EmptyHttpRequest request = newGetRequest();
request.setOriginalRequest(new EmptyAmazonWebServiceRequest().withSdkRequestTimeout(REQUEST_TIMEOUT));
execute(httpClient, request);
fail("Exception expected");
} catch (AmazonClientException e) {
assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class));
}
}
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutDisabledInRequestObject_TakesPrecedenceOverClientConfiguration() {
final int socketTimeout = REQUEST_TIMEOUT;
// Client configuration is set arbitrarily low so that the request will be aborted if
// the client configuration is incorrectly honored over the request config
httpClient = new AmazonHttpClient(
new ClientConfiguration().withSocketTimeout(socketTimeout).withRequestTimeout(1).withMaxErrorRetry(0));
try {
EmptyHttpRequest request = newGetRequest();
request.setOriginalRequest(new EmptyAmazonWebServiceRequest().withSdkRequestTimeout(0));
execute(httpClient, request);
fail("Exception expected");
} catch (AmazonClientException e) {
assertThat(e.getCause(), instanceOf(SocketTimeoutException.class));
}
}
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutEnabled_ServerRespondsWithRetryableError_RetriesUpToLimitThenThrowsServerException()
throws IOException {
int maxRetries = 2;
ClientConfiguration config = new ClientConfiguration().withRequestTimeout(25 * 1000)
.withClientExecutionTimeout(25 * 1000).withMaxErrorRetry(maxRetries);
HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory();
ConnectionManagerAwareHttpClient rawHttpClient = spy(httpClientFactory.create(HttpClientSettings.adapt(config)));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
httpClient.execute(newGetRequest(),
new ErrorDuringUnmarshallingResponseHandler(),
new NullErrorResponseHandler(),
new ExecutionContext());
fail("Exception expected");
} catch (AmazonServiceException e) {
assertEquals(e.getStatusCode(), STATUS_CODE);
int expectedNumberOfRequests = 1 + maxRetries;
assertNumberOfRetries(rawHttpClient, expectedNumberOfRequests);
assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 0);
assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 0);
}
}
@Test(expected = ClientExecutionTimeoutException.class)
public void
clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_expired()
throws Exception {
ClientConfiguration config = new ClientConfiguration()
.withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT)
.withMaxErrorRetry(0);
ConnectionManagerAwareHttpClient rawHttpClient =
createRawHttpClientSpy(config);
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
execute(httpClient, new EmptyHttpRequest(server.getEndpoint(),
HttpMethodName.PUT, new SdkBufferedInputStream(new InputStream() {
@Override
public int read() throws IOException {
// Sleeping here to avoid OOM issues from a limitless InputStream
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return 1;
}
})));
}
/**
* Tests that a streaming operation has it's request properly cleaned up if the client is interrupted after the
* response is received.
*
* @see TT0070103230
*/
@Test
public void clientInterruptedDuringResponseHandlers_DoesNotLeakConnection() throws IOException {
ClientConfiguration config = new ClientConfiguration();
ConnectionManagerAwareHttpClient rawHttpClient = new ApacheHttpClientFactory().create(HttpClientSettings.adapt(config));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
interruptCurrentThreadAfterDelay(1000);
List<RequestHandler2> requestHandlers = RequestHandlerTestUtils
.buildRequestHandlerList(new SlowRequestHandler().withAfterResponseWaitInSeconds(10));
try {
requestBuilder().executionContext(withHandlers(requestHandlers)).execute(new DummyResponseHandler().leaveConnectionOpen());
fail("Expected exception");
} catch (AmazonClientException e) {
assertThat(e.getCause(), instanceOf(InterruptedException.class));
}
@SuppressWarnings("deprecation")
int leasedConnections = ((ConnPoolControl<?>) ((SdkHttpClient)rawHttpClient).getHttpClientConnectionManager()).getTotalStats().getLeased();
assertEquals(0, leasedConnections);
}
@Test
public void clientExecutionTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(0);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
execute(httpClient, createMockGetRequest());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
@Test
public void clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse()
throws Exception {
ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT);
ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
HttpResponseProxy responseProxy = createHttpResponseProxySpy();
doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
httpClient = new AmazonHttpClient(config, rawHttpClient, null);
try {
httpClient.requestExecutionBuilder().request(createMockGetRequest()).execute(new ErrorDuringUnmarshallingResponseHandler().leaveConnectionOpen());
fail("Exception expected");
} catch (AmazonClientException e) {
}
assertResponseWasNotBuffered(responseProxy);
}
/**
* The client execution timer uses interrupts to abort the client but if another thread
* interrupts the current thread for another reason we don't want to squash the
* {@link InterruptedException}. We should set the thread's interrupted status and throw the
* exception back out (we can't throw the actual {@link InterruptedException} because it's
* checked)
*/
@Test(timeout = TEST_TIMEOUT)
public void interruptCausedBySomethingOtherThanTimer_PropagatesInterruptToCaller() {
final int socketTimeoutInMillis = 100;
httpClient = new AmazonHttpClient(new ClientConfiguration().withSocketTimeout(socketTimeoutInMillis)
.withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT)
.withRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
new FixedTimeBackoffStrategy(CLIENT_EXECUTION_TIMEOUT), 1, false)));
// We make sure the first connection has failed due to the socket timeout before
// interrupting so we know that we are sleeping per the backoff strategy. Apache HTTP
// client doesn't seem to honor interrupts reliably but Thread.sleep does
interruptCurrentThreadAfterDelay(socketTimeoutInMillis * 2);
try {
httpClient.requestExecutionBuilder().request(newGetRequest()).execute();
fail("Exception expected");
} catch (AmazonClientException e) {
assertTrue(Thread.currentThread().isInterrupted());
assertThat(e.getCause(), instanceOf(InterruptedException.class));
}
}
/**
* @deprecated use {@link AmazonS3EncryptionClientBuilder#withEncryptionMaterials(EncryptionMaterialsProvider)} and
* {@link AmazonS3EncryptionClientBuilder#withCredentials(AWSCredentialsProvider)} and
* {@link AmazonS3EncryptionClientBuilder#withCryptoConfiguration(CryptoConfiguration)} and
* {@link AmazonS3EncryptionClientBuilder#withClientConfiguration(ClientConfiguration)} and
* {@link AmazonS3EncryptionClientBuilder#withMetricsCollector(RequestMetricCollector)} and
* {@link AmazonS3EncryptionClientBuilder#withKmsClient(AWSKMS)}
*/
@Deprecated
public AmazonS3EncryptionClient(AWSKMSClient kms,
AWSCredentialsProvider credentialsProvider,
EncryptionMaterialsProvider kekMaterialsProvider,
ClientConfiguration clientConfig,
CryptoConfiguration cryptoConfig,
RequestMetricCollector requestMetricCollector) {
super(credentialsProvider, clientConfig, requestMetricCollector);
assertParameterNotNull(kekMaterialsProvider,
"EncryptionMaterialsProvider parameter must not be null.");
assertParameterNotNull(cryptoConfig,
"CryptoConfiguration parameter must not be null.");
this.isKMSClientInternal = kms == null;
this.kms = isKMSClientInternal
? newAWSKMSClient(credentialsProvider, clientConfig, cryptoConfig,
requestMetricCollector)
: kms;
this.crypto = new CryptoModuleDispatcher(this.kms, new S3DirectImpl(),
credentialsProvider, kekMaterialsProvider, cryptoConfig);
}
@Test(timeout = TEST_TIMEOUT)
public void clientExecutionTimeoutEnabled_WithShorterRequestTimeout_ThrowsHttpRequestTimeoutException()
throws IOException {
httpClient = new AmazonHttpClient(new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT)
.withRequestTimeout(SHORTER_REQUEST_TIMEOUT).withMaxErrorRetry(0));
try {
httpClient.requestExecutionBuilder().request(newGetRequest()).execute();
fail("Exception expected");
} catch (AmazonClientException e) {
assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class));
// Completed tasks means the client execution was aborted by the timer
assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 0);
assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 1);
}
}
@Test(timeout = TEST_TIMEOUT)
public void clientExecutionTimeoutEnabled_WithShorterRequestTimeoutAndRetry_ThrowsClientExecutionTimeoutException()
throws IOException {
final int clientExecutionTimeout = 1500;
final int requestTimeout = 1000;
final int backoffTime = 300;
httpClient = new AmazonHttpClient(new ClientConfiguration().withClientExecutionTimeout(clientExecutionTimeout)
.withRequestTimeout(requestTimeout)
.withRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
new FixedTimeBackoffStrategy(backoffTime), Integer.MAX_VALUE, false)));
try {
httpClient.requestExecutionBuilder().request(newGetRequest()).execute();
fail("Exception expected");
} catch (AmazonClientException e) {
assertThat(e, instanceOf(ClientExecutionTimeoutException.class));
// Completed tasks means the client execution was aborted by the timer
assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 1);
assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 1);
}
}
@Test
public void request_has_proxy_config_when_proxy_auth_enabled() throws Exception {
List<ProxyAuthenticationMethod> authMethods = Arrays.asList(ProxyAuthenticationMethod.BASIC,
ProxyAuthenticationMethod.DIGEST,
ProxyAuthenticationMethod.KERBEROS,
ProxyAuthenticationMethod.NTLM,
ProxyAuthenticationMethod.SPNEGO);
List<String> expectedAuthMethods = Arrays.asList(AuthSchemes.BASIC,
AuthSchemes.DIGEST,
AuthSchemes.KERBEROS,
AuthSchemes.NTLM,
AuthSchemes.SPNEGO);
ClientConfiguration configuration = new ClientConfiguration().withProxyHost("localhost")
.withProxyPort(80)
.withProxyUsername("user")
.withProxyPassword("password")
.withProxyAuthenticationMethods(authMethods);
HttpClientSettings settings = HttpClientSettings.adapt(configuration);
HttpRequestBase requestBase = requestFactory.create(newDefaultRequest(HttpMethodName.POST), settings);
Assert.assertEquals(expectedAuthMethods, requestBase.getConfig().getProxyPreferredAuthSchemes());
}
@Test(timeout = 60 * 1000)
public void leasing_a_new_connection_fails_with_connection_pool_timeout()
throws Exception {
String localhostEndpoint = "http://localhost:" + server.getPort();
AmazonHttpClient httpClient = new AmazonHttpClient(
new ClientConfiguration()
.withMaxConnections(1)
.withConnectionTimeout(100)
.withMaxErrorRetry(0));
Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET);
// Block the first connection in the pool with this request.
httpClient.requestExecutionBuilder().request(request).execute(new EmptyAWSResponseHandler());
try {
// A new connection will be leased here which would fail in
// ConnectionPoolTimeoutException.
httpClient.requestExecutionBuilder().request(request).execute();
Assert.fail("Connection pool timeout exception is expected!");
} catch (AmazonClientException e) {
Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException);
}
}
/**
* Get the default user agent and append the user agent marker if there are any.
*/
private String getDefaultUserAgent(Request<?> request) {
String userAgentMarker = request.getOriginalRequest().getRequestClientOptions().getClientMarker(RequestClientOptions
.Marker.USER_AGENT);
String userAgent = ClientConfiguration.DEFAULT_USER_AGENT;
if (StringUtils.hasValue(userAgentMarker)) {
userAgent += " " + userAgentMarker;
}
return userAgent;
}
/**
* @deprecated use {@link AmazonS3EncryptionClientBuilder#withEncryptionMaterials(EncryptionMaterialsProvider)} and
* {@link AmazonS3EncryptionClientBuilder#withCredentials(AWSCredentialsProvider)} and
* {@link AmazonS3EncryptionClientBuilder#withCryptoConfiguration(CryptoConfiguration)} and
* {@link AmazonS3EncryptionClientBuilder#withClientConfiguration(ClientConfiguration)}
*/
@Deprecated
public AmazonS3EncryptionClient(AWSCredentials credentials,
EncryptionMaterialsProvider encryptionMaterialsProvider,
ClientConfiguration clientConfig, CryptoConfiguration cryptoConfig) {
this(new StaticCredentialsProvider(credentials),
encryptionMaterialsProvider, clientConfig, cryptoConfig);
}
/**
* Loads a set of region metadata by downloading an XML file from the
* given URI and parsing it.
*
* @param uri the uri of the XML file to parse
* @param config configuration for the HTTP client to use to fetch the file
* @throws SdkClientException on error
*/
@Deprecated
public static synchronized void initializeFromURI(
final URI uri,
final ClientConfiguration config) {
try {
regionMetadata = loadMetadataFromURI(uri, config);
} catch (IOException exception) {
throw new SdkClientException(
"Error parsing region metadata from " + uri,
exception);
}
}
@Test
public void clientConfigurationExplicitlySet_UsesExplicitConfiguration() {
ClientConfiguration config = new ClientConfiguration().withSocketTimeout(1000);
AwsAsyncClientParams params = builderWithRegion().withClientConfiguration(config).build()
.getAsyncParams();
assertEquals(config.getSocketTimeout(), params.getClientConfiguration().getSocketTimeout());
}
/**
* Package-protected constructor for unit test purposes.
*/
@SdkTestInternalApi
public AmazonHttpClient(ClientConfiguration clientConfig,
ConnectionManagerAwareHttpClient httpClient,
RequestMetricCollector requestMetricCollector) {
this(clientConfig,
null,
requestMetricCollector,
HttpClientSettings.adapt(clientConfig, false));
this.httpClient = httpClient;
}
/**
* Creates and returns a new instance of AWS KMS client in the case when
* an explicit AWS KMS client is not specified.
*/
private AWSKMSClient newAWSKMSClient(
AWSCredentialsProvider credentialsProvider,
ClientConfiguration clientConfig,
CryptoConfiguration cryptoConfig,
RequestMetricCollector requestMetricCollector
) {
final AWSKMSClient kmsClient = new AWSKMSClient(
credentialsProvider, clientConfig, requestMetricCollector);
final Region kmsRegion = cryptoConfig.getAwsKmsRegion();
if (kmsRegion != null)
kmsClient.setRegion(kmsRegion);
return kmsClient;
}
private HttpClient createHttpClient(String nonProxyHosts) {
HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory();
ClientConfiguration config = new ClientConfiguration()
.withProxyHost("localhost").withProxyPort(server.getPort())
.withNonProxyHosts(nonProxyHosts);
return httpClientFactory.create(HttpClientSettings.adapt(config));
}
@Test
public void emptyClient() {
AmazonWebServiceClient client =
new AmazonWebServiceClient(new ClientConfiguration()) { };
try {
client.getServiceName();
} catch (IllegalStateException exception) {
}
}