Search in sources :

Example 21 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class SubscribeEmail method subEmail.

// snippet-start:[sns.java2.SubscribeEmail.main]
public static void subEmail(SnsClient snsClient, String topicArn, String email) {
    try {
        SubscribeRequest request = SubscribeRequest.builder().protocol("email").endpoint(email).returnSubscriptionArn(true).topicArn(topicArn).build();
        SubscribeResponse result = snsClient.subscribe(request);
        System.out.println("Subscription ARN: " + result.subscriptionArn() + "\n\n Status is " + result.sdkHttpResponse().statusCode());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SubscribeRequest(software.amazon.awssdk.services.sns.model.SubscribeRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) SubscribeResponse(software.amazon.awssdk.services.sns.model.SubscribeResponse)

Example 22 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class ConfirmSubscription method confirmSub.

// snippet-start:[sns.java2.ConfirmSubscription.main]
public static void confirmSub(SnsClient snsClient, String subscriptionToken, String topicArn) {
    try {
        ConfirmSubscriptionRequest request = ConfirmSubscriptionRequest.builder().token(subscriptionToken).topicArn(topicArn).build();
        ConfirmSubscriptionResponse result = snsClient.confirmSubscription(request);
        System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode() + "\n\nSubscription Arn: \n\n" + result.subscriptionArn());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ConfirmSubscriptionRequest(software.amazon.awssdk.services.sns.model.ConfirmSubscriptionRequest) ConfirmSubscriptionResponse(software.amazon.awssdk.services.sns.model.ConfirmSubscriptionResponse) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Example 23 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class SubscribeHTTPS method subHTTPS.

// snippet-start:[sns.java2.SubscribeHTTPS.main]
public static void subHTTPS(SnsClient snsClient, String topicArn, String url) {
    try {
        SubscribeRequest request = SubscribeRequest.builder().protocol("http").endpoint(url).returnSubscriptionArn(true).topicArn(topicArn).build();
        SubscribeResponse result = snsClient.subscribe(request);
        System.out.println("Subscription ARN is " + result.subscriptionArn() + "\n\n Status is " + result.sdkHttpResponse().statusCode());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SubscribeRequest(software.amazon.awssdk.services.sns.model.SubscribeRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) SubscribeResponse(software.amazon.awssdk.services.sns.model.SubscribeResponse)

Example 24 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException in project aws-doc-sdk-examples by awsdocs.

the class ListSubscriptions method listSNSSubscriptions.

// snippet-start:[sns.java2.ListSubscriptions.main]
public static void listSNSSubscriptions(SnsClient snsClient) {
    try {
        ListSubscriptionsRequest request = ListSubscriptionsRequest.builder().build();
        ListSubscriptionsResponse result = snsClient.listSubscriptions(request);
        System.out.println(result.subscriptions());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ListSubscriptionsResponse(software.amazon.awssdk.services.sns.model.ListSubscriptionsResponse) ListSubscriptionsRequest(software.amazon.awssdk.services.sns.model.ListSubscriptionsRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Aggregations

SnsException (software.amazon.awssdk.services.sns.model.SnsException)24 PublishRequest (software.amazon.awssdk.services.sns.model.PublishRequest)5 SubscribeRequest (software.amazon.awssdk.services.sns.model.SubscribeRequest)4 SubscribeResponse (software.amazon.awssdk.services.sns.model.SubscribeResponse)4 SnsClient (software.amazon.awssdk.services.sns.SnsClient)2 PublishResponse (software.amazon.awssdk.services.sns.model.PublishResponse)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Region (software.amazon.awssdk.regions.Region)1 CheckIfPhoneNumberIsOptedOutRequest (software.amazon.awssdk.services.sns.model.CheckIfPhoneNumberIsOptedOutRequest)1 CheckIfPhoneNumberIsOptedOutResponse (software.amazon.awssdk.services.sns.model.CheckIfPhoneNumberIsOptedOutResponse)1 ConfirmSubscriptionRequest (software.amazon.awssdk.services.sns.model.ConfirmSubscriptionRequest)1 ConfirmSubscriptionResponse (software.amazon.awssdk.services.sns.model.ConfirmSubscriptionResponse)1 CreateTopicRequest (software.amazon.awssdk.services.sns.model.CreateTopicRequest)1 CreateTopicResponse (software.amazon.awssdk.services.sns.model.CreateTopicResponse)1 DeleteTopicRequest (software.amazon.awssdk.services.sns.model.DeleteTopicRequest)1 DeleteTopicResponse (software.amazon.awssdk.services.sns.model.DeleteTopicResponse)1 GetSubscriptionAttributesRequest (software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesRequest)1 GetSubscriptionAttributesResponse (software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesResponse)1