Search in sources :

Example 1 with PublishResponse

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);
}
Also used : NonNull(org.checkerframework.checker.nullness.qual.NonNull) PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) AutoValue(com.google.auto.value.AutoValue) Optional(java.util.Optional) OptionalInt(java.util.OptionalInt) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Serializable(java.io.Serializable) PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) OptionalInt(java.util.OptionalInt)

Example 2 with PublishResponse

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));
}
Also used : PublishResponseCoders.defaultPublishResponse(org.apache.beam.sdk.io.aws2.sns.PublishResponseCoders.defaultPublishResponse) PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) Test(org.junit.Test)

Example 3 with PublishResponse

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();
    });
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse)

Example 4 with PublishResponse

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);
    }
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Example 5 with PublishResponse

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);
    }
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Aggregations

PublishResponse (software.amazon.awssdk.services.sns.model.PublishResponse)6 PublishResponseCoders.defaultPublishResponse (org.apache.beam.sdk.io.aws2.sns.PublishResponseCoders.defaultPublishResponse)2 Test (org.junit.Test)2 PublishRequest (software.amazon.awssdk.services.sns.model.PublishRequest)2 SnsException (software.amazon.awssdk.services.sns.model.SnsException)2 AutoValue (com.google.auto.value.AutoValue)1 Serializable (java.io.Serializable)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 SdkHttpResponse (software.amazon.awssdk.http.SdkHttpResponse)1