Skip to content

Commit 9cb352e

Browse files
committed
Added support for the "contentMd5Required" C2J trait, which will inject the "Content-MD5" header when an operation requires it.
This functionality was previously hard-coded to certain operations within S3. It's now driven by a trait, so that Content-MD5 does not get calculated when it isn't needed. Other changes in this commit: 1. Cleaned up some of the code generation poet code around the content-md5-related logic. 2. Added support for empty async XML responses without content-lengths. These would previously throw an exception that they're invalid XML. 3. Fixed an issue where requestBody and asyncRequestBody were not visible in ExecutionInterceptor.afterMarshalling.
1 parent 30660f4 commit 9cb352e

File tree

34 files changed

+1568
-899
lines changed

34 files changed

+1568
-899
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"description": "Fixed an issue where requestBody and asyncRequestBody were not visible in ExecutionInterceptor.afterMarshalling."
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Amazon S3",
4+
"description": "Fixed an issue where metrics were not being collected for Amazon S3 (or other XML services)"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "Amazon S3",
4+
"description": "Moved the logic for calculating the Content-MD5 checksums from s3 to sdk-core. As always, make sure to use a version of 'sdk-core' greater than or equal to your version of 's3'. If you use an old version of 'sdk-core' and a new version of 's3', you will receive errors that Content-MD5 is required."
5+
}

build-tools/src/main/resources/software/amazon/awssdk/spotbugs-suppressions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,11 @@
211211
<Method name="execute"/>
212212
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
213213
</Match>
214+
215+
<!-- For forward-compatibility with this having members (i.e. the checksum type) -->
216+
<Match>
217+
<Class name="software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired"/>
218+
<Method name="create"/>
219+
<Bug pattern="ISC_INSTANTIATE_STATIC_CLASS"/>
220+
</Match>
214221
</FindBugsFilter>

codegen/src/main/java/software/amazon/awssdk/codegen/AddOperations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public Map<String, OperationModel> constructOperations() {
162162
operationModel.setEndpointOperation(op.isEndpointoperation());
163163
operationModel.setEndpointDiscovery(op.getEndpointdiscovery());
164164
operationModel.setEndpointTrait(op.getEndpoint());
165+
operationModel.setHttpChecksumRequired(op.isHttpChecksumRequired());
165166

166167
Input input = op.getInput();
167168
if (input != null) {

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/OperationModel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class OperationModel extends DocumentationModel {
6262

6363
private EndpointTrait endpointTrait;
6464

65+
private boolean httpChecksumRequired;
66+
6567
public String getOperationName() {
6668
return operationName;
6769
}
@@ -272,4 +274,12 @@ private boolean containsEventStream(ShapeModel shapeModel) {
272274
.filter(m -> m.getShape() != null)
273275
.anyMatch(m -> m.getShape().isEventStream());
274276
}
277+
278+
public boolean isHttpChecksumRequired() {
279+
return httpChecksumRequired;
280+
}
281+
282+
public void setHttpChecksumRequired(boolean httpChecksumRequired) {
283+
this.httpChecksumRequired = httpChecksumRequired;
284+
}
275285
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/Operation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class Operation {
4646

4747
private AuthType authtype = AuthType.IAM;
4848

49+
private boolean httpChecksumRequired;
50+
4951
public String getName() {
5052
return name;
5153
}
@@ -164,4 +166,12 @@ public EndpointTrait getEndpoint() {
164166
public void setEndpoint(EndpointTrait endpoint) {
165167
this.endpoint = endpoint;
166168
}
169+
170+
public boolean isHttpChecksumRequired() {
171+
return httpChecksumRequired;
172+
}
173+
174+
public void setHttpChecksumRequired(boolean httpChecksumRequired) {
175+
this.httpChecksumRequired = httpChecksumRequired;
176+
}
167177
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/Ec2ProtocolSpec.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,54 +29,4 @@ public Ec2ProtocolSpec(IntermediateModel model, PoetExtensions poetExtensions) {
2929
protected Class<?> protocolFactoryClass() {
3030
return AwsEc2ProtocolFactory.class;
3131
}
32-
33-
/*
34-
TODO Dry run support
35-
private MethodSpec dryRunMethod() {
36-
TypeVariableName typeVariableName = TypeVariableName.get("X", AmazonWebServiceRequest.class);
37-
ClassName dryRunResult = poetExtensions.getModelClass("DryRunResult");
38-
TypeName dryRunResultGeneric = ParameterizedTypeName.get(dryRunResult, typeVariableName);
39-
ClassName dryRunRequest = poetExtensions.getModelClass("DryRunSupportedRequest");
40-
TypeName dryRunRequestGeneric = ParameterizedTypeName.get(dryRunRequest, typeVariableName);
41-
return MethodSpec.methodBuilder("dryRun")
42-
.returns(dryRunResultGeneric)
43-
.addModifiers(Modifier.PUBLIC)
44-
.addParameter(dryRunRequestGeneric, "request")
45-
.addTypeVariable(typeVariableName)
46-
.addStatement("$T<X> dryRunRequest = request.getDryRunRequest()",
47-
Request.class)
48-
.beginControlFlow("try")
49-
.addStatement("$T<$T> responseHandler = new $T<$T>(new $T())",
50-
StaxResponseHandler.class,
51-
dryRunResult,
52-
StaxResponseHandler.class,
53-
dryRunResult,
54-
VoidStaxUnmarshaller.class)
55-
.addStatement("\nclientHandler.execute(new $T<$T, $T>().marshaller($L).withResponseHandler($N)" +
56-
".withInput($L))",
57-
ClientExecutionParams.class,
58-
Request.class,
59-
dryRunResult,
60-
"null",
61-
"responseHandler",
62-
"dryRunRequest")
63-
.addStatement("throw new $T($S)", SdkClientException.class,
64-
"Unrecognized service response for the dry-run request.")
65-
.endControlFlow()
66-
.beginControlFlow("catch (AwsServiceException exception)")
67-
.beginControlFlow("if (exception.errorCode().equals($S) && exception.statusCode() == 412)",
68-
"DryRunOperation")
69-
.addStatement("return new $T(true, request, exception.getMessage(), exception)", dryRunResultGeneric)
70-
.endControlFlow()
71-
.beginControlFlow("else if (exception.errorCode().equals($S) && exception.statusCode() == 403)",
72-
"UnauthorizedOperation")
73-
.addStatement("return new $T(false, request, exception.getMessage(), exception)", dryRunResultGeneric)
74-
.endControlFlow()
75-
.addStatement("throw new $T($S, exception)", SdkClientException.class,
76-
"Unrecognized service response for the dry-run request.")
77-
.endControlFlow()
78-
.build();
79-
80-
}
81-
*/
8232
}

0 commit comments

Comments
 (0)