Search in sources :

Example 11 with SnsException

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

the class DeleteTag method removeTag.

// snippet-start:[sns.java2.delete_tags.main]
public static void removeTag(SnsClient snsClient, String topicArn, String tagKey) {
    try {
        UntagResourceRequest resourceRequest = UntagResourceRequest.builder().resourceArn(topicArn).tagKeys(tagKey).build();
        snsClient.untagResource(resourceRequest);
        System.out.println(tagKey + " was deleted from " + topicArn);
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : UntagResourceRequest(software.amazon.awssdk.services.sns.model.UntagResourceRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Example 12 with SnsException

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

the class GetSMSAtrributes method getSNSAttrutes.

// snippet-start:[sns.java2.GetSMSAtrributes.main]
public static void getSNSAttrutes(SnsClient snsClient, String topicArn) {
    try {
        GetSubscriptionAttributesRequest request = GetSubscriptionAttributesRequest.builder().subscriptionArn(topicArn).build();
        // Get the Subscription attributes
        GetSubscriptionAttributesResponse res = snsClient.getSubscriptionAttributes(request);
        Map<String, String> map = res.attributes();
        // Iterate through the map
        Iterator iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            System.out.println("[Key] : " + entry.getKey() + " [Value] : " + entry.getValue());
        }
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    System.out.println("\n\nStatus was good");
}
Also used : GetSubscriptionAttributesResponse(software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesResponse) Iterator(java.util.Iterator) SnsException(software.amazon.awssdk.services.sns.model.SnsException) Map(java.util.Map) GetSubscriptionAttributesRequest(software.amazon.awssdk.services.sns.model.GetSubscriptionAttributesRequest)

Example 13 with SnsException

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

the class ListOptOut method listOpts.

// snippet-start:[sns.java2.ListOptOut.main]
public static void listOpts(SnsClient snsClient) {
    try {
        ListPhoneNumbersOptedOutRequest request = ListPhoneNumbersOptedOutRequest.builder().build();
        ListPhoneNumbersOptedOutResponse result = snsClient.listPhoneNumbersOptedOut(request);
        System.out.println("Status is " + result.sdkHttpResponse().statusCode() + "\n\nPhone Numbers: \n\n" + result.phoneNumbers());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SnsException(software.amazon.awssdk.services.sns.model.SnsException) ListPhoneNumbersOptedOutRequest(software.amazon.awssdk.services.sns.model.ListPhoneNumbersOptedOutRequest) ListPhoneNumbersOptedOutResponse(software.amazon.awssdk.services.sns.model.ListPhoneNumbersOptedOutResponse)

Example 14 with SnsException

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

the class ListTags method listTopicTags.

// snippet-start:[sns.java2.list_tags.main]
public static void listTopicTags(SnsClient snsClient, String topicArn) {
    try {
        ListTagsForResourceRequest tagsForResourceRequest = ListTagsForResourceRequest.builder().resourceArn(topicArn).build();
        ListTagsForResourceResponse response = snsClient.listTagsForResource(tagsForResourceRequest);
        System.out.println(String.format("Tags for topic %s are %s.\n", topicArn, response.tags()));
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ListTagsForResourceResponse(software.amazon.awssdk.services.sns.model.ListTagsForResourceResponse) ListTagsForResourceRequest(software.amazon.awssdk.services.sns.model.ListTagsForResourceRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Example 15 with SnsException

use of software.amazon.awssdk.services.sns.model.SnsException 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

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