Search in sources :

Example 1 with ClientType

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;
}
Also used : StringUtils(software.amazon.awssdk.utils.StringUtils) SdkHttpUtils(software.amazon.awssdk.utils.http.SdkHttpUtils) ClientType(software.amazon.awssdk.core.ClientType) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) HttpClientDependencies(software.amazon.awssdk.core.internal.http.HttpClientDependencies) RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) SdkAdvancedClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedClientOption) Collectors(java.util.stream.Collectors) SdkSystemSetting(software.amazon.awssdk.core.SdkSystemSetting) INTERNAL_USER_AGENT(software.amazon.awssdk.core.client.config.SdkClientOption.INTERNAL_USER_AGENT) List(java.util.List) ApiName(software.amazon.awssdk.core.ApiName) SdkUserAgent(software.amazon.awssdk.core.util.SdkUserAgent) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) MutableRequestToRequestPipeline(software.amazon.awssdk.core.internal.http.pipeline.MutableRequestToRequestPipeline) ClientType(software.amazon.awssdk.core.ClientType)

Aggregations

List (java.util.List)1 Collectors (java.util.stream.Collectors)1 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)1 ApiName (software.amazon.awssdk.core.ApiName)1 ClientType (software.amazon.awssdk.core.ClientType)1 SdkSystemSetting (software.amazon.awssdk.core.SdkSystemSetting)1 SdkAdvancedClientOption (software.amazon.awssdk.core.client.config.SdkAdvancedClientOption)1 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)1 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)1 INTERNAL_USER_AGENT (software.amazon.awssdk.core.client.config.SdkClientOption.INTERNAL_USER_AGENT)1 HttpClientDependencies (software.amazon.awssdk.core.internal.http.HttpClientDependencies)1 RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)1 MutableRequestToRequestPipeline (software.amazon.awssdk.core.internal.http.pipeline.MutableRequestToRequestPipeline)1 SdkUserAgent (software.amazon.awssdk.core.util.SdkUserAgent)1 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)1 StringUtils (software.amazon.awssdk.utils.StringUtils)1 SdkHttpUtils (software.amazon.awssdk.utils.http.SdkHttpUtils)1