//snippet-sourcedescription:[GetServerCertificate.java demonstrates how to get information about an IAM server certificate.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[iam]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[soo-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.
 */
package com.example.iam;
// snippet-start:[iam.java2.get_server_certificate.complete]
// snippet-start:[iam.java2.get_server_certificate.import]
import software.amazon.awssdk.services.iam.model.GetServerCertificateRequest;
import software.amazon.awssdk.services.iam.model.GetServerCertificateResponse;

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.iam.IamClient;
 
// snippet-end:[iam.java2.get_server_certificate.import]
/**
 * Gets a server certificate
 */
public class GetServerCertificate {

    public static void main(String[] args) {

        final String USAGE =
            "To run this example, supply a certificate name\n" +
            "Ex: GetServerCertificate <certificate-name>\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String cert_name = args[0];

        // snippet-start:[iam.java2.get_server_certificate.main]
        Region region = Region.AWS_GLOBAL;
        IamClient iam = IamClient.builder().region(region).build();

        GetServerCertificateRequest request = GetServerCertificateRequest.builder()
                    .serverCertificateName(cert_name).build();

        GetServerCertificateResponse response = iam.getServerCertificate(request); 
        // snippet-end:[iam.java2.get_server_certificate.main]

        System.out.format("Successfully retrieved certificate with body %s",
                response.serverCertificate().certificateBody());
    }
}

// snippet-end:[iam.java2.get_server_certificate.complete]

@@ -274,16 +274,26 @@
 cedate:%5B
+03/02/2020
 %5D%0D%0A//sni
@@ -316,10 +316,15 @@
 r:%5Bs
-oo
+cmacdon
 -aws
@@ -1230,18 +1230,16 @@
 ponse;%0D%0A
-%0D%0A
 import s
@@ -1332,17 +1332,80 @@
 lient;%0D%0A
- 
+import software.amazon.awssdk.services.iam.model.IamException;%0D%0A
 %0D%0A// sni
@@ -1625,16 +1625,20 @@
         
+    
 %22To run 
@@ -1683,16 +1683,28 @@
 e%5Cn%22 +%0D%0A
+            
         
@@ -1872,18 +1872,16 @@
      %7D%0D%0A
-%0D%0A
         
@@ -1891,18 +1891,17 @@
 ing cert
-_n
+N
 ame = ar
@@ -2083,32 +2083,51 @@
 on).build();%0D%0A%0D%0A
+        try %7B%0D%0A    
         GetServe
@@ -2211,20 +2211,16 @@
         
-    
 .serverC
@@ -2242,10 +2242,9 @@
 cert
-_n
+N
 ame)
@@ -2256,32 +2256,36 @@
 d();%0D%0A%0D%0A        
+ 
+   
 GetServerCertifi
@@ -2342,17 +2342,16 @@
 equest);
- 
 %0D%0A      
@@ -2344,32 +2344,36 @@
 uest);%0D%0A        
+   
+ 
 // snippet-end:%5B
@@ -2412,18 +2412,20 @@
 .main%5D%0D%0A
-%0D%0A
+    
         
@@ -2559,16 +2559,190 @@
 ody());%0D
+%0A%0D%0A    %7D catch (%0D%0A    IamException e) %7B%0D%0A        System.err.println(e.awsErrorDetails().errorMessage());%0D%0A        System.exit(1);%0D%0A    %7D%0D%0A        System.out.println(%22Done%22);%0D
 %0A    %7D%0D%0A

Update GetServerCertificate.java