use of software.amazon.awssdk.core.ClientType 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