use of software.amazon.awssdk.core.ApiName in project aws-glue-schema-registry by awslabs.
the class UserAgentRequestInterceptorTest method test_UserAgentInterceptor_ReturnsSdkRequestWithUserAgent.
@ParameterizedTest
@MethodSource("getClientConfigTestCases")
void test_UserAgentInterceptor_ReturnsSdkRequestWithUserAgent(GlueSchemaRegistryConfiguration config, String expectedName) {
AwsCredentialsProvider mockAwsCredentialsProvider = mock(AwsCredentialsProvider.class);
AWSSchemaRegistryClient awsSchemaRegistryClient = new AWSSchemaRegistryClient(mockAwsCredentialsProvider, config);
AWSSchemaRegistryClient.UserAgentRequestInterceptor userAgentRequestInterceptor = awsSchemaRegistryClient.new UserAgentRequestInterceptor();
Context.ModifyRequest modifyRequest = mock(Context.ModifyRequest.class);
GetSchemaVersionRequest glueRequest = GetSchemaVersionRequest.builder().build();
doReturn(glueRequest).when(modifyRequest).request();
SdkRequest sdkHttpRequest = userAgentRequestInterceptor.modifyRequest(modifyRequest, null);
assertNotNull(sdkHttpRequest);
assertTrue(sdkHttpRequest.overrideConfiguration().isPresent());
ApiName actualApiName = sdkHttpRequest.overrideConfiguration().get().apiNames().get(0);
assertEquals(MavenPackaging.VERSION, actualApiName.version());
assertEquals(expectedName, actualApiName.name());
}
use of software.amazon.awssdk.core.ApiName in project aws-sdk-java-v2 by aws.
the class ApplyUserAgentStage method getUserAgent.
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 = SdkUserAgent.create().userAgent();
if (!systemUserAgent.equals(userDefinedPrefix)) {
userAgent.append(COMMA).append(systemUserAgent);
}
String internalUserAgent = StringUtils.trimToEmpty(clientConfig.option(INTERNAL_USER_AGENT));
if (!internalUserAgent.isEmpty()) {
userAgent.append(SPACE).append(internalUserAgent);
}
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));
String retryMode = config.option(SdkClientOption.RETRY_POLICY).retryMode().toString();
userAgent.append(SPACE).append(CONFIG).append("/").append(RETRY_MODE).append("/").append(StringUtils.lowerCase(retryMode));
if (!requestApiNames.isEmpty()) {
String requestUserAgent = requestApiNames.stream().map(n -> n.name() + "/" + n.version()).collect(Collectors.joining(" "));
userAgent.append(SPACE).append(requestUserAgent);
}
return userAgent;
}
Aggregations