List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(String message, Throwable t)
From source file:io.kickflip.sdk.api.Jackson.java
License:Apache License
/** * Returns the deserialized object from the given json string and target * class; or null if the given json string is null. *///from www. j av a2 s . c om public static <T> T fromJsonString(String json, Class<T> clazz) { if (json == null) return null; try { return objectMapper.readValue(json, clazz); } catch (Exception e) { throw new AmazonClientException("Unable to parse Json String.", e); } }
From source file:io.robrose.hop.watermap.aws.DynamoGeoClient.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials // * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration *//*from w w w. jav a2 s.c o m*/ public static void init() { if (initialized) return; /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (C:\\Users\\Robert\\.aws\\credentials). */ AWSCredentials credentials; try { credentials = new BasicAWSCredentials(accessKey, secretKey); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (C:\\Users\\Robert\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); dynamoDB.setRegion(usEast1); initialized = true; }
From source file:Java21.S3Files.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from w w w . ja v a 2 s.com*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); String bucketName = "msm-gb-env-etl-iq/dev1-dwh/" + UUID.randomUUID(); //String key = ""; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); /* * List objects in your bucket by prefix - There are many options for * listing the objects in your bucket. Keep in mind that buckets with * many objects might truncate their results when listing their objects, * so be sure to check if the returned object listing is truncated, and * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve * additional results. */ System.out.println("Listing objects"); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); }
From source file:onl.area51.filesystem.s3.AbstractS3Action.java
License:Apache License
public AbstractS3Action(FileSystemIO delegate, Map<String, ?> env) { this.delegate = delegate; AWSCredentials credentials;//from www . j av a 2 s . c om try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception ex) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", ex); } s3 = new AmazonS3Client(credentials); Region region = Region.getRegion(Regions.EU_WEST_1); s3.setRegion(region); String n = FileSystemUtils.get(env, BUCKET_READ); if (n == null || n.trim().isEmpty()) { n = FileSystemUtils.get(env, BUCKET); } bucketName = Objects.requireNonNull(n, BUCKET + " or " + BUCKET_READ + " is not defined"); }
From source file:org.alfresco.provision.AWSService.java
License:Open Source License
private static AWSCredentialsProvider getCredentials() { AWSCredentialsProvider credentials = null; try {//from w ww. ja v a2 s . c o m credentials = new DefaultAWSCredentialsProviderChain(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } return credentials; }
From source file:org.apache.hadoop.fs.s3a.AWSCredentialProviderList.java
License:Apache License
/** * Iterate through the list of providers, to find one with credentials. * If {@link #reuseLastProvider} is true, then it is re-used. * @return a set of credentials (possibly anonymous), for authenticating. *//*from ww w. j a v a 2 s . c om*/ @Override public AWSCredentials getCredentials() { checkNotEmpty(); if (reuseLastProvider && lastProvider != null) { return lastProvider.getCredentials(); } AmazonClientException lastException = null; for (AWSCredentialsProvider provider : providers) { try { AWSCredentials credentials = provider.getCredentials(); if ((credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) || (credentials instanceof AnonymousAWSCredentials)) { lastProvider = provider; LOG.debug("Using credentials from {}", provider); return credentials; } } catch (AmazonClientException e) { lastException = e; LOG.debug("No credentials provided by {}: {}", provider, e.toString(), e); } } // no providers had any credentials. Rethrow the last exception // or create a new one. String message = "No AWS Credentials provided by " + listProviderNames(); if (lastException != null) { message += ": " + lastException; } throw new AmazonClientException(message, lastException); }
From source file:org.freeeed.aws.SimpleQueueServiceSample.java
License:Apache License
public static void main(String[] args) throws Exception { /*//from w w w . j a v a2 s.com * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); // TODO restore System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(message.toString()); } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:org.hashbang.util.AutoDiscoverQueue.java
License:Open Source License
private static AmazonSQS init() { /*//w w w .j av a 2 s .com * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); return sqs; }
From source file:org.juneja.eventdemo.utils.AmazonSimpleQueueService.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/*from ww w. j a v a 2 s. co m*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.DEFAULT_REGION); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue // System.out.println("Creating a new SQS queue called MyQueue.\n"); // CreateQueueRequest createQueueRequest = new CreateQueueRequest("TestQueue_EventDriven_2"); // String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); GetQueueUrlResult queueResult = sqs.getQueueUrl("TestQueue_EventDriven_2"); String myQueueUrl = queueResult.getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message //System.out.println("Sending a message to MyQueue.\n"); //sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my new text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); System.out.println("Number of messages : " + messages.size()); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message //System.out.println("Deleting a message.\n"); //String messageRecieptHandle = messages.get(0).getReceiptHandle(); //sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); // Delete a queue /** System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); **/ } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:org.kmbmicro.chatwebsocket.DbString.java
public static void init() { try {/*from ww w. j a v a 2s . c om*/ credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/sandiwibowo/.aws/credentials), and is in valid format.", e); } AmazonDynamoDBClient dynamoDBAWS = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDBAWS.setRegion(usWest2); dynamoDB = new DynamoDB(dynamoDBAWS); }