Skip to content

Commit f58cb75

Browse files
committed
Including extended request id in event stream response
1 parent b716379 commit f58cb75

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core/aws-core/src/main/java/software/amazon/awssdk/awscore/eventstream/EventStreamAsyncResponseTransformer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.awscore.eventstream;
1717

1818
import static software.amazon.awssdk.core.http.HttpResponseHandler.X_AMZN_REQUEST_ID_HEADER;
19+
import static software.amazon.awssdk.core.http.HttpResponseHandler.X_AMZ_ID_2_HEADER;
1920
import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError;
2021

2122
import java.io.ByteArrayInputStream;
@@ -156,6 +157,13 @@ public class EventStreamAsyncResponseTransformer<ResponseT, EventT>
156157
*/
157158
private String requestId = null;
158159

160+
/**
161+
* Extended Request Id for the streaming request. The value is populated when the initial response is received from the
162+
* service. As request id is not sent in event messages (including exceptions), this can be returned by the SDK along with
163+
* received exception details.
164+
*/
165+
private String extendedRequestId = null;
166+
159167
@Deprecated
160168
@ReviewBeforeRelease("Remove this on full GA of 2.0.0")
161169
public EventStreamAsyncResponseTransformer(
@@ -194,6 +202,9 @@ public void responseReceived(SdkResponse response) {
194202
this.requestId = response.sdkHttpResponse()
195203
.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER)
196204
.orElse(null);
205+
this.extendedRequestId = response.sdkHttpResponse()
206+
.firstMatchingHeader(X_AMZ_ID_2_HEADER)
207+
.orElse(null);
197208
}
198209
}
199210

@@ -324,6 +335,9 @@ private HttpResponse adaptMessageToResponse(Message m, boolean isException) {
324335
if (requestId != null) {
325336
response.addHeader(X_AMZN_REQUEST_ID_HEADER, requestId);
326337
}
338+
if (extendedRequestId != null) {
339+
response.addHeader(X_AMZ_ID_2_HEADER, extendedRequestId);
340+
}
327341

328342
//TODO: fix the hard-coded status code
329343
response.setStatusCode(isException ? 500 : 200);

core/sdk-core/src/main/java/software/amazon/awssdk/core/http/HttpResponseHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public interface HttpResponseHandler<T> {
3333

3434
String X_AMZN_REQUEST_ID_HEADER = "x-amzn-RequestId";
3535

36+
String X_AMZ_ID_2_HEADER = "x-amz-id-2";
37+
3638
/**
3739
* Accepts an HTTP response object, and returns an object of type T.
3840
* Individual implementations may choose to handle the response however they

0 commit comments

Comments
 (0)