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;
}
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);
}
}
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 "";
}
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;
}
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);
}
}
Aggregations