diff --git a/core/sdk-core/src/main/java/software/amazon/awssdk/core/checksums/Algorithm.java b/core/sdk-core/src/main/java/software/amazon/awssdk/core/checksums/Algorithm.java index cd2b0d7303c1..46813da33da5 100644 --- a/core/sdk-core/src/main/java/software/amazon/awssdk/core/checksums/Algorithm.java +++ b/core/sdk-core/src/main/java/software/amazon/awssdk/core/checksums/Algorithm.java @@ -32,7 +32,8 @@ public enum Algorithm { SHA1("sha1", 28), ; - private static final Map VALUE_MAP = EnumUtils.uniqueIndex(Algorithm.class, Algorithm::toString); + private static final Map VALUE_MAP = EnumUtils.uniqueIndex(Algorithm.class, + a -> StringUtils.upperCase(a.value)); private final String value; private final int length; @@ -46,12 +47,17 @@ public static Algorithm fromValue(String value) { if (value == null) { return null; } - String normalizedValue = StringUtils.lowerCase(value); - Algorithm algorithm = VALUE_MAP.get(normalizedValue); + // The clients will send the algorithm name in all upper case + // try using that name directly and if not found then normalize + // it and try again. + Algorithm algorithm = VALUE_MAP.get(value); if (algorithm == null) { - throw new IllegalArgumentException("The provided value is not a valid algorithm " + value); + String normalizedValue = StringUtils.upperCase(value); + algorithm = VALUE_MAP.get(normalizedValue); + if (algorithm == null) { + throw new IllegalArgumentException("The provided value is not a valid algorithm " + value); + } } - return algorithm; } diff --git a/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/HttpChecksumResolver.java b/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/HttpChecksumResolver.java index 86954a67e405..c204c7a4fc4e 100644 --- a/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/HttpChecksumResolver.java +++ b/core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/HttpChecksumResolver.java @@ -15,9 +15,8 @@ package software.amazon.awssdk.core.internal.util; +import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.checksums.Algorithm; import software.amazon.awssdk.core.checksums.ChecksumSpecs; @@ -25,7 +24,6 @@ import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute; import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; import software.amazon.awssdk.core.interceptor.trait.HttpChecksum; -import software.amazon.awssdk.utils.StringUtils; /** * Class to resolve the different Checksums specs from ExecutionAttributes. @@ -37,8 +35,11 @@ private HttpChecksumResolver() { } public static ChecksumSpecs getResolvedChecksumSpecs(ExecutionAttributes executionAttributes) { - return Optional.ofNullable(executionAttributes.getAttribute(SdkExecutionAttribute.RESOLVED_CHECKSUM_SPECS)) - .orElseGet(() -> resolveChecksumSpecs(executionAttributes)); + ChecksumSpecs checksumSpecs = executionAttributes.getAttribute(SdkExecutionAttribute.RESOLVED_CHECKSUM_SPECS); + if (checksumSpecs != null) { + return checksumSpecs; + } + return resolveChecksumSpecs(executionAttributes); } public static ChecksumSpecs resolveChecksumSpecs(ExecutionAttributes executionAttributes) { @@ -47,9 +48,8 @@ public static ChecksumSpecs resolveChecksumSpecs(ExecutionAttributes executionAt return null; } boolean hasRequestValidation = hasRequestValidationMode(httpChecksumTraitInOperation); - String checksumHeaderName = httpChecksumTraitInOperation.requestAlgorithm() != null ? - HttpChecksumUtils.httpChecksumHeader(httpChecksumTraitInOperation.requestAlgorithm()) - : null; + String requestAlgorithm = httpChecksumTraitInOperation.requestAlgorithm(); + String checksumHeaderName = requestAlgorithm != null ? HttpChecksumUtils.httpChecksumHeader(requestAlgorithm) : null; List responseValidationAlgorithms = getResponseValidationAlgorithms(httpChecksumTraitInOperation); return ChecksumSpecs.builder() @@ -67,16 +67,14 @@ private static boolean hasRequestValidationMode(HttpChecksum httpChecksum) { } private static List getResponseValidationAlgorithms(HttpChecksum httpChecksumTraitInOperation) { - List responseValidationAlgorithms = null; - - if (httpChecksumTraitInOperation.responseAlgorithms() != null && - !httpChecksumTraitInOperation.responseAlgorithms().isEmpty()) { - responseValidationAlgorithms = - httpChecksumTraitInOperation.responseAlgorithms().stream().filter(StringUtils::isNotBlank) - .map(StringUtils::trim) - .map(Algorithm::fromValue) - .collect(Collectors.toList()); + List responseAlgorithms = httpChecksumTraitInOperation.responseAlgorithms(); + if (responseAlgorithms != null && !responseAlgorithms.isEmpty()) { + List responseValidationAlgorithms = new ArrayList<>(responseAlgorithms.size()); + for (String algorithmName : responseAlgorithms) { + responseValidationAlgorithms.add(Algorithm.fromValue(algorithmName)); + } + return responseValidationAlgorithms; } - return responseValidationAlgorithms; + return null; } }