//snippet-sourcedescription:[PutEvents.java demonstrates how to put a sample CloudWatch event.]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[cloudwatch]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[]
//snippet-sourceauthor:[soo-aws]
// snippet-start:[cloudwatch.java2.put_events.complete]
/*
 * 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.cloudwatch;
// snippet-start:[cloudwatch.java2.put_events.import]
import software.amazon.awssdk.services.cloudwatchevents.CloudWatchEventsClient;
import software.amazon.awssdk.services.cloudwatchevents.model.PutEventsRequest;
import software.amazon.awssdk.services.cloudwatchevents.model.PutEventsRequestEntry;
import software.amazon.awssdk.services.cloudwatchevents.model.PutEventsResponse;
// snippet-end:[cloudwatch.java2.put_events.import]

/**
 * Puts a sample CloudWatch event
 */
public class PutEvents
{
    public static void main(String[] args)
    {
        final String USAGE =
            "To run this example, supply a resource arn\n" +
            "Ex: PutEvents <resource-arn>\n";

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

        String resource_arn = args[0];

        // snippet-start:[cloudwatch.java2.put_events.main]
        CloudWatchEventsClient cwe =
        		CloudWatchEventsClient.builder().build();

        final String EVENT_DETAILS =
            "{ \"key1\": \"value1\", \"key2\": \"value2\" }";

        PutEventsRequestEntry request_entry = PutEventsRequestEntry.builder()
            .detail(EVENT_DETAILS)
            .detailType("sampleSubmitted")
            .resources(resource_arn)
            .source("aws-sdk-java-cloudwatch-example").build();

        PutEventsRequest request = PutEventsRequest.builder()
            .entries(request_entry).build();

        PutEventsResponse response = cwe.putEvents(request);
        // snippet-end:[cloudwatch.java2.put_events.main]

        System.out.println("Successfully put CloudWatch event");
    }
}
// snippet-end:[cloudwatch.java2.put_events.complete]
@@ -287,16 +287,17 @@
 soo-aws%5D
+%0D
 %0A// snip
@@ -943,16 +943,17 @@
 se.%0D%0A */
+%0D
 %0Apackage
@@ -1033,16 +1033,94 @@
 mport%5D%0D%0A
+import software.amazon.awssdk.services.cloudwatch.model.CloudWatchException;%0D%0A
 import s
@@ -1539,16 +1539,17 @@
 ent%0D%0A */
+%0D
 %0Apublic 
@@ -1563,18 +1563,17 @@
 utEvents
-%0D%0A
+ 
 %7B%0D%0A    p
@@ -1609,21 +1609,16 @@
 %5B%5D args)
-%0D%0A   
  %7B%0D%0A    
@@ -1639,24 +1639,28 @@
 ng USAGE =%0D%0A
+    
             
@@ -1709,16 +1709,28 @@
 n%5Cn%22 +%0D%0A
+            
         
@@ -1908,18 +1908,17 @@
 resource
-_a
+A
 rn = arg
@@ -2037,10 +2037,16 @@
     
-%09%09
+        
 Clou
@@ -2078,32 +2078,53 @@
 r().build();%0D%0A%0D%0A
+        try %7B%0D%0A%0D%0A    
         final St
@@ -2141,24 +2141,28 @@
 _DETAILS =%0D%0A
+    
             
@@ -2214,32 +2214,36 @@
  %7D%22;%0D%0A%0D%0A        
+  
+  
 PutEventsRequest
@@ -2251,26 +2251,25 @@
 ntry request
-_e
+E
 ntry = PutEv
@@ -2304,24 +2304,28 @@
             
+  
+  
 .detail(EVEN
@@ -2336,16 +2336,20 @@
 TAILS)%0D%0A
+    
         
@@ -2396,16 +2396,20 @@
         
+ 
+   
 .resourc
@@ -2423,10 +2423,9 @@
 urce
-_a
+A
 rn)%0D
@@ -2437,16 +2437,20 @@
         
+ 
+   
 .source(
@@ -2488,32 +2488,36 @@
 e%22).build();%0D%0A%0D%0A
+    
         PutEvent
@@ -2575,16 +2575,20 @@
         
+ 
+   
 .entries
@@ -2595,18 +2595,17 @@
 (request
-_e
+E
 ntry).bu
@@ -2614,32 +2614,36 @@
 d();%0D%0A%0D%0A        
+ 
+   
 PutEventsRespons
@@ -2679,16 +2679,170 @@
 quest);%0D
+%0A%0D%0A        %7D catch (CloudWatchException e) %7B%0D%0A            System.err.println(e.awsErrorDetails().errorMessage());%0D%0A            System.exit(1);%0D%0A        %7D%0D
 %0A       
@@ -2893,18 +2893,16 @@
 .main%5D%0D%0A
-%0D%0A
         
@@ -3002,28 +3002,30 @@
 h.java2.put_events.complete%5D
+%0D%0A

Update PutEvents.java