/**
* Retrieves the authorization token for Amazon Elastic Container Registry (ECR).
* This method makes an asynchronous call to the ECR client to retrieve the authorization token.
* If the operation is successful, the method prints the token to the console.
* If an exception occurs, the method handles the exception and prints the error message.
*
* @throws EcrException if there is an error retrieving the authorization token from ECR.
* @throws RuntimeException if there is an unexpected error during the operation.
*/publicvoidgetAuthToken(){
CompletableFuture<GetAuthorizationTokenResponse> response = getAsyncClient().getAuthorizationToken();
response.whenComplete((authorizationTokenResponse, ex) -> {if (authorizationTokenResponse != null) {
AuthorizationData authorizationData = authorizationTokenResponse.authorizationData().get(0);
String token = authorizationData.authorizationToken();
if (!token.isEmpty()) {
System.out.println("The token was successfully retrieved.");
}
} else{if (ex.getCause() instanceof EcrException) {throw (EcrException) ex.getCause();
} else{
String errorMessage = "Unexpected error occurred: " + ex.getMessage();
thrownew RuntimeException(errorMessage, ex); // Rethrow the exception
}
}
});
response.join();
}