Search in sources :

Example 6 with SnsException

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

the class GetTopicAttributes method getSNSTopicAttributes.

// snippet-start:[sns.java2.GetTopicAttributes.main]
public static void getSNSTopicAttributes(SnsClient snsClient, String topicArn) {
    try {
        GetTopicAttributesRequest request = GetTopicAttributesRequest.builder().topicArn(topicArn).build();
        GetTopicAttributesResponse result = snsClient.getTopicAttributes(request);
        System.out.println("\n\nStatus is " + result.sdkHttpResponse().statusCode() + "\n\nAttributes: \n\n" + result.attributes());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetTopicAttributesRequest(software.amazon.awssdk.services.sns.model.GetTopicAttributesRequest) GetTopicAttributesResponse(software.amazon.awssdk.services.sns.model.GetTopicAttributesResponse) SnsException(software.amazon.awssdk.services.sns.model.SnsException)

Example 7 with SnsException

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

the class ListTopics method listSNSTopics.

// snippet-start:[sns.java2.ListTopics.main]
public static void listSNSTopics(SnsClient snsClient) {
    try {
        ListTopicsRequest request = ListTopicsRequest.builder().build();
        ListTopicsResponse result = snsClient.listTopics(request);
        System.out.println("Status was " + result.sdkHttpResponse().statusCode() + "\n\nTopics\n\n" + result.topics());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ListTopicsRequest(software.amazon.awssdk.services.sns.model.ListTopicsRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) ListTopicsResponse(software.amazon.awssdk.services.sns.model.ListTopicsResponse)

Example 8 with SnsException

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

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

the class SetSMSAttributes method setSNSAttributes.

// snippet-start:[sns.java2.SetSMSAttributes.main]
public static void setSNSAttributes(SnsClient snsClient, HashMap<String, String> attributes) {
    try {
        SetSmsAttributesRequest request = SetSmsAttributesRequest.builder().attributes(attributes).build();
        SetSmsAttributesResponse result = snsClient.setSMSAttributes(request);
        System.out.println("Set default Attributes to " + attributes + ". Status was " + result.sdkHttpResponse().statusCode());
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SetSmsAttributesRequest(software.amazon.awssdk.services.sns.model.SetSmsAttributesRequest) SnsException(software.amazon.awssdk.services.sns.model.SnsException) SetSmsAttributesResponse(software.amazon.awssdk.services.sns.model.SetSmsAttributesResponse)

Example 10 with SnsException

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

the class AddTags method addTopicTags.

// snippet-start:[sns.java2.add_tags.main]
public static void addTopicTags(SnsClient snsClient, String topicArn) {
    try {
        Tag tag = Tag.builder().key("Team").value("Development").build();
        Tag tag2 = Tag.builder().key("Environment").value("Gamma").build();
        List<Tag> tagList = new ArrayList<>();
        tagList.add(tag);
        tagList.add(tag2);
        TagResourceRequest tagResourceRequest = TagResourceRequest.builder().resourceArn(topicArn).tags(tagList).build();
        snsClient.tagResource(tagResourceRequest);
        System.out.println("Tags have been added to " + topicArn);
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : TagResourceRequest(software.amazon.awssdk.services.sns.model.TagResourceRequest) ArrayList(java.util.ArrayList) SnsException(software.amazon.awssdk.services.sns.model.SnsException) Tag(software.amazon.awssdk.services.sns.model.Tag)

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