Skip to content

Commit 090c10b

Browse files
committed
Updates xml error unmarshalling to look at all request id keys when populating error information
1 parent abf7a2c commit 090c10b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"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"
6+
}

core/protocols/aws-query-protocol/src/main/java/software/amazon/awssdk/protocols/query/internal/unmarshall/AwsXmlErrorUnmarshaller.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.time.Duration;
2121
import java.util.List;
22+
import java.util.Map;
2223
import java.util.Optional;
2324
import java.util.function.Supplier;
2425
import software.amazon.awssdk.annotations.SdkInternalApi;
@@ -27,6 +28,7 @@
2728
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2829
import software.amazon.awssdk.core.SdkBytes;
2930
import software.amazon.awssdk.core.SdkPojo;
31+
import software.amazon.awssdk.core.http.HttpResponseHandler;
3032
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
3133
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
3234
import software.amazon.awssdk.http.SdkHttpFullResponse;
@@ -175,7 +177,16 @@ private String getRequestId(SdkHttpFullResponse response, XmlElement document) {
175177
.orElse(document.getElementByName("RequestID"));
176178
return requestId != null ?
177179
requestId.textContent() :
178-
response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).orElse(null);
180+
matchRequestIdHeaders(response);
181+
}
182+
183+
private String matchRequestIdHeaders(SdkHttpFullResponse response) {
184+
return HttpResponseHandler.X_AMZN_REQUEST_ID_HEADERS.stream()
185+
.map(h -> response.firstMatchingHeader(h))
186+
.filter(Optional::isPresent)
187+
.map(Optional::get)
188+
.findFirst()
189+
.orElse(null);
179190
}
180191

181192
/**

0 commit comments

Comments
 (0)