Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import java.util.Objects;
import java.util.function.Supplier;
import software.amazon.smithy.java.core.schema.InputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.OutputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.ApiOperation;
import software.amazon.smithy.java.core.schema.Schema;
import software.amazon.smithy.java.core.schema.SerializableStruct;
import software.amazon.smithy.java.core.schema.ShapeBuilder;
Expand Down Expand Up @@ -60,8 +59,9 @@ private AwsEventDecoderFactory(
* @param <IE> The output event type
* @return A new event decoder factory
*/
@SuppressWarnings("unchecked")
public static <IE extends SerializableStruct> AwsEventDecoderFactory<IE, ?> forInputStream(
InputEventStreamingApiOperation<?, ?, IE> operation,
ApiOperation<?, ?> operation,
Codec codec,
FrameTransformer<AwsEventFrame> transformer
) {
Expand All @@ -70,7 +70,7 @@ private AwsEventDecoderFactory(
operation::inputBuilder,
operation.inputStreamMember(),
codec,
operation.inputEventBuilderSupplier(),
(Supplier<ShapeBuilder<IE>>) (Supplier<?>) operation.inputEventBuilderSupplier(),
transformer);
}

Expand All @@ -83,8 +83,9 @@ private AwsEventDecoderFactory(
* @param <OE> The output event type
* @return A new event decoder factory
*/
@SuppressWarnings("unchecked")
public static <OE extends SerializableStruct> AwsEventDecoderFactory<OE, ?> forOutputStream(
OutputEventStreamingApiOperation<?, ?, OE> operation,
ApiOperation<?, ?> operation,
Codec codec,
FrameTransformer<AwsEventFrame> transformer
) {
Expand All @@ -93,7 +94,7 @@ private AwsEventDecoderFactory(
operation::outputBuilder,
operation.outputStreamMember(),
codec,
operation.outputEventBuilderSupplier(),
(Supplier<ShapeBuilder<OE>>) (Supplier<?>) operation.outputEventBuilderSupplier(),
transformer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import java.util.Objects;
import java.util.function.Function;
import software.amazon.smithy.java.core.schema.InputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.OutputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.ApiOperation;
import software.amazon.smithy.java.core.schema.Schema;
import software.amazon.smithy.java.core.serde.Codec;
import software.amazon.smithy.java.core.serde.event.EventEncoder;
Expand Down Expand Up @@ -54,7 +53,7 @@ private AwsEventEncoderFactory(
* @return A new event encoder factory
*/
public static AwsEventEncoderFactory forInputStream(
InputEventStreamingApiOperation<?, ?, ?> operation,
ApiOperation<?, ?> operation,
Codec codec,
String payloadMediaType,
FrameTransformer<AwsEventFrame> transformer,
Expand All @@ -78,7 +77,7 @@ public static AwsEventEncoderFactory forInputStream(
* @return A new event encoder factory
*/
public static AwsEventEncoderFactory forOutputStream(
OutputEventStreamingApiOperation<?, ?, ?> operation,
ApiOperation<?, ?> operation,
Codec codec,
String payloadMediaType,
FrameTransformer<AwsEventFrame> transformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

import java.nio.charset.StandardCharsets;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;
import software.amazon.eventstream.Message;
import software.amazon.smithy.java.aws.events.model.BodyAndHeaderEvent;
Expand Down Expand Up @@ -143,10 +144,11 @@ public void testDecodeStringMember() {
assertEquals(expected, actual);
}

@SuppressWarnings("unchecked")
static AwsEventShapeDecoder<?, ?> createDecoder() {
return new AwsEventShapeDecoder<>(InitialEventType.INITIAL_RESPONSE,
() -> TestOperation.instance().outputBuilder(), // output builder
TestOperation.instance().outputEventBuilderSupplier(),
(Supplier) TestOperation.instance().outputEventBuilderSupplier(),
TestOperation.instance().outputStreamMember(),
createJsonCodec());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

import java.util.List;
import java.util.function.Supplier;
import software.amazon.smithy.java.core.schema.ApiOperation;
import software.amazon.smithy.java.core.schema.ApiService;
import software.amazon.smithy.java.core.schema.InputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.OutputEventStreamingApiOperation;
import software.amazon.smithy.java.core.schema.Schema;
import software.amazon.smithy.java.core.schema.SerializableStruct;
import software.amazon.smithy.java.core.schema.ShapeBuilder;
import software.amazon.smithy.java.core.serde.TypeRegistry;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.utils.SmithyGenerated;

@SmithyGenerated
public final class TestOperation
implements InputEventStreamingApiOperation<TestOperationInput, TestOperationOutput, TestEventStream>,
OutputEventStreamingApiOperation<TestOperationInput, TestOperationOutput, TestEventStream> {
implements ApiOperation<TestOperationInput, TestOperationOutput> {

private static final TestOperation $INSTANCE = new TestOperation();

Expand Down Expand Up @@ -51,7 +50,7 @@ public ShapeBuilder<TestOperationInput> inputBuilder() {
}

@Override
public Supplier<ShapeBuilder<TestEventStream>> inputEventBuilderSupplier() {
public Supplier<ShapeBuilder<? extends SerializableStruct>> inputEventBuilderSupplier() {
return () -> TestEventStream.builder();
}

Expand All @@ -61,7 +60,7 @@ public ShapeBuilder<TestOperationOutput> outputBuilder() {
}

@Override
public Supplier<ShapeBuilder<TestEventStream>> outputEventBuilderSupplier() {
public Supplier<ShapeBuilder<? extends SerializableStruct>> outputEventBuilderSupplier() {
return () -> TestEventStream.builder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
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;
Expand Down Expand Up @@ -79,8 +77,8 @@ public <I extends SerializableStruct, O extends SerializableStruct> HttpRequest
.omitEmptyPayload(omitEmptyPayload())
.allowEmptyStructPayload(hasStructPayload(input));

if (operation instanceof InputEventStreamingApiOperation<?, ?, ?> i) {
serializer.eventEncoderFactory(getEventEncoderFactory(i));
if (operation.inputEventBuilderSupplier() != null) {
serializer.eventEncoderFactory(getEventEncoderFactory(operation));
}

return serializer.serializeRequest();
Expand All @@ -107,23 +105,19 @@ protected boolean omitEmptyPayload() {
}

@Override
protected EventEncoderFactory<AwsEventFrame> getEventEncoderFactory(
InputEventStreamingApiOperation<?, ?, ?> inputOperation
) {
protected EventEncoderFactory<AwsEventFrame> getEventEncoderFactory(ApiOperation<?, ?> operation) {
// TODO: this is where you'd plumb through Sigv4 support, another frame transformer?
return AwsEventEncoderFactory.forInputStream(
inputOperation,
operation,
payloadCodec(),
payloadMediaType(),
FrameTransformer.identity(),
(e) -> new EventStreamingException("InternalServerException", "Internal Server Error"));
}

@Override
protected EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(
OutputEventStreamingApiOperation<?, ?, ?> outputOperation
) {
return AwsEventDecoderFactory.forOutputStream(outputOperation, payloadCodec(), f -> f);
protected EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(ApiOperation<?, ?> operation) {
return AwsEventDecoderFactory.forOutputStream(operation, payloadCodec(), f -> f);
}

private <I extends SerializableStruct> boolean hasStructPayload(I input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import software.amazon.smithy.java.core.error.CallException;
import software.amazon.smithy.java.core.error.ModeledException;
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.serde.Codec;
import software.amazon.smithy.java.core.serde.TypeRegistry;
import software.amazon.smithy.java.core.serde.document.Document;
Expand Down Expand Up @@ -81,23 +79,19 @@ protected HttpErrorDeserializer getErrorDeserializer(Context context) {
}

@Override
protected EventEncoderFactory<AwsEventFrame> getEventEncoderFactory(
InputEventStreamingApiOperation<?, ?, ?> inputOperation
) {
protected EventEncoderFactory<AwsEventFrame> getEventEncoderFactory(ApiOperation<?, ?> operation) {
// TODO: this is where you'd plumb through Sigv4 support, another frame transformer?
return AwsEventEncoderFactory.forInputStream(
inputOperation,
operation,
payloadCodec(),
payloadMediaType(),
FrameTransformer.identity(),
(e) -> new EventStreamingException("InternalServerException", "Internal Server Error"));
}

@Override
protected EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(
OutputEventStreamingApiOperation<?, ?, ?> outputOperation
) {
return AwsEventDecoderFactory.forOutputStream(outputOperation, payloadCodec(), f -> f);
protected EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(ApiOperation<?, ?> operation) {
return AwsEventDecoderFactory.forOutputStream(operation, payloadCodec(), f -> f);
}

private static final HttpErrorDeserializer.ErrorPayloadParser XML_ERROR_PAYLOAD_PARSER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import software.amazon.smithy.java.context.Context;
import software.amazon.smithy.java.core.error.CallException;
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.serde.Codec;
import software.amazon.smithy.java.core.serde.TypeRegistry;
Expand Down Expand Up @@ -55,11 +53,11 @@ protected final HttpBinding httpBinding() {
return httpBinding;
}

protected EventEncoderFactory<F> getEventEncoderFactory(InputEventStreamingApiOperation<?, ?, ?> inputOperation) {
protected EventEncoderFactory<F> getEventEncoderFactory(ApiOperation<?, ?> operation) {
throw new UnsupportedOperationException("This protocol does not support event streaming");
}

protected EventDecoderFactory<F> getEventDecoderFactory(OutputEventStreamingApiOperation<?, ?, ?> outputOperation) {
protected EventDecoderFactory<F> getEventDecoderFactory(ApiOperation<?, ?> operation) {
throw new UnsupportedOperationException("This protocol does not support event streaming");
}

Expand All @@ -78,8 +76,8 @@ public <I extends SerializableStruct, O extends SerializableStruct> HttpRequest
.endpoint(endpoint)
.omitEmptyPayload(omitEmptyPayload());

if (operation instanceof InputEventStreamingApiOperation<?, ?, ?> i) {
serializer.eventEncoderFactory(getEventEncoderFactory(i));
if (operation.inputEventBuilderSupplier() != null) {
serializer.eventEncoderFactory(getEventEncoderFactory(operation));
}

return serializer.serializeRequest();
Expand All @@ -106,8 +104,8 @@ public <I extends SerializableStruct, O extends SerializableStruct> O deserializ
.outputShapeBuilder(outputBuilder)
.response(response);

if (operation instanceof OutputEventStreamingApiOperation<?, ?, ?> o) {
deser.eventDecoderFactory(getEventDecoderFactory(o));
if (operation.outputEventBuilderSupplier() != null) {
deser.eventDecoderFactory(getEventDecoderFactory(operation));
}

deser.deserialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import software.amazon.smithy.java.client.http.HttpErrorDeserializer;
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.Unit;
import software.amazon.smithy.java.core.serde.Codec;
Expand Down Expand Up @@ -82,9 +80,9 @@ public <I extends SerializableStruct, O extends SerializableStruct> HttpRequest
// Top-level Unit types do not get serialized
builder.headers(HttpHeaders.of(headersForEmptyBody()))
.body(DataStream.ofEmpty());
} else if (operation instanceof InputEventStreamingApiOperation<?, ?, ?> i) {
} else if (operation.inputEventBuilderSupplier() != null) {
// Event streaming
var encoderFactory = getEventEncoderFactory(i);
var encoderFactory = getEventEncoderFactory(operation);
var body = RpcEventStreamsUtil.bodyForEventStreaming(encoderFactory, input);
builder.headers(HttpHeaders.of(headersForEventStreaming()))
.body(body);
Expand All @@ -108,8 +106,8 @@ public <I extends SerializableStruct, O extends SerializableStruct> O deserializ
throw errorDeserializer.createError(context, operation, typeRegistry, response);
}

if (operation instanceof OutputEventStreamingApiOperation<I, O, ?> o) {
var eventDecoderFactory = getEventDecoderFactory(o);
if (operation.outputEventBuilderSupplier() != null) {
var eventDecoderFactory = getEventDecoderFactory(operation);
return RpcEventStreamsUtil.deserializeResponse(eventDecoderFactory, bodyDataStream(response));
}

Expand Down Expand Up @@ -154,22 +152,17 @@ private Map<String, List<String>> headersForEventStreaming() {
CONTENT_TYPE);
}

private EventEncoderFactory<AwsEventFrame> getEventEncoderFactory(
InputEventStreamingApiOperation<?, ?, ?> inputOperation
) {

private EventEncoderFactory<AwsEventFrame> getEventEncoderFactory(ApiOperation<?, ?> operation) {
// TODO: this is where you'd plumb through Sigv4 support, another frame transformer?
return AwsEventEncoderFactory.forInputStream(inputOperation,
return AwsEventEncoderFactory.forInputStream(operation,
payloadCodec(),
PAYLOAD_MEDIA_TYPE,
FrameTransformer.identity(),
(e) -> new EventStreamingException("InternalServerException", "Internal Server Error"));
}

private EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(
OutputEventStreamingApiOperation<?, ?, ?> outputOperation
) {
return AwsEventDecoderFactory.forOutputStream(outputOperation, payloadCodec(), f -> f);
private EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(ApiOperation<?, ?> operation) {
return AwsEventDecoderFactory.forOutputStream(operation, payloadCodec(), f -> f);
}

private static ShapeId extractErrorType(Document document, String namespace) {
Expand Down
Loading