Search in sources :

Example 16 with SnsClient

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

the class ListOptOut method main.

public static void main(String[] args) {
    SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();
    listOpts(snsClient);
    snsClient.close();
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient)

Example 17 with SnsClient

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

the class SubscribeHTTPS method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <topicArn> <url>\n\n" + "Where:\n" + "   topicArn - the ARN of the topic to subscribe.\n\n" + "   url - the HTTPS endpoint that you want to receive notifications.\n\n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String topicArn = args[0];
    String url = args[1];
    SnsClient snsClient = SnsClient.builder().region(Region.US_WEST_2).build();
    subHTTPS(snsClient, topicArn, url);
    snsClient.close();
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient)

Example 18 with SnsClient

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

the class SnsService method pubTopic.

public String pubTopic(String message, String lang) {
    try {
        String body;
        Region region = Region.US_WEST_2;
        TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
        if (lang.compareTo("English") == 0) {
            body = message;
        } else if (lang.compareTo("French") == 0) {
            TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("fr").text(message).build();
            TranslateTextResponse textResponse = translateClient.translateText(textRequest);
            body = textResponse.translatedText();
        } else {
            TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode("es").text(message).build();
            TranslateTextResponse textResponse = translateClient.translateText(textRequest);
            body = textResponse.translatedText();
        }
        SnsClient snsClient = getSnsClient();
        PublishRequest request = PublishRequest.builder().message(body).topicArn(topicArn).build();
        PublishResponse result = snsClient.publish(request);
        return " Message sent in " + lang + ". Status was " + result.sdkHttpResponse().statusCode();
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "Error - msg not sent";
}
Also used : TranslateClient(software.amazon.awssdk.services.translate.TranslateClient) SnsClient(software.amazon.awssdk.services.sns.SnsClient) TranslateTextRequest(software.amazon.awssdk.services.translate.model.TranslateTextRequest) Region(software.amazon.awssdk.regions.Region) TranslateTextResponse(software.amazon.awssdk.services.translate.model.TranslateTextResponse)

Example 19 with SnsClient

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

the class SnsService method unSubEmail.

public void unSubEmail(String emailEndpoint) {
    try {
        String subscriptionArn = getTopicArnValue(emailEndpoint);
        SnsClient snsClient = getSnsClient();
        UnsubscribeRequest request = UnsubscribeRequest.builder().subscriptionArn(subscriptionArn).build();
        snsClient.unsubscribe(request);
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient)

Example 20 with SnsClient

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

the class SnsService method subEmail.

// Create a Subscription.
public String subEmail(String email) {
    try {
        SnsClient snsClient = getSnsClient();
        SubscribeRequest request = SubscribeRequest.builder().protocol("email").endpoint(email).returnSubscriptionArn(true).topicArn(topicArn).build();
        SubscribeResponse result = snsClient.subscribe(request);
        return result.subscriptionArn();
    } catch (SnsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient)

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