Java Code Examples for software.amazon.awssdk.utils.StringUtils#isEmpty()

The following examples show how to use software.amazon.awssdk.utils.StringUtils#isEmpty() . 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: DefaultSdkHttpFullRequest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private String standardizePath(String path) {
    if (StringUtils.isEmpty(path)) {
        return "";
    }

    StringBuilder standardizedPath = new StringBuilder();

    // Path must always start with '/'
    if (!path.startsWith("/")) {
        standardizedPath.append('/');
    }

    standardizedPath.append(path);

    return standardizedPath.toString();
}
 
Example 2
Source File: StreamingRequestMarshaller.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public SdkHttpFullRequest marshall(T in) {
    SdkHttpFullRequest.Builder marshalled = delegateMarshaller.marshall(in).toBuilder();
    marshalled.contentStreamProvider(requestBody.contentStreamProvider());
    String contentType = marshalled.firstMatchingHeader(CONTENT_TYPE)
                                   .orElse(null);
    if (StringUtils.isEmpty(contentType)) {
        marshalled.putHeader(CONTENT_TYPE, requestBody.contentType());
    }

    // Currently, SDK always require content length in RequestBody. So we always
    // send Content-Length header for sync APIs
    // This change will be useful if SDK relaxes the content-length requirement in RequestBody
    addHeaders(marshalled, Optional.of(requestBody.contentLength()), requiresLength, transferEncoding, useHttp2);

    return marshalled.build();
}
 
Example 3
Source File: SdkHttpUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Append the given path to the given baseUri, separating them with a slash, if required. The result will preserve the
 * trailing slash of the provided path.
 */
public static String appendUri(String baseUri, String path) {
    Validate.paramNotNull(baseUri, "baseUri");
    StringBuilder resultUri = new StringBuilder(baseUri);

    if (!StringUtils.isEmpty(path)) {
        if (!baseUri.endsWith("/")) {
            resultUri.append("/");
        }

        resultUri.append(path.startsWith("/") ? path.substring(1) : path);
    }

    return resultUri.toString();
}
 
Example 4
Source File: IntegrationTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the account ID out of the IAM user arn
 *
 * @param arn IAM user ARN
 * @return Account ID if it can be extracted
 * @throws IllegalArgumentException If ARN is not in a valid format
 */
private String parseAccountIdFromArn(String arn) throws IllegalArgumentException {
    String[] arnComponents = arn.split(":");
    if (arnComponents.length < 5 || StringUtils.isEmpty(arnComponents[4])) {
        throw new IllegalArgumentException(String.format("%s is not a valid ARN", arn));
    }
    return arnComponents[4];
}
 
Example 5
Source File: ProxyConfiguration.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Java system property for nonProxyHosts as set of Strings.
 * See http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html.
 */
private Set<String> parseNonProxyHostsProperty() {
    String nonProxyHosts = ProxySystemSetting.NON_PROXY_HOSTS.getStringValue().orElse(null);

    if (!StringUtils.isEmpty(nonProxyHosts)) {
        return Arrays.stream(nonProxyHosts.split("\\|"))
                     .map(String::toLowerCase)
                     .map(s -> s.replace("*", ".*?"))
                     .collect(Collectors.toSet());
    }
    return Collections.emptySet();
}
 
Example 6
Source File: QueryParamsAssertion.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private List<NameValuePair> parseNameValuePairsFromQuery(LoggedRequest actual) {
    String queryParams = URI.create(actual.getUrl()).getQuery();
    if (StringUtils.isEmpty(queryParams)) {
        return Collections.emptyList();
    }
    return URLEncodedUtils.parse(queryParams, StandardCharsets.UTF_8);
}
 
Example 7
Source File: ClientClassUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
static CodeBlock addEndpointTraitCode(OperationModel opModel) {
    CodeBlock.Builder builder = CodeBlock.builder();

    if (opModel.getEndpointTrait() != null && !StringUtils.isEmpty(opModel.getEndpointTrait().getHostPrefix())) {
        String hostPrefix = opModel.getEndpointTrait().getHostPrefix();
        HostPrefixProcessor processor = new HostPrefixProcessor(hostPrefix);

        builder.addStatement("String hostPrefix = $S", hostPrefix);

        if (processor.c2jNames().isEmpty()) {
            builder.addStatement("String resolvedHostExpression = $S", processor.hostWithStringSpecifier());
        } else {
            processor.c2jNames()
                     .forEach(name -> builder.addStatement("$T.paramNotBlank($L, $S)", Validate.class,
                                                          inputShapeMemberGetter(opModel, name),
                                                           name));

            builder.addStatement("String resolvedHostExpression = String.format($S, $L)",
                                 processor.hostWithStringSpecifier(),
                                 processor.c2jNames().stream()
                                          .map(n -> inputShapeMemberGetter(opModel, n))
                                          .collect(Collectors.joining(",")));
        }
    }

    return builder.build();
}
 
Example 8
Source File: HostPrefixProcessor.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Replace all the labels in host with %s symbols and collect the input shape member names into a list
 */
private void replaceHostLabelsWithStringSpecifier(String hostExpression) {
    if (StringUtils.isEmpty(hostExpression)) {
        throw new IllegalArgumentException("Given host prefix is either null or empty");
    }

    Matcher matcher = PATTERN.matcher(hostExpression);

    while (matcher.find()) {
        String matched = matcher.group(1);
        c2jNames.add(matched);
        hostWithStringSpecifier = hostWithStringSpecifier.replaceFirst("\\{" + matched + "}", "%s");
    }
}
 
Example 9
Source File: AbstractAwsSigner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
String getCanonicalizedResourcePath(String resourcePath, boolean urlEncode) {
    if (StringUtils.isEmpty(resourcePath)) {
        return "/";
    } else {
        String value = urlEncode ? SdkHttpUtils.urlEncodeIgnoreSlashes(resourcePath) : resourcePath;
        if (value.startsWith("/")) {
            return value;
        } else {
            return "/".concat(value);
        }
    }
}
 
Example 10
Source File: SystemSettingsCredentialsProvider.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public AwsCredentials resolveCredentials() {
    String accessKey = trim(loadSetting(SdkSystemSetting.AWS_ACCESS_KEY_ID).orElse(null));
    String secretKey = trim(loadSetting(SdkSystemSetting.AWS_SECRET_ACCESS_KEY).orElse(null));
    String sessionToken = trim(loadSetting(SdkSystemSetting.AWS_SESSION_TOKEN).orElse(null));

    if (StringUtils.isEmpty(accessKey)) {
        throw SdkClientException.builder()
                                .message(String.format("Unable to load credentials from system settings. Access key must be" +
                                         " specified either via environment variable (%s) or system property (%s).",
                                         SdkSystemSetting.AWS_ACCESS_KEY_ID.environmentVariable(),
                                         SdkSystemSetting.AWS_ACCESS_KEY_ID.property()))
                                .build();
    }

    if (StringUtils.isEmpty(secretKey)) {
        throw SdkClientException.builder()
                                .message(String.format("Unable to load credentials from system settings. Secret key must be" +
                                         " specified either via environment variable (%s) or system property (%s).",
                                         SdkSystemSetting.AWS_SECRET_ACCESS_KEY.environmentVariable(),
                                         SdkSystemSetting.AWS_SECRET_ACCESS_KEY.property()))
                                .build();
    }

    return sessionToken == null ? AwsBasicCredentials.create(accessKey, secretKey)
                                : AwsSessionCredentials.create(accessKey, secretKey, sessionToken);
}
 
Example 11
Source File: ApplyUserAgentStage.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: ElasticFileSystemIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    if (!StringUtils.isEmpty(fileSystemId)) {
        client.deleteFileSystem(DeleteFileSystemRequest.builder().fileSystemId(fileSystemId).build());
    }
}
 
Example 13
Source File: ProtocolSpec.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
default String hostPrefixExpression(OperationModel opModel) {
    return opModel.getEndpointTrait() != null && !StringUtils.isEmpty(opModel.getEndpointTrait().getHostPrefix())
           ? ".hostPrefixExpression(resolvedHostExpression)\n"
           : "";
}
 
Example 14
Source File: ApplyUserAgentStage.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
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;
}