Skip to content

Updates xml error unmarshalling to look at all request id keys when p… #2764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-a6e2ed8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "bugfix",
"description": "Fixes a bug in XML error unmarshalling where error responses with empty body won't populate the requestId field. Affects Amazon S3 API calls such as Head object"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import software.amazon.awssdk.annotations.SdkInternalApi;
Expand All @@ -27,6 +28,7 @@
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.http.SdkHttpFullResponse;
Expand Down Expand Up @@ -175,7 +177,16 @@ private String getRequestId(SdkHttpFullResponse response, XmlElement document) {
.orElse(document.getElementByName("RequestID"));
return requestId != null ?
requestId.textContent() :
response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).orElse(null);
matchRequestIdHeaders(response);
}

private String matchRequestIdHeaders(SdkHttpFullResponse response) {
return HttpResponseHandler.X_AMZN_REQUEST_ID_HEADERS.stream()
.map(h -> response.firstMatchingHeader(h))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse(null);
}

/**
Expand Down