Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public class RestJson1ProtocolTests {
@HttpClientRequestTests
@ProtocolTestFilter(
skipTests = {
// TODO: These tests require a payload even when the httpPayload member is null. Should it?
"RestJsonHttpWithHeadersButNoPayload",
"RestJsonHttpWithEmptyStructurePayload",
"RestJsonHttpEmptyPrefixHeadersRequestClient" //FIXME https://github.com/smithy-lang/smithy-java/issues/647
})
public void requestTest(DataStream expected, DataStream actual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.java.aws.client.restjson;

import java.net.URI;
import software.amazon.smithy.aws.traits.protocols.RestJson1Trait;
import software.amazon.smithy.java.aws.events.AwsEventDecoderFactory;
import software.amazon.smithy.java.aws.events.AwsEventEncoderFactory;
Expand All @@ -17,14 +18,20 @@
import software.amazon.smithy.java.client.http.binding.HttpBindingClientProtocol;
import software.amazon.smithy.java.client.http.binding.HttpBindingErrorFactory;
import software.amazon.smithy.java.context.Context;
import software.amazon.smithy.java.core.schema.ApiOperation;
import software.amazon.smithy.java.core.schema.InputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.OutputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.SerializableStruct;
import software.amazon.smithy.java.core.schema.TraitKey;
import software.amazon.smithy.java.core.serde.Codec;
import software.amazon.smithy.java.core.serde.event.EventDecoderFactory;
import software.amazon.smithy.java.core.serde.event.EventEncoderFactory;
import software.amazon.smithy.java.core.serde.event.EventStreamingException;
import software.amazon.smithy.java.http.api.HttpRequest;
import software.amazon.smithy.java.io.datastream.DataStream;
import software.amazon.smithy.java.json.JsonCodec;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.ShapeType;

/**
* Implements aws.protocols#restJson1.
Expand Down Expand Up @@ -55,6 +62,32 @@ public RestJsonClientProtocol(ShapeId service) {
.build();
}

@Override
public <I extends SerializableStruct, O extends SerializableStruct> HttpRequest createRequest(
ApiOperation<I, O> operation,
I input,
Context context,
URI endpoint
) {
HttpRequest request = super.createRequest(operation, input, context, endpoint);

if (request.body().contentLength() == 0) {
var payloadMember = input.schema()
.members()
.stream()
.filter(m -> m.hasTrait(TraitKey.HTTP_PAYLOAD_TRAIT))
.findFirst();
if (payloadMember.isPresent() && payloadMember.get().type().equals(ShapeType.STRUCTURE)) {
return request.toBuilder()
.body(DataStream.ofString("{}"))
.withAddedHeader("Content-Type", "application/json")
.build();
}
}

return request;
}

@Override
public Codec payloadCodec() {
return codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public HttpRequest serializeRequest() {
Objects.requireNonNull(operation, "operation is not set");
Objects.requireNonNull(payloadCodec, "payloadCodec is not set");
Objects.requireNonNull(endpoint, "endpoint is not set");
Objects.requireNonNull(shapeValue, "value is not set");
Objects.requireNonNull(payloadMediaType, "payloadMediaType is not set");

var matcher = bindingCache.computeIfAbsent(operation.inputSchema(), BindingMatcher::requestMatcher);
Expand Down