Skip to content

Use standardized REST-JSON behavior #2783

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 5 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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-47e105f.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": "Update the REST-JSON marshalling logic to conform to the standard expected behavior WRT to the `Content-Type` of the request."
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,17 @@ public List<MemberModel> getUnboundMembers() {
List<MemberModel> unboundMembers = new ArrayList<>();
if (members != null) {
for (MemberModel member : members) {
if (member.getHttp().getLocation() == null) {
if (member.getHttp().getLocation() == null && !member.getHttp().getIsPayload()) {
if (hasPayloadMember) {
// There is an explicit payload, but this unbound
// member isn't it.
// Note: Somewhat unintuitive, explicit payloads don't
// have an explicit location; they're identified by
// the payload HTTP trait being true.
throw new IllegalStateException(String.format(
"C2J Shape %s has both an explicit payload member and unbound (no explicit location) members. "
+ "This is undefined behavior, verify the correctness of the C2J model", c2jName));
"C2J Shape %s has both an explicit payload member and unbound (no explicit location) member, %s."
+ " This is undefined behavior, verify the correctness of the C2J model.",
c2jName, member.getName()));
}
unboundMembers.add(member);
}
Expand Down Expand Up @@ -221,7 +227,12 @@ public List<MemberModel> getUnboundEventMembers() {
public boolean hasPayloadMembers() {
return hasPayloadMember ||
getExplicitEventPayloadMember() != null ||
!getUnboundMembers().isEmpty() ||
hasImplicitPayloadMembers();

}

public boolean hasImplicitPayloadMembers() {
return !getUnboundMembers().isEmpty() ||
(isEvent() && !getUnboundEventMembers().isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected FieldSpec operationInfoField() {
.add(".httpMethod($T.$L)", SdkHttpMethod.class, shapeModel.getMarshaller().getVerb())
.add(".hasExplicitPayloadMember($L)", shapeModel.isHasPayloadMember() ||
shapeModel.getExplicitEventPayloadMember() != null)
.add(".hasImplicitPayloadMembers($L)", shapeModel.hasImplicitPayloadMembers())
.add(".hasPayloadMembers($L)", shapeModel.hasPayloadMembers());

if (StringUtils.isNotBlank(shapeModel.getMarshaller().getTarget())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@SdkInternalApi
public class AllTypesRequestMarshaller implements Marshaller<AllTypesRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder().requestUri("/")
.httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false).hasPayloadMembers(true).build();
.httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false).hasImplicitPayloadMembers(true)
.hasPayloadMembers(true).build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -32,11 +33,10 @@ public SdkHttpFullRequest marshall(AllTypesRequest allTypesRequest) {
Validate.paramNotNull(allTypesRequest, "allTypesRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(allTypesRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@SdkInternalApi
public class EventStreamOperationRequestMarshaller implements Marshaller<EventStreamOperationRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder()
.requestUri("/2016-03-11/eventStreamOperation").httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(true)
.hasPayloadMembers(true).hasEventStreamingInput(true).build();
.requestUri("/2016-03-11/eventStreamOperation").httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(true)
.hasImplicitPayloadMembers(false).hasPayloadMembers(true).hasEventStreamingInput(true).build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -33,7 +33,7 @@ public SdkHttpFullRequest marshall(EventStreamOperationRequest eventStreamOperat
Validate.paramNotNull(eventStreamOperationRequest, "eventStreamOperationRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(eventStreamOperationRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
public class EventStreamOperationWithOnlyInputRequestMarshaller implements
Marshaller<EventStreamOperationWithOnlyInputRequest> {
public class EventStreamOperationWithOnlyInputRequestMarshaller implements Marshaller<EventStreamOperationWithOnlyInputRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder()
.requestUri("/2016-03-11/EventStreamOperationWithOnlyInput").httpMethod(SdkHttpMethod.POST)
.hasExplicitPayloadMember(false).hasPayloadMembers(true).hasEventStreamingInput(true).build();
.requestUri("/2016-03-11/EventStreamOperationWithOnlyInput").httpMethod(SdkHttpMethod.POST)
.hasExplicitPayloadMember(false).hasImplicitPayloadMembers(true).hasPayloadMembers(true).hasEventStreamingInput(true)
.build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -34,11 +34,10 @@ public SdkHttpFullRequest marshall(EventStreamOperationWithOnlyInputRequest even
Validate.paramNotNull(eventStreamOperationWithOnlyInputRequest, "eventStreamOperationWithOnlyInputRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(eventStreamOperationWithOnlyInputRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@SdkInternalApi
public class NestedContainersRequestMarshaller implements Marshaller<NestedContainersRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder().requestUri("/")
.httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false).hasPayloadMembers(true).build();
.httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false).hasImplicitPayloadMembers(true)
.hasPayloadMembers(true).build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -32,11 +33,10 @@ public SdkHttpFullRequest marshall(NestedContainersRequest nestedContainersReque
Validate.paramNotNull(nestedContainersRequest, "nestedContainersRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(nestedContainersRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
public class OperationWithNoInputOrOutputRequestMarshaller implements
Marshaller<OperationWithNoInputOrOutputRequest> {
public class OperationWithNoInputOrOutputRequestMarshaller implements Marshaller<OperationWithNoInputOrOutputRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder().requestUri("/")
.httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false).hasPayloadMembers(false).build();
.httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false).hasImplicitPayloadMembers(false)
.hasPayloadMembers(false).build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -33,11 +33,10 @@ public SdkHttpFullRequest marshall(OperationWithNoInputOrOutputRequest operation
Validate.paramNotNull(operationWithNoInputOrOutputRequest, "operationWithNoInputOrOutputRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(operationWithNoInputOrOutputRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@SdkInternalApi
public class StreamingInputOperationRequestMarshaller implements Marshaller<StreamingInputOperationRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder()
.requestUri("/2016-03-11/streamingInputOperation").httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(true)
.hasPayloadMembers(true).hasStreamingInput(true).build();
.requestUri("/2016-03-11/streamingInputOperation").httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(true)
.hasImplicitPayloadMembers(false).hasPayloadMembers(true).hasStreamingInput(true).build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -33,11 +33,10 @@ public SdkHttpFullRequest marshall(StreamingInputOperationRequest streamingInput
Validate.paramNotNull(streamingInputOperationRequest, "streamingInputOperationRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(streamingInputOperationRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@SdkInternalApi
public class StreamingOutputOperationRequestMarshaller implements Marshaller<StreamingOutputOperationRequest> {
private static final OperationInfo SDK_OPERATION_BINDING = OperationInfo.builder()
.requestUri("/2016-03-11/streamingOutputOperation").httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false)
.hasPayloadMembers(false).build();
.requestUri("/2016-03-11/streamingOutputOperation").httpMethod(SdkHttpMethod.POST).hasExplicitPayloadMember(false)
.hasImplicitPayloadMembers(false).hasPayloadMembers(false).build();

private final BaseAwsJsonProtocolFactory protocolFactory;

Expand All @@ -33,11 +33,10 @@ public SdkHttpFullRequest marshall(StreamingOutputOperationRequest streamingOutp
Validate.paramNotNull(streamingOutputOperationRequest, "streamingOutputOperationRequest");
try {
ProtocolMarshaller<SdkHttpFullRequest> protocolMarshaller = protocolFactory
.createProtocolMarshaller(SDK_OPERATION_BINDING);
.createProtocolMarshaller(SDK_OPERATION_BINDING);
return protocolMarshaller.marshall(streamingOutputOperationRequest);
} catch (Exception e) {
throw SdkClientException.builder().message("Unable to marshall request to JSON: " + e.getMessage()).cause(e).build();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
@SdkProtectedApi
public class DefaultJsonContentTypeResolver implements JsonContentTypeResolver {
private static final String REST_JSON_CONTENT_TYPE = "application/json";

private final String prefix;

Expand All @@ -32,7 +33,9 @@ public DefaultJsonContentTypeResolver(String prefix) {

@Override
public String resolveContentType(AwsJsonProtocolMetadata protocolMetadata) {
//Changing this to 'application/json' may break clients expecting 'application/x-amz-json-1.1'
if (AwsJsonProtocol.REST_JSON.equals(protocolMetadata.protocol())) {
return REST_JSON_CONTENT_TYPE;
}
return prefix + protocolMetadata.protocolVersion();
}
}
Loading