//snippet-sourcedescription:[PublishTopic.java demonstrates how to send a message to an SNS Topic.]
//snippet-keyword:[Java]
//snippet-sourcesyntax:[java]
//snippet-keyword:[Code Sample]
//snippet-keyword:[Amazon Simple Notification Service]
//snippet-service:[sns]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-07-20]
//snippet-sourceauthor:[jschwarzwalder AWS]
/*
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
//snippet-start:[sns.java2.PublishTopic.complete]
package com.example.sns;

//snippet-start:[sns.java2.PublishTopic.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.PublishRequest;
import software.amazon.awssdk.services.sns.model.PublishResponse;
//snippet-end:[sns.java2.PublishTopic.import]

public class PublishTopic {

    public static void main(String[] args) {
        final String USAGE = "\n" +
                "PublishTopic - publish an sns topic\n" +
                "Usage: PublishTopic <message> <topicArn>\n\n" +
                "Where:\n" +
                "  message - message text to send.\n\n" +
                "  topicArn - the arn of the topic to look up.\n\n";

        if (args.length < 2) {
            System.out.println(USAGE);
            System.exit(1);
        }
        //snippet-start:[sns.java2.PublishTopic.main]
        String message = args[0];
        String topicArn = args[1];

        SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();

        PublishRequest request = PublishRequest.builder()
                .message(message)
                .topicArn(topicArn)
                .build();

        PublishResponse result = snsClient.publish(request);

        System.out.println(result.messageId() + " Message sent. Status was " + result.sdkHttpResponse().statusCode());
        //snippet-end:[sns.java2.PublishTopic.main]
    }
}
//snippet-end:[sns.java2.PublishTopic.complete]
@@ -357,22 +357,16 @@
 or:%5B
-j
 sc
-hwarzwalder
+macdon
  AWS
@@ -390,18 +390,18 @@
  2010-20
-19
+20
  Amazon.
@@ -1307,16 +1307,79 @@
 sponse;%0A
+import software.amazon.awssdk.services.sns.model.SnsException;%0A
 //snippe
@@ -1915,16 +1915,17 @@
       %7D%0A
+%0A
         
@@ -2089,16 +2089,33 @@
 uilder()
+%0A                
 .region(
@@ -2128,26 +2128,62 @@
 .US_
+W
 E
-A
 ST_
-1).build();%0A%0A
+2)%0A                .build();%0A%0A        try %7B%0A%0A    
     
@@ -2333,32 +2333,36 @@
 ild();%0A%0A        
+   
+ 
 PublishResponse 
@@ -2398,17 +2398,20 @@
 quest);%0A
-%0A
+    
         
@@ -2520,16 +2520,162 @@
 Code());
+%0A%0A         %7D catch (SnsException e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A              System.exit(1);%0A         %7D
 %0A       
@@ -2754,28 +2754,29 @@
 java2.PublishTopic.complete%5D
+%0A

Update PublishTopic.java