Search in sources :

Example 1 with SnsClient

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

the class SendNotifications method handleTextMessage.

public String handleTextMessage(String myDom) throws JDOMException, IOException {
    String mobileNum = "";
    SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();
    SAXBuilder builder = new SAXBuilder();
    Document jdomDocument = builder.build(new InputSource(new StringReader(myDom)));
    org.jdom2.Element root = jdomDocument.getRootElement();
    // get the list of children agent elements.
    List<org.jdom2.Element> students = root.getChildren("Student");
    for (org.jdom2.Element element : students) {
        mobileNum = element.getChildText("Mobile");
        publishTextSMS(snsClient, mobileNum);
    }
    snsClient.close();
    return mobileNum;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) SnsClient(software.amazon.awssdk.services.sns.SnsClient) StringReader(java.io.StringReader) Document(org.jdom2.Document)

Example 2 with SnsClient

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

the class ScanEmployees method sentTextMessage.

// Use the Amazon SNS Service to send a text message
private void sentTextMessage(String first, String phone) {
    SnsClient snsClient = SnsClient.builder().region(Region.US_WEST_2).build();
    String message = first + " happy one year anniversary. We are very happy that you have been working here for a year! ";
    try {
        PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phone).build();
        snsClient.publish(request);
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Example 3 with SnsClient

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

the class SnsService method getTopicArnValue.

// Returns the Sub ARN based on the given endpoint
private String getTopicArnValue(String endpoint) {
    SnsClient snsClient = getSnsClient();
    try {
        String subArn = "";
        ListSubscriptionsByTopicRequest request = ListSubscriptionsByTopicRequest.builder().topicArn(topicArn).build();
        ListSubscriptionsByTopicResponse result = snsClient.listSubscriptionsByTopic(request);
        List<Subscription> allSubs = result.subscriptions();
        for (Subscription sub : allSubs) {
            if (sub.endpoint().compareTo(endpoint) == 0) {
                subArn = sub.subscriptionArn();
                return subArn;
            }
        }
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) ListSubscriptionsByTopicRequest(software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest)

Example 4 with SnsClient

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

the class SnsService method getSnsClient.

private SnsClient getSnsClient() {
    Region region = Region.US_WEST_2;
    SnsClient snsClient = SnsClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
    return snsClient;
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) Region(software.amazon.awssdk.regions.Region)

Example 5 with SnsClient

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

the class PublishTextSMS method sendMessage.

public void sendMessage(String id) {
    Region region = Region.US_EAST_1;
    SnsClient snsClient = SnsClient.builder().region(region).credentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
    String message = "A new item with ID value " + id + " was added to the DynamoDB table";
    // Replace with a mobile phone number
    String phoneNumber = "18195765654";
    try {
        PublishRequest request = PublishRequest.builder().message(message).phoneNumber(phoneNumber).build();
        snsClient.publish(request);
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) Region(software.amazon.awssdk.regions.Region) SnsException(software.amazon.awssdk.services.sns.model.SnsException) PublishRequest(software.amazon.awssdk.services.sns.model.PublishRequest)

Aggregations

SnsClient (software.amazon.awssdk.services.sns.SnsClient)31 Region (software.amazon.awssdk.regions.Region)3 ListSubscriptionsByTopicRequest (software.amazon.awssdk.services.sns.model.ListSubscriptionsByTopicRequest)2 PublishRequest (software.amazon.awssdk.services.sns.model.PublishRequest)2 SnsException (software.amazon.awssdk.services.sns.model.SnsException)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Document (org.jdom2.Document)1 SAXBuilder (org.jdom2.input.SAXBuilder)1 InputSource (org.xml.sax.InputSource)1 TranslateClient (software.amazon.awssdk.services.translate.TranslateClient)1 TranslateTextRequest (software.amazon.awssdk.services.translate.model.TranslateTextRequest)1 TranslateTextResponse (software.amazon.awssdk.services.translate.model.TranslateTextResponse)1