Skip to content

Commit 13ad018

Browse files
committed
added supporting documents
1 parent 06f5786 commit 13ad018

File tree

3 files changed

+180
-305
lines changed

3 files changed

+180
-305
lines changed

javav2/example_code/location/src/main/java/com/example/location/scenario/LocationActions.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import software.amazon.awssdk.services.location.model.BatchUpdateDevicePositionResponse;
1616
import software.amazon.awssdk.services.location.model.CalculateRouteRequest;
1717
import software.amazon.awssdk.services.location.model.CalculateRouteResponse;
18+
import software.amazon.awssdk.services.location.model.ConflictException;
1819
import software.amazon.awssdk.services.location.model.CreateGeofenceCollectionRequest;
1920
import software.amazon.awssdk.services.location.model.CreateGeofenceCollectionResponse;
2021
import software.amazon.awssdk.services.location.model.CreateKeyRequest;
@@ -38,6 +39,9 @@
3839
import software.amazon.awssdk.services.location.model.PutGeofenceRequest;
3940
import software.amazon.awssdk.services.location.model.PutGeofenceResponse;
4041
import software.amazon.awssdk.services.location.model.ResourceNotFoundException;
42+
import software.amazon.awssdk.services.location.model.ServiceQuotaExceededException;
43+
import software.amazon.awssdk.services.location.model.ThrottlingException;
44+
import software.amazon.awssdk.services.location.model.ValidationException;
4145
import software.amazon.awssdk.services.location.paginators.ListGeofencesPublisher;
4246
import java.time.Duration;
4347
import java.time.Instant;
@@ -293,7 +297,7 @@ public CompletableFuture<PutGeofenceResponse> putGeofence(String collectionName,
293297
}
294298

295299
Throwable cause = exception.getCause();
296-
if (cause instanceof LocationException) {
300+
if (cause instanceof ValidationException) {
297301
throw new CompletionException("AWS Location Service error: " + cause.getMessage(), cause);
298302
}
299303
throw new CompletionException("Error creating geofence: " + exception.getMessage(), exception);
@@ -322,8 +326,8 @@ public CompletableFuture<CreateGeofenceCollectionResponse> createGeofenceCollect
322326
}
323327

324328
Throwable cause = exception.getCause();
325-
if (cause instanceof ResourceNotFoundException) {
326-
throw new CompletionException("The requested resource was not found while creating the geofence collection.", cause);
329+
if (cause instanceof ConflictException) {
330+
throw new CompletionException("The geofence collection was not created due to a conflict. ", cause);
327331
}
328332
throw new CompletionException("Failed to create geofence collection: " + exception.getMessage(), exception);
329333
}
@@ -354,31 +358,27 @@ public CompletableFuture<String> createKey(String keyName, String mapArn) {
354358
.whenComplete((response, exception) -> {
355359
if (response != null) {
356360
String keyArn = response.keyArn();
357-
logger.info("API Key Created: " + keyArn);
361+
logger.info("The API key was successfully created: " + keyArn);
358362
} else {
359363
if (exception == null) {
360364
throw new CompletionException("An unknown error occurred while creating the API key.", null);
361365
}
362366

363367
Throwable cause = exception.getCause();
364-
if (cause instanceof ResourceNotFoundException) {
365-
throw new CompletionException("The requested resource was not found while creating the API key.", cause);
368+
if (cause instanceof ThrottlingException) {
369+
throw new CompletionException("Request throttling was detected.", cause);
366370
}
367371
throw new CompletionException("Failed to create API key: " + exception.getMessage(), exception);
368372
}
369373
}).thenApply(response -> response != null ? response.keyArn() : null); // Return the key ARN
370374
}
371375

372376
/**
373-
* Creates a new map with the specified name and default configuration.
377+
* Creates a new map with the specified name and configuration.
374378
*
375-
* @param mapName the name of the map to create
376-
* @return a {@link CompletableFuture} that resolves to the Amazon Resource Name (ARN) of the created map, or
377-
* {@code null} if the map creation failed
378-
* @throws CompletionException if an error occurs while creating the map
379-
* - if the requested resource was not found
380-
* - if an unknown error occurred
381-
* - if the map creation failed for any other reason
379+
* @param mapName the name of the map to be created
380+
* @return a {@link CompletableFuture} that, when completed, will contain the Amazon Resource Name (ARN) of the created map
381+
* @throws CompletionException if an error occurs while creating the map, such as exceeding the service quota
382382
*/
383383
public CompletableFuture<String> createMap(String mapName) {
384384
MapConfiguration configuration = MapConfiguration.builder()
@@ -401,8 +401,8 @@ public CompletableFuture<String> createMap(String mapName) {
401401
}
402402

403403
Throwable cause = exception.getCause();
404-
if (cause instanceof ResourceNotFoundException) {
405-
throw new CompletionException("The requested resource was not found while creating the map.", cause);
404+
if (cause instanceof ServiceQuotaExceededException) {
405+
throw new CompletionException("The operation was denied because the request would exceed the maximum quota.", cause);
406406
}
407407
throw new CompletionException("Failed to create map: " + exception.getMessage(), exception);
408408
}

javav2/example_code/location/src/main/java/com/example/location/scenario/LocationScenario.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ public static void main(String[] args) {
3131
deviceId - The ID of the device (e.g., "iPhone-112356").
3232
""";
3333

34-
if (args.length != 7) {
35-
System.out.println(usage);
36-
System.exit(1);
37-
}
38-
39-
String mapName = args[0];
40-
String keyName = args[1];
41-
String collectionName = args[2];
42-
String geoId = args[4];
43-
String trackerName = args[5];
44-
String calculatorName = args[6];
45-
String deviceId = args[7];
34+
//if (args.length != 7) {
35+
// System.out.println(usage);
36+
// System.exit(1);
37+
// }
38+
39+
String mapName = "MyMap" ; //args[0];
40+
String keyName = "MyLocationKey" ; //args[1];
41+
String collectionName = "AWSLocationCollection" ; //args[2];
42+
String geoId = "geoId1"; //args[4];
43+
String trackerName = "geoTracker1"; //args[5];
44+
String calculatorName = "AWSRouteCalc32"; //args[6];
45+
String deviceId = "iPhone-112359" ; //args[7];
4646

4747
logger.info("""
4848
AWS Location Service is a fully managed service offered by Amazon Web Services (AWS) that

0 commit comments

Comments
 (0)