in sdk/greengrass/event-stream-rpc-client/src/main/java/software/amazon/awssdk/eventstreamrpc/EventStreamRPCClient.java [217:260]
void handleData(String applicationModelType, byte[] payload, boolean isInitial, CompletableFuture<RespType> responseFuture,
final Optional<StreamResponseHandler<StrRespType>> streamResponseHandler,
final OperationModelContext<?, RespType, ?, StrRespType> operationModelContext,
ClientConnectionContinuation continuation,
final AtomicBoolean isClosed) {
if (isInitial) {
//mismatch between type on the wire and type expected by the operation
if (!applicationModelType.equals(operationModelContext.getResponseApplicationModelType())) {
handleError(new UnmappedDataException(applicationModelType, operationModelContext.getResponseTypeClass()),
isInitial, responseFuture, streamResponseHandler, continuation, isClosed);
return;
}
RespType responseObj = null;
try {
responseObj = operationModelContext.getServiceModel().fromJson(operationModelContext.getResponseTypeClass(), payload);
} catch (Exception e) {
handleError(new DeserializationException(payload, e), isInitial, responseFuture, streamResponseHandler, continuation, isClosed);
return; //we're done if we can't deserialize
}
//complete normally
responseFuture.complete(responseObj);
} else {
//mismatch between type on the wire and type expected by the operation
if (!applicationModelType.equals(operationModelContext.getStreamingResponseApplicationModelType().get())) {
handleError(new UnmappedDataException(applicationModelType, operationModelContext.getStreamingResponseTypeClass().get()),
isInitial, responseFuture, streamResponseHandler, continuation, isClosed);
return;
}
StrRespType strResponseObj = null;
try {
strResponseObj = operationModelContext.getServiceModel().fromJson(
operationModelContext.getStreamingResponseTypeClass().get(), payload);
} catch (Exception e) {
handleError(new DeserializationException(payload, e), isInitial, responseFuture, streamResponseHandler, continuation, isClosed);
return; //we're done if we can't deserialize
}
try {
streamResponseHandler.get().onStreamEvent(strResponseObj);
} catch (Exception e) {
handleError(e, isInitial, responseFuture, streamResponseHandler, continuation, isClosed);
}
}
}