in sdk/src/main/java/software/amazon/awssdk/iot/iotshadow/IotShadowV2Client.java [352:411]
public CompletableFuture<UpdateShadowResponse> updateNamedShadow(UpdateNamedShadowRequest request) {
V2ClientFuture<UpdateShadowResponse> responseFuture = new V2ClientFuture<>();
try {
if (request.thingName == null) {
throw new CrtRuntimeException("UpdateNamedShadowRequest.thingName cannot be null");
}
if (request.shadowName == null) {
throw new CrtRuntimeException("UpdateNamedShadowRequest.shadowName cannot be null");
}
RequestResponseOperation.RequestResponseOperationBuilder builder = RequestResponseOperation.builder();
// Correlation Token
String correlationToken = UUID.randomUUID().toString();
request.clientToken = correlationToken;
builder.withCorrelationToken(correlationToken);
// Publish Topic
String publishTopic = "$aws/things/{thingName}/shadow/name/{shadowName}/update";
publishTopic = publishTopic.replace("{thingName}", request.thingName);
publishTopic = publishTopic.replace("{shadowName}", request.shadowName);
builder.withPublishTopic(publishTopic);
// Payload
String payloadJson = gson.toJson(request);
builder.withPayload(payloadJson.getBytes(StandardCharsets.UTF_8));
// Subscriptions
String subscription0 = "$aws/things/{thingName}/shadow/name/{shadowName}/update/accepted";
subscription0 = subscription0.replace("{thingName}", request.thingName);
subscription0 = subscription0.replace("{shadowName}", request.shadowName);
builder.withSubscription(subscription0);
String subscription1 = "$aws/things/{thingName}/shadow/name/{shadowName}/update/rejected";
subscription1 = subscription1.replace("{thingName}", request.thingName);
subscription1 = subscription1.replace("{shadowName}", request.shadowName);
builder.withSubscription(subscription1);
// Response paths
ResponsePath.ResponsePathBuilder pathBuilder1 = ResponsePath.builder();
String responseTopic1 = publishTopic + "/accepted";
pathBuilder1.withResponseTopic(publishTopic + "/accepted");
pathBuilder1.withCorrelationTokenJsonPath("clientToken");
builder.withResponsePath(pathBuilder1.build());
ResponsePath.ResponsePathBuilder pathBuilder2 = ResponsePath.builder();
String responseTopic2 = publishTopic + "/rejected";
pathBuilder2.withResponseTopic(publishTopic + "/rejected");
pathBuilder2.withCorrelationTokenJsonPath("clientToken");
builder.withResponsePath(pathBuilder2.build());
// Submit
submitOperation(responseFuture, builder.build(), responseTopic1, UpdateShadowResponse.class, responseTopic2, V2ErrorResponse.class, IotShadowV2Client::createV2ErrorResponseException);
} catch (Exception e) {
responseFuture.completeExceptionally(createV2ErrorResponseException(e.getMessage(), null));
}
return responseFuture;
}