use of software.amazon.awssdk.services.sns.model.PublishResponse in project beam by apache.
the class SnsResponse method of.
public static <T> SnsResponse<T> of(@NonNull T element, @Nullable PublishResponse response) {
final Optional<PublishResponse> publishResponse = Optional.ofNullable(response);
OptionalInt statusCode = publishResponse.map(r -> OptionalInt.of(r.sdkHttpResponse().statusCode())).orElse(OptionalInt.empty());
Optional<String> statusText = publishResponse.flatMap(r -> r.sdkHttpResponse().statusText());
return create(element, statusCode, statusText);
}
use of software.amazon.awssdk.services.sns.model.PublishResponse in project beam by apache.
the class PublishResponseCodersTest method testFullPublishResponseWithoutHeadersDecodeEncodeEquals.
@Test
public void testFullPublishResponseWithoutHeadersDecodeEncodeEquals() throws Exception {
CoderProperties.coderDecodeEncodeEqual(fullPublishResponseWithoutHeaders(), PublishResponse.builder().messageId(UUID.randomUUID().toString()).build());
PublishResponse value = buildFullPublishResponse();
PublishResponse clone = CoderUtils.clone(fullPublishResponseWithoutHeaders(), value);
assertThat(clone.responseMetadata().requestId(), equalTo(value.responseMetadata().requestId()));
assertThat(clone.sdkHttpResponse().statusCode(), equalTo(value.sdkHttpResponse().statusCode()));
assertThat(clone.sdkHttpResponse().headers().isEmpty(), equalTo(true));
}
use of software.amazon.awssdk.services.sns.model.PublishResponse in project beam by apache.
the class MockSnsAsyncClient method publish.
@Override
public CompletableFuture<PublishResponse> publish(PublishRequest publishRequest) {
return CompletableFuture.supplyAsync(() -> {
SdkHttpResponse sdkHttpResponse = SdkHttpResponse.builder().statusCode(statusCode).build();
PublishResponse.Builder builder = PublishResponse.builder();
builder.messageId(UUID.randomUUID().toString());
builder.sdkHttpResponse(sdkHttpResponse).build();
return builder.build();
});
}
use of software.amazon.awssdk.services.sns.model.PublishResponse in project aws-doc-sdk-examples by awsdocs.
the class PublishTopic method pubTopic.
// snippet-start:[sns.java2.PublishTopic.main]
public static void pubTopic(SnsClient snsClient, String message, String topicArn) {
try {
PublishRequest request = PublishRequest.builder().message(message).topicArn(topicArn).build();
PublishResponse result = snsClient.publish(request);
System.out.println(result.messageId() + " Message sent. Status is " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sns.model.PublishResponse in project aws-doc-sdk-examples by awsdocs.
the class PublishTextSMS method pubTextSMS.
// snippet-start:[sns.java2.PublishTextSMS.main]
public static void pubTextSMS(SnsClient snsClient, String message, String phoneNumber) {
try {
PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phoneNumber).build();
PublishResponse result = snsClient.publish(request);
System.out.println(result.messageId() + " Message sent. Status was " + result.sdkHttpResponse().statusCode());
} catch (SnsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations