24
24
import software .amazon .awssdk .annotations .SdkProtectedApi ;
25
25
import software .amazon .awssdk .awscore .protocol .xml .StaxUnmarshallerContext ;
26
26
import software .amazon .awssdk .awscore .protocol .xml .VoidStaxUnmarshaller ;
27
- import software .amazon .awssdk .core .ResponseMetadata ;
27
+ import software .amazon .awssdk .core .SdkResponse ;
28
+ import software .amazon .awssdk .core .SdkResponseMetadata ;
28
29
import software .amazon .awssdk .core .SdkStandardLoggers ;
29
30
import software .amazon .awssdk .core .async .AsyncResponseTransformer ;
30
31
import software .amazon .awssdk .core .http .HttpResponse ;
45
46
* @param <T> Indicates the type being unmarshalled by this response handler.
46
47
*/
47
48
@ SdkProtectedApi
48
- @ ReviewBeforeRelease ("Metadata is currently broken. Revisit when base result types are refactored" )
49
- public class StaxResponseHandler <T > implements HttpResponseHandler <T > {
49
+ @ ReviewBeforeRelease ("ResponseMetadata is currently broken. Revisit when base result types are refactored" )
50
+ public class StaxResponseHandler <T extends SdkResponse > implements HttpResponseHandler <T > {
50
51
private static final Logger log = Logger .loggerFor (StaxResponseHandler .class );
51
52
52
53
/**
@@ -73,7 +74,7 @@ public StaxResponseHandler(Unmarshaller<T, StaxUnmarshallerContext> responseUnma
73
74
* don't have to do this check here.
74
75
*/
75
76
if (this .responseUnmarshaller == null ) {
76
- this .responseUnmarshaller = new VoidStaxUnmarshaller <T >();
77
+ this .responseUnmarshaller = new VoidStaxUnmarshaller <>();
77
78
}
78
79
}
79
80
@@ -92,8 +93,8 @@ public T handle(HttpResponse response, ExecutionAttributes executionAttributes)
92
93
93
94
try {
94
95
StaxUnmarshallerContext unmarshallerContext = new StaxUnmarshallerContext (eventReader , response .getHeaders ());
95
- unmarshallerContext .registerMetadataExpression ("ResponseMetadata/RequestId" , 2 , ResponseMetadata .AWS_REQUEST_ID );
96
- unmarshallerContext .registerMetadataExpression ("requestId" , 2 , ResponseMetadata .AWS_REQUEST_ID );
96
+ unmarshallerContext .registerMetadataExpression ("ResponseMetadata/RequestId" , 2 , SdkResponseMetadata .AWS_REQUEST_ID );
97
+ unmarshallerContext .registerMetadataExpression ("requestId" , 2 , SdkResponseMetadata .AWS_REQUEST_ID );
97
98
registerAdditionalMetadataExpressions (unmarshallerContext );
98
99
99
100
T result = responseUnmarshaller .unmarshall (unmarshallerContext );
@@ -111,11 +112,11 @@ public T handle(HttpResponse response, ExecutionAttributes executionAttributes)
111
112
}
112
113
113
114
/**
114
- * Create the default {@link ResponseMetadata }. Subclasses may override this to create a
115
- * subclass of {@link ResponseMetadata }. Currently only SimpleDB does this.
115
+ * Create the default {@link SdkResponseMetadata }. Subclasses may override this to create a
116
+ * subclass of {@link SdkResponseMetadata }. Currently only SimpleDB does this.
116
117
*/
117
- protected ResponseMetadata getResponseMetadata (Map <String , String > metadata ) {
118
- return new ResponseMetadata (metadata );
118
+ protected SdkResponseMetadata getResponseMetadata (Map <String , String > metadata ) {
119
+ return new SdkResponseMetadata (metadata );
119
120
}
120
121
121
122
/**
@@ -147,7 +148,7 @@ public boolean needsConnectionLeftOpen() {
147
148
* @param unmarshaller Unmarshaller for response POJO.
148
149
* @param <ResponseT> Response POJO type.
149
150
*/
150
- public static <ResponseT > HttpResponseHandler <ResponseT > createStreamingResponseHandler (
151
+ public static <ResponseT extends SdkResponse > HttpResponseHandler <ResponseT > createStreamingResponseHandler (
151
152
Unmarshaller <ResponseT , StaxUnmarshallerContext > unmarshaller ) {
152
153
UnsafeFunction <HttpResponse , ResponseT > unmarshallFunction = response -> unmarshallStreaming (unmarshaller , response );
153
154
return new HttpResponseHandler <ResponseT >() {
@@ -173,16 +174,16 @@ public boolean needsConnectionLeftOpen() {
173
174
* @return Unmarshalled response type.
174
175
* @throws Exception if error occurs during unmarshalling.
175
176
*/
176
- private static <ResponseT > ResponseT unmarshallStreaming (Unmarshaller <ResponseT , StaxUnmarshallerContext > unmarshaller ,
177
- HttpResponse response ) throws Exception {
177
+ private static <ResponseT extends SdkResponse > ResponseT unmarshallStreaming (Unmarshaller <ResponseT ,
178
+ StaxUnmarshallerContext > unmarshaller , HttpResponse response ) throws Exception {
178
179
// Create a dummy event reader to make unmarshallers happy
179
180
XMLEventReader eventReader = XmlUtils .xmlInputFactory ().createXMLEventReader (
180
181
new ByteArrayInputStream ("<eof/>" .getBytes (StringUtils .UTF8 )));
181
182
182
183
StaxUnmarshallerContext unmarshallerContext = new StaxUnmarshallerContext (eventReader , response .getHeaders ());
183
- unmarshallerContext .registerMetadataExpression ("ResponseMetadata/RequestId" , 2 , ResponseMetadata .AWS_REQUEST_ID );
184
- unmarshallerContext .registerMetadataExpression ("requestId" , 2 , ResponseMetadata .AWS_REQUEST_ID );
184
+ unmarshallerContext .registerMetadataExpression ("ResponseMetadata/RequestId" , 2 , SdkResponseMetadata .AWS_REQUEST_ID );
185
+ unmarshallerContext .registerMetadataExpression ("requestId" , 2 , SdkResponseMetadata .AWS_REQUEST_ID );
186
+
185
187
return unmarshaller .unmarshall (unmarshallerContext );
186
188
}
187
-
188
189
}
0 commit comments