software.amazon.awssdk.core.client.config.SdkAdvancedClientOption Java Examples
The following examples show how to use
software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.
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: S3TestHelper.java From edison-microservice with Apache License 2.0 | 6 votes |
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 #2
Source File: BaseClientBuilderClass.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private MethodSpec mergeServiceDefaultsMethod() { boolean crc32FromCompressedDataEnabled = model.getCustomizationConfig().isCalculateCrc32FromCompressedData(); MethodSpec.Builder builder = MethodSpec.methodBuilder("mergeServiceDefaults") .addAnnotation(Override.class) .addModifiers(PROTECTED, FINAL) .returns(SdkClientConfiguration.class) .addParameter(SdkClientConfiguration.class, "config") .addCode("return config.merge(c -> c.option($T.SIGNER, defaultSigner())\n", SdkAdvancedClientOption.class) .addCode(" .option($T" + ".CRC32_FROM_COMPRESSED_DATA_ENABLED, $L)", SdkClientOption.class, crc32FromCompressedDataEnabled); String clientConfigClassName = model.getCustomizationConfig().getServiceSpecificClientConfigClass(); if (StringUtils.isNotBlank(clientConfigClassName)) { builder.addCode(".option($T.SERVICE_CONFIGURATION, $T.builder().build())", SdkClientOption.class, ClassName.bestGuess(clientConfigClassName)); } builder.addCode(");"); return builder.build(); }
Example #3
Source File: BaseClientHandler.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
protected <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext createExecutionContext( ClientExecutionParams<InputT, OutputT> params, ExecutionAttributes executionAttributes) { SdkRequest originalRequest = params.getInput(); executionAttributes .putAttribute(SdkExecutionAttribute.SERVICE_CONFIG, clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION)) .putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfiguration.option(SdkClientOption.SERVICE_NAME)); ExecutionInterceptorChain interceptorChain = new ExecutionInterceptorChain(clientConfiguration.option(SdkClientOption.EXECUTION_INTERCEPTORS)); return ExecutionContext.builder() .interceptorChain(interceptorChain) .interceptorContext(InterceptorContext.builder() .request(originalRequest) .build()) .executionAttributes(executionAttributes) .signer(clientConfiguration.option(SdkAdvancedClientOption.SIGNER)) .build(); }
Example #4
Source File: ApplyUserAgentStage.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Only user agent suffix needs to be added in this method. Any other changes to user agent should be handled in * {@link #getUserAgent(SdkClientConfiguration, List)} method. */ private String addUserAgentSuffix(StringBuilder userAgent, SdkClientConfiguration config) { String userDefinedSuffix = config.option(SdkAdvancedClientOption.USER_AGENT_SUFFIX); if (!StringUtils.isEmpty(userDefinedSuffix)) { userAgent.append(COMMA).append(userDefinedSuffix.trim()); } return userAgent.toString(); }
Example #5
Source File: TranscribeStreamingRetryClient.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
/** * Create a TranscribeStreamingRetryClient with given credential and configuration * * @param creds Creds to use for transcription * @param endpoint Endpoint to use for transcription * @param region Region to use for transcriptions * @throws URISyntaxException if the endpoint is not a URI */ public TranscribeStreamingRetryClient(AwsCredentialsProvider creds, String endpoint, Region region) throws URISyntaxException { this(TranscribeStreamingAsyncClient.builder() .overrideConfiguration( c -> c.putAdvancedOption( SdkAdvancedClientOption.SIGNER, EventStreamAws4Signer.create())) .credentialsProvider(creds) .endpointOverride(new URI(endpoint)) .region(region) .build()); }
Example #6
Source File: STSCredentialProviderV2.java From dremio-oss with Apache License 2.0 | 5 votes |
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 #7
Source File: HttpTestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public static SdkClientConfiguration testClientConfiguration() { return SdkClientConfiguration.builder() .option(SdkClientOption.EXECUTION_INTERCEPTORS, new ArrayList<>()) .option(SdkClientOption.ENDPOINT, URI.create("http://localhost:8080")) .option(SdkClientOption.RETRY_POLICY, RetryPolicy.defaultRetryPolicy()) .option(SdkClientOption.ADDITIONAL_HTTP_HEADERS, new HashMap<>()) .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) .option(SdkAdvancedClientOption.SIGNER, new NoOpSigner()) .option(SdkAdvancedClientOption.USER_AGENT_PREFIX, "") .option(SdkAdvancedClientOption.USER_AGENT_SUFFIX, "") .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run) .option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE, Executors.newScheduledThreadPool(1)) .build(); }
Example #8
Source File: AwsDefaultClientBuilder.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected final SdkClientConfiguration mergeChildDefaults(SdkClientConfiguration configuration) { SdkClientConfiguration config = mergeServiceDefaults(configuration); return config.merge(c -> c.option(AwsAdvancedClientOption.ENABLE_DEFAULT_REGION_DETECTION, true) .option(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, false) .option(AwsClientOption.SERVICE_SIGNING_NAME, signingName()) .option(SdkClientOption.SERVICE_NAME, serviceName()) .option(AwsClientOption.ENDPOINT_PREFIX, serviceEndpointPrefix())); }
Example #9
Source File: AmazonHttpClientTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void testUserAgentPrefixAndSuffixAreAdded() { String prefix = "somePrefix"; String suffix = "someSuffix-blah-blah"; HttpResponseHandler<?> handler = mock(HttpResponseHandler.class); SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder() .option(SdkAdvancedClientOption.USER_AGENT_PREFIX, prefix) .option(SdkAdvancedClientOption.USER_AGENT_SUFFIX, suffix) .option(SdkClientOption.SYNC_HTTP_CLIENT, sdkHttpClient) .option(SdkClientOption.ENDPOINT, URI.create("http://example.com")) .build(); AmazonSyncHttpClient client = new AmazonSyncHttpClient(config); client.requestExecutionBuilder() .request(ValidSdkObjects.sdkHttpFullRequest().build()) .originalRequest(NoopTestRequest.builder().build()) .executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null)) .execute(combinedSyncResponseHandler(handler, null)); ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class); verify(sdkHttpClient).prepareRequest(httpRequestCaptor.capture()); final String userAgent = httpRequestCaptor.getValue().httpRequest().firstMatchingHeader("User-Agent") .orElseThrow(() -> new AssertionError("User-Agent header was not found")); Assert.assertTrue(userAgent.startsWith(prefix)); Assert.assertTrue(userAgent.endsWith(suffix)); }
Example #10
Source File: HttpTestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public static SdkClientConfiguration testClientConfiguration() { return SdkClientConfiguration.builder() .option(SdkClientOption.EXECUTION_INTERCEPTORS, new ArrayList<>()) .option(SdkClientOption.ENDPOINT, URI.create("http://localhost:8080")) .option(SdkClientOption.RETRY_POLICY, RetryPolicy.defaultRetryPolicy()) .option(SdkClientOption.ADDITIONAL_HTTP_HEADERS, new HashMap<>()) .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) .option(SdkAdvancedClientOption.SIGNER, new NoOpSigner()) .option(SdkAdvancedClientOption.USER_AGENT_PREFIX, "") .option(SdkAdvancedClientOption.USER_AGENT_SUFFIX, "") .option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE, Executors.newScheduledThreadPool(1)) .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run) .build(); }
Example #11
Source File: S3EndpointResolutionTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * @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 #12
Source File: ProfileFileConfigurationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
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 #13
Source File: EndpointTraitTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@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 #14
Source File: DefaultClientBuilderTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override protected SdkClientConfiguration mergeChildDefaults(SdkClientConfiguration configuration) { return configuration.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, TEST_SIGNER)); }
Example #15
Source File: ApplyUserAgentStage.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private StringBuilder getUserAgent(SdkClientConfiguration config, List<ApiName> requestApiNames) { String userDefinedPrefix = config.option(SdkAdvancedClientOption.USER_AGENT_PREFIX); String awsExecutionEnvironment = SdkSystemSetting.AWS_EXECUTION_ENV.getStringValue().orElse(null); StringBuilder userAgent = new StringBuilder(StringUtils.trimToEmpty(userDefinedPrefix)); String systemUserAgent = UserAgentUtils.getUserAgent(); if (!systemUserAgent.equals(userDefinedPrefix)) { userAgent.append(COMMA).append(systemUserAgent); } if (!StringUtils.isEmpty(awsExecutionEnvironment)) { userAgent.append(SPACE).append(AWS_EXECUTION_ENV_PREFIX).append(awsExecutionEnvironment.trim()); } ClientType clientType = clientConfig.option(SdkClientOption.CLIENT_TYPE); if (clientType == null) { clientType = ClientType.UNKNOWN; } userAgent.append(SPACE) .append(IO) .append("/") .append(StringUtils.lowerCase(clientType.name())); String clientName = clientName(clientType); userAgent.append(SPACE) .append(HTTP) .append("/") .append(SdkHttpUtils.urlEncode(clientName)); if (!requestApiNames.isEmpty()) { String requestUserAgent = requestApiNames.stream() .map(n -> n.name() + "/" + n.version()) .collect(Collectors.joining(" ")); userAgent.append(SPACE).append(requestUserAgent); } return userAgent; }
Example #16
Source File: test-query-client-builder-class.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner()).option( SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)); }
Example #17
Source File: test-client-builder-class.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override protected final SdkClientConfiguration mergeServiceDefaults(SdkClientConfiguration config) { return config.merge(c -> c.option(SdkAdvancedClientOption.SIGNER, defaultSigner()) .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false) .option(SdkClientOption.SERVICE_CONFIGURATION, ServiceConfiguration.builder().build())); }