//snippet-sourcedescription:[ConfirmSubscription.java demonstrates how to retrieve the defaults for an AWS 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.ConfirmSubscription.complete]
package com.example.sns;

//snippet-start:[sns.java2.ConfirmSubscription.import]

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.ConfirmSubscriptionRequest;
import software.amazon.awssdk.services.sns.model.ConfirmSubscriptionResponse;
//snippet-end:[sns.java2.ConfirmSubscription.import]

public class ConfirmSubscription {
    public static void main(String[] args) {
        final String USAGE = "\n" +
                "ConfirmSubscription - confirm a subscription to an sns topic\n" +
                "Usage: ConfirmSubscription <subscriptionToken> <topicArn>\n\n" +
                "Where:\n" +
                "  subscriptionToken - endpoint token from Subscribe action.\n\n" +
                "  topicArn - the arn of the topic to delete.\n\n";

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

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

        ConfirmSubscriptionRequest request = ConfirmSubscriptionRequest.builder()
                .token(subscriptionToken)
                .topicArn(topicArn)
                .build();

        ConfirmSubscriptionResponse result = snsClient.confirmSubscription(request);

        System.out.println("\n\nStatus was " + result.sdkHttpResponse().statusCode() + "\n\nSubscription Arn: \n\n" + result.subscriptionArn());
        //snippet-end:[sns.java2.ConfirmSubscription.main]
    }
}
//snippet-end:[sns.java2.ConfirmSubscription.complete]


@@ -376,22 +376,16 @@
 or:%5B
-j
 sc
-hwarzwalder
+macdon
  AWS
@@ -1109,17 +1109,16 @@
 import%5D%0A
-%0A
 import s
@@ -1364,16 +1364,79 @@
 sponse;%0A
+import software.amazon.awssdk.services.sns.model.SnsException;%0A
 //snippe
@@ -2021,25 +2021,24 @@
 %0A           
- 
 System.exit(
@@ -2108,24 +2108,25 @@
 ption.main%5D%0A
+%0A
         Stri
@@ -2193,16 +2193,34 @@
 gs%5B1%5D;%0A%0A
+        try %7B%0A    
         
@@ -2260,16 +2260,33 @@
 uilder()
+%0A                
 .region(
@@ -2299,15 +2299,32 @@
 .US_
+W
 E
-A
 ST_
-1)
+2)%0A                
 .bui
@@ -2322,32 +2322,36 @@
      .build();%0A%0A
+    
         ConfirmS
@@ -2521,32 +2521,36 @@
 ild();%0A%0A        
+  
+  
 ConfirmSubscript
@@ -2607,24 +2607,28 @@
 (request);%0A%0A
+    
         Syst
@@ -2760,16 +2760,143 @@
 Arn());%0A
+    %7D catch (SnsException e) %7B%0A%0A        System.err.println(e.awsErrorDetails().errorMessage());%0A        System.exit(1);%0A    %7D%0A%0A
         
@@ -3009,9 +3009,8 @@
 mplete%5D%0A
-%0A

Update ConfirmSubscription.java