software.amazon.awssdk.core.client.config.ClientOverrideConfiguration Java Examples

The following examples show how to use software.amazon.awssdk.core.client.config.ClientOverrideConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsyncSqsClientFactory.java    From dynein with Apache License 2.0 7 votes vote down vote up
private SqsAsyncClient getAsyncSQSClient(AsyncSqsClientConfiguration config) {
  if (config.getType().equals(AsyncSqsClientConfiguration.Type.PRODUCTION)) {
    SqsAsyncClientBuilder builder =
        SqsAsyncClient.builder()
            .region(Region.of(config.getRegion()))
            .endpointOverride(config.getEndpoint());

    OverrideConfiguration overrideConfig = config.getOverrideConfiguration();

    if (overrideConfig != null) {

      RetryPolicy retry = buildRetryPolicy(overrideConfig.getRetryPolicyConfiguration());
      ClientOverrideConfiguration clientOverrideConfiguration =
          ClientOverrideConfiguration.builder()
              .apiCallAttemptTimeout(Duration.ofMillis(overrideConfig.getApiCallAttemptTimeout()))
              .apiCallTimeout(Duration.ofMillis(overrideConfig.getApiCallTimeout()))
              .retryPolicy(retry)
              .build();

      builder = builder.overrideConfiguration(clientOverrideConfiguration);
    }
    return builder.build();
  } else {
    throw new IllegalArgumentException("Doesn't support this Type " + config.getType());
  }
}
 
Example #2
Source File: S3TestHelper.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
public static S3Client createS3Client(final Integer mappedPort) {
    final AwsBasicCredentials credentials = AwsBasicCredentials.create("test", "test");
    final StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(credentials);

    return S3Client.builder()
            .credentialsProvider(credentialsProvider)
            .endpointOverride(URI.create(String.format("http://localhost:%d", mappedPort)))
            .region(Region.EU_CENTRAL_1)
            .serviceConfiguration(S3Configuration.builder()
                    .pathStyleAccessEnabled(true)
                    .build())
            .overrideConfiguration(ClientOverrideConfiguration
                    .builder()
                    .putAdvancedOption(SdkAdvancedClientOption.SIGNER, new NoOpSigner())
                    .build())
            .build();
}
 
Example #3
Source File: SqsMessageQueueReceiverEndpointIntegrationTest.java    From synapse with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    new SqsClientHelper(asyncClient).createChannelIfNotExists(SQS_INTEGRATION_TEST_CHANNEL);

    AwsProperties awsProperties = new AwsProperties();
    awsProperties.setRegion(Region.EU_CENTRAL_1.id());

    delegateAsyncClient = SqsAsyncClient.builder()
            .credentialsProvider(StaticCredentialsProvider.create(
                    AwsBasicCredentials.create("foobar", "foobar")))
            .overrideConfiguration(ClientOverrideConfiguration.builder()
                    .apiCallAttemptTimeout(Duration.ofMillis(200))
                    .retryPolicy(new SqsAutoConfiguration(awsProperties)
                            .sqsRetryPolicy()).build())
            .endpointOverride(URI.create("http://localhost:8080/"))
            .build();
}
 
Example #4
Source File: SdkDefaultClientBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public final B overrideConfiguration(ClientOverrideConfiguration overrideConfig) {
    clientConfiguration.option(EXECUTION_INTERCEPTORS, overrideConfig.executionInterceptors());
    clientConfiguration.option(RETRY_POLICY, overrideConfig.retryPolicy().orElse(null));
    clientConfiguration.option(ADDITIONAL_HTTP_HEADERS, overrideConfig.headers());
    clientConfiguration.option(SIGNER, overrideConfig.advancedOption(SIGNER).orElse(null));
    clientConfiguration.option(USER_AGENT_SUFFIX, overrideConfig.advancedOption(USER_AGENT_SUFFIX).orElse(null));
    clientConfiguration.option(USER_AGENT_PREFIX, overrideConfig.advancedOption(USER_AGENT_PREFIX).orElse(null));
    clientConfiguration.option(API_CALL_TIMEOUT, overrideConfig.apiCallTimeout().orElse(null));
    clientConfiguration.option(API_CALL_ATTEMPT_TIMEOUT, overrideConfig.apiCallAttemptTimeout().orElse(null));
    clientConfiguration.option(DISABLE_HOST_PREFIX_INJECTION,
                               overrideConfig.advancedOption(DISABLE_HOST_PREFIX_INJECTION).orElse(null));
    clientConfiguration.option(PROFILE_FILE, overrideConfig.defaultProfileFile().orElse(null));
    clientConfiguration.option(PROFILE_NAME, overrideConfig.defaultProfileName().orElse(null));
    return thisBuilder();
}
 
Example #5
Source File: MessageAttributesIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sendMessage_InvalidMd5_ThrowsException() {
    try (SqsClient tamperingClient = SqsClient.builder()
                                              .credentialsProvider(getCredentialsProvider())
                                              .overrideConfiguration(ClientOverrideConfiguration
                                                                             .builder()
                                                                             .addExecutionInterceptor(
                                                                                     new TamperingInterceptor())
                                                                             .build())
                                              .build()) {
        tamperingClient.sendMessage(
                SendMessageRequest.builder()
                                  .queueUrl(queueUrl)
                                  .messageBody(MESSAGE_BODY)
                                  .messageAttributes(createRandomAttributeValues(10))
                                  .build());
        fail("Expected SdkClientException");
    } catch (SdkClientException e) {
        assertThat(e.getMessage(), containsString("MD5 returned by SQS does not match"));
    }
}
 
Example #6
Source File: Aws2ITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static DynamoDbClient buildClient() {
  final AwsSessionCredentials awsCreds = AwsSessionCredentials.create("access_key_id", "secret_key_id", "session_token");
  return DynamoDbClient
    .builder()
    .endpointOverride(URI.create("http://localhost:8000"))
    .region(Region.US_WEST_2)
    .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
    .overrideConfiguration(ClientOverrideConfiguration.builder().apiCallTimeout(Duration.ofSeconds(1)).build())
    .build();

  // final AwsClientBuilder.EndpointConfiguration endpointConfiguration = new
  // AwsClientBuilder.EndpointConfiguration(
  // "http://localhost:8000", "us-west-2");
  // final BasicAWSCredentials awsCreds = new
  // BasicAWSCredentials("access_key_id", "secret_key_id");
  // final AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder
  // .standard()
  // .withEndpointConfiguration(endpointConfiguration)
  // .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
  // .withClientConfiguration(new
  // ClientConfiguration().withConnectionTimeout(1));
  //
  // return builder.build();
}
 
Example #7
Source File: STSCredentialProviderV2.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static void initUserAgent(StsClientBuilder builder, Configuration conf) {
  String userAgent = "Hadoop " + VersionInfo.getVersion();
  final String userAgentPrefix = conf.getTrimmed(Constants.USER_AGENT_PREFIX, "");
  if (!userAgentPrefix.isEmpty()) {
    userAgent = userAgentPrefix + ", " + userAgent;
  }

  builder.overrideConfiguration(ClientOverrideConfiguration.builder()
    .putAdvancedOption(SdkAdvancedClientOption.USER_AGENT_PREFIX, userAgent)
    .build());
}
 
Example #8
Source File: SyncStreamingOperationApiCallTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
ClientOverrideConfiguration clientOverrideConfiguration() {
    return ClientOverrideConfiguration.builder()
                                      .apiCallTimeout(Duration.ofMillis(TIMEOUT))
                                      .retryPolicy(RetryPolicy.none())
                                      .build();
}
 
Example #9
Source File: EndpointTraitTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    client = clientBuilder().build();

    clientWithDisabledHostPrefix = clientBuilder().overrideConfiguration(
        ClientOverrideConfiguration.builder()
                                   .putAdvancedOption(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, true)
                                   .build()).build();

    when(mockHttpClient.prepareRequest(any())).thenReturn(abortableCallable);

    when(abortableCallable.call()).thenThrow(SdkClientException.create("Dummy exception"));
}
 
Example #10
Source File: ProfileFileConfigurationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private ClientOverrideConfiguration overrideConfig(String profileContent, String profileName, Signer signer) {
    return ClientOverrideConfiguration.builder()
                                      .defaultProfileFile(profileFile(profileContent))
                                      .defaultProfileName(profileName)
                                      .retryPolicy(r -> r.numRetries(0))
                                      .putAdvancedOption(SdkAdvancedClientOption.SIGNER, signer)
                                      .build();
}
 
Example #11
Source File: V2OptimizedClientCreationBenchmark.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
@Benchmark
public void createClient(Blackhole blackhole) throws Exception {
    client = DynamoDbClient.builder()
                                    .region(Region.US_WEST_2)
                                    .credentialsProvider(StaticCredentialsProvider.create(
                                        AwsBasicCredentials.create("test", "test")))
                                    .httpClient(ApacheHttpClient.builder().build())
                                    .overrideConfiguration(ClientOverrideConfiguration.builder().build())
                                    .endpointDiscoveryEnabled(false)
                                    .build();

    blackhole.consume(client);
}
 
Example #12
Source File: Aws2Test.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static DynamoDbAsyncClient buildAsyncClient() {
  final AwsSessionCredentials awsCreds = AwsSessionCredentials.create("access_key_id", "secret_key_id", "session_token");
  final DynamoDbAsyncClient build = DynamoDbAsyncClient.builder()
    .endpointOverride(URI.create("http://localhost:8000"))
    .region(Region.US_WEST_2)
    .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
    .overrideConfiguration(ClientOverrideConfiguration.builder()
      .apiCallTimeout(Duration.ofSeconds(1)).build())
    .build();
  return build;
}
 
Example #13
Source File: DefaultClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private SdkDefaultClientBuilder<TestClientBuilder, TestClient> testClientBuilder() {
    ClientOverrideConfiguration overrideConfig =
            ClientOverrideConfiguration.builder()
                                       .putAdvancedOption(SIGNER, TEST_SIGNER)
                                       .build();

    return new TestClientBuilder().overrideConfiguration(overrideConfig);
}
 
Example #14
Source File: DefaultClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private SdkDefaultClientBuilder<TestAsyncClientBuilder, TestAsyncClient> testAsyncClientBuilder() {
    ClientOverrideConfiguration overrideConfig =
            ClientOverrideConfiguration.builder()
                                       .putAdvancedOption(SIGNER, TEST_SIGNER)
                                       .build();

    return new TestAsyncClientBuilder().overrideConfiguration(overrideConfig);
}
 
Example #15
Source File: DefaultAwsClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private AwsClientBuilder<TestClientBuilder, TestClient> testClientBuilder() {
    ClientOverrideConfiguration overrideConfig =
        ClientOverrideConfiguration.builder()
                                   .putAdvancedOption(SIGNER, TEST_SIGNER)
                                   .putAdvancedOption(ENABLE_DEFAULT_REGION_DETECTION, false)
                                   .build();

    return new TestClientBuilder().credentialsProvider(AnonymousCredentialsProvider.create())
                                  .overrideConfiguration(overrideConfig);
}
 
Example #16
Source File: DefaultAwsClientBuilderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private AwsClientBuilder<TestAsyncClientBuilder, TestAsyncClient> testAsyncClientBuilder() {
    ClientOverrideConfiguration overrideConfig =
        ClientOverrideConfiguration.builder()
                                   .putAdvancedOption(SIGNER, TEST_SIGNER)
                                   .putAdvancedOption(ENABLE_DEFAULT_REGION_DETECTION, false)
                                   .build();

    return new TestAsyncClientBuilder().credentialsProvider(AnonymousCredentialsProvider.create())
                                       .overrideConfiguration(overrideConfig);
}
 
Example #17
Source File: ExecutionInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private <T extends AwsClientBuilder<?, U>, U> U initializeAndBuild(T builder, ExecutionInterceptor interceptor) {
    return builder.region(Region.US_WEST_1)
                  .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                  .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid")))
                  .overrideConfiguration(ClientOverrideConfiguration.builder()
                                                                    .addExecutionInterceptor(interceptor)
                                                                    .build())
                  .build();
}
 
Example #18
Source File: SqsAutoConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(SqsAsyncClient.class)
public SqsAsyncClient sqsAsyncClient(final AwsCredentialsProvider credentialsProvider, final RetryPolicy sqsRetryPolicy) {
    return SqsAsyncClient.builder()
            .credentialsProvider(credentialsProvider)
            .region(Region.of(awsProperties.getRegion()))
            .overrideConfiguration(ClientOverrideConfiguration.builder()
                    .apiCallAttemptTimeout(Duration.ofSeconds(5))
                    .retryPolicy(sqsRetryPolicy).build())
            .build();
}
 
Example #19
Source File: Aws2Test.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static DynamoDbClient buildClient() {
  final AwsSessionCredentials awsCreds = AwsSessionCredentials.create("access_key_id", "secret_key_id", "session_token");
  return DynamoDbClient.builder()
    .endpointOverride(URI.create("http://localhost:8000"))
    .region(Region.US_WEST_2)
    .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
    .overrideConfiguration(ClientOverrideConfiguration.builder()
      .apiCallTimeout(Duration.ofSeconds(1)).build())
    .build();
}
 
Example #20
Source File: KinesisAutoConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(KinesisAsyncClient.class)
public KinesisAsyncClient kinesisAsyncClient(final AwsCredentialsProvider credentialsProvider,
                                             final RetryPolicy kinesisRetryPolicy) {
    return KinesisAsyncClient.builder()
            .credentialsProvider(credentialsProvider)
            .region(Region.of(awsProperties.getRegion()))
            .overrideConfiguration(ClientOverrideConfiguration.builder().retryPolicy(kinesisRetryPolicy).build())
            .build();
}
 
Example #21
Source File: KinesisTestConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public KinesisAsyncClient kinesisAsyncClient(final @Value("${test.environment:local}") String testEnvironment,
                                             final AwsCredentialsProvider credentialsProvider,
                                             final RetryPolicy kinesisRetryPolicy) {
    // kinesalite does not support cbor at the moment (v1.11.6)
    System.setProperty("aws.cborEnabled", "false");
    LOG.info("kinesis client for local tests");
    final KinesisAsyncClient kinesisClient;
    if (testEnvironment.equals("local")) {
        kinesisClient = KinesisAsyncClient.builder()
                .httpClient(
                        // Disables HTTP2 because of problems with LocalStack
                        NettyNioAsyncHttpClient.builder()
                                .protocol(Protocol.HTTP1_1)
                                .build())
                .endpointOverride(URI.create("http://localhost:4568"))
                .region(Region.EU_CENTRAL_1)
                .credentialsProvider(credentialsProvider)
                .overrideConfiguration(ClientOverrideConfiguration.builder().retryPolicy(kinesisRetryPolicy).build())
                .build();
    } else {
        kinesisClient = KinesisAsyncClient.builder()
                .credentialsProvider(credentialsProvider)
                .build();
    }
    createChannelIfNotExists(kinesisClient, KINESIS_INTEGRATION_TEST_CHANNEL, EXPECTED_NUMBER_OF_SHARDS);
    return kinesisClient;
}
 
Example #22
Source File: ITTracingExecutionInterceptor.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override protected DynamoDbClient newClient(int port) throws IOException {
  ClientOverrideConfiguration configuration = ClientOverrideConfiguration.builder()
      .retryPolicy(RetryPolicy.builder().numRetries(3).build())
      .apiCallTimeout(Duration.ofSeconds(1))
      .addExecutionInterceptor(AwsSdkTracing.create(httpTracing).executionInterceptor())
      .build();

  return client = DynamoDbClient.builder()
      .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x")))
      .httpClient(primeHttpClient())
      .region(Region.US_EAST_1)
      .overrideConfiguration(configuration)
      .endpointOverride(URI.create("http://127.0.0.1:" + port))
      .build();
}
 
Example #23
Source File: FirehoseAppender.java    From kinesis-logback-appender with Apache License 2.0 5 votes vote down vote up
@Override
protected FirehoseAsyncClient createClient(AwsCredentialsProvider credentials, ClientOverrideConfiguration configuration, ThreadPoolExecutor executor, Region region, Optional<URI> endpointOverride) {
  FirehoseAsyncClientBuilder builder = FirehoseAsyncClient.builder()
    .credentialsProvider(credentials)
    .asyncConfiguration(b -> b.advancedOption(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, executor))
    .overrideConfiguration(configuration)
    .region(region);
  
  endpointOverride.ifPresent(endpoint -> builder.endpointOverride(endpoint));
  
  return builder.build();
}
 
Example #24
Source File: KinesisAppender.java    From kinesis-logback-appender with Apache License 2.0 5 votes vote down vote up
@Override
protected KinesisAsyncClient createClient(AwsCredentialsProvider credentials, ClientOverrideConfiguration configuration,
    ThreadPoolExecutor executor, Region region, Optional<URI> endpointOverride) {
  KinesisAsyncClientBuilder builder = KinesisAsyncClient.builder()
    .credentialsProvider(credentials)
    .region(region)
    .overrideConfiguration(configuration)
    .asyncConfiguration(b -> b.advancedOption(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, executor));
  
  endpointOverride.ifPresent(endpoint -> builder.endpointOverride(endpoint));
  
  return builder.build();
}
 
Example #25
Source File: S3ClientBuilderListener.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Override
public S3ClientBuilder onCreated(BeanCreatedEvent<S3ClientBuilder> event) {
    S3ClientBuilder builder = event.getBean();
    builder.overrideConfiguration(ClientOverrideConfiguration.builder().retryPolicy(RetryMode.LEGACY).build());

    return builder;
}
 
Example #26
Source File: ServiceIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    client = GlacierClient.builder()
                          .credentialsProvider(getCredentialsProvider())
                          .overrideConfiguration(ClientOverrideConfiguration
                                                         .builder()
                                                         .addExecutionInterceptor(capturingExecutionInterceptor)
                                                         .build())
                          .build();
}
 
Example #27
Source File: S3EndpointResolutionTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @return Client builder instance preconfigured with credentials and region using the {@link #mockHttpClient} for transport
 * and {@link #mockSigner} for signing. Using actual AwsS3V4Signer results in NPE as the execution goes into payload signing
 * due to "http" protocol and input stream is not mark supported.
 */
private S3ClientBuilder clientBuilderWithMockSigner() {
    return S3Client.builder()
                   .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid")))
                   .region(Region.AP_SOUTH_1)
                   .overrideConfiguration(ClientOverrideConfiguration.builder()
                                                                     .putAdvancedOption(SdkAdvancedClientOption.SIGNER,
                                                                                        mockSigner)
                                                                     .build())
                   .httpClient(mockHttpClient);
}
 
Example #28
Source File: AwsS3V4SignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_UsingSdkClient_WithCorrectSigner_SetInConfig() {
    S3Client customClient = getClientBuilder()
        .overrideConfiguration(ClientOverrideConfiguration.builder()
                                                          .putAdvancedOption(SIGNER, AwsS3V4Signer.create())
                                                          .build())
        .build();

    String response = customClient.getObjectAsBytes(req -> req.bucket(BUCKET_NAME).key(KEY))
                                  .asString(StandardCharsets.UTF_8);

    assertEquals(CONTENT, response);
}
 
Example #29
Source File: AwsS3V4SignerIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test (expected = S3Exception.class)
public void test_UsingSdkClient_WithIncorrectSigner_SetInConfig() {
    S3Client customClient = getClientBuilder()
        .overrideConfiguration(ClientOverrideConfiguration.builder()
                                                          .putAdvancedOption(SIGNER, Aws4Signer.create())
                                                          .build())
        .build();

   customClient.getObjectAsBytes(req -> req.bucket(BUCKET_NAME).key(KEY))
               .asString(StandardCharsets.UTF_8);
}
 
Example #30
Source File: AsyncGetObjectFaultIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupFixture() {
    createBucket(BUCKET);
    s3.putObject(PutObjectRequest.builder()
                                 .bucket(BUCKET)
                                 .key(KEY)
                                 .build(), RequestBody.fromString("some contents"));
    s3ClientWithTimeout = s3AsyncClientBuilder()
        .overrideConfiguration(ClientOverrideConfiguration.builder()
                                                          .apiCallTimeout(Duration.ofSeconds(1))
                                                          .build())
        .build();
}