Example usage for com.amazonaws AmazonClientException AmazonClientException

List of usage examples for com.amazonaws AmazonClientException AmazonClientException

Introduction

In this page you can find the example usage for com.amazonaws AmazonClientException AmazonClientException.

Prototype

public AmazonClientException(String message, Throwable t) 

Source Link

Document

Creates a new AmazonClientException with the specified message, and root cause.

Usage

From source file:assign1.simpledb1.java

License:Open Source License

public List<record> query(String word) throws Exception {
    /*//w  w  w.  ja va  2  s  .com
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials*/

    ArrayList<record> result = new ArrayList<record>();
    AWSCredentials credentials = null;
    try {
        credentials = new PropertiesCredentials(
                simpledb.class.getResourceAsStream("AwsCredentials.properties"));
    } 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/huanglin/.aws/credentials), and is in valid format.", e);
    }

    AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    String myDomain = "Twitter";

    String filter = word;
    String nextToken = null;
    SelectResult selectResult = null;
    do {
        String selectExpression = "";
        if (word.equals("all"))
            selectExpression = "select * from MyStore LIMIT 2500";
        else
            selectExpression = "select * from " + myDomain + " where content like '%" + filter
                    + "%' LIMIT 2500";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        selectRequest.setNextToken(nextToken);
        selectResult = sdb.select(selectRequest);
        nextToken = selectResult.getNextToken();
        List<Item> list = selectResult.getItems();
        for (Item item : list) {
            System.out.println("    itemIndex: " + item.getName());
            List<Attribute> attributeTmp = new ArrayList<Attribute>();
            attributeTmp = item.getAttributes();
            record tmp = new record();
            for (int i = 0; i < 5; i++) {
                if (attributeTmp.get(i).getName().equals("content"))
                    tmp.content = attributeTmp.get(i).getValue();
                else if (attributeTmp.get(i).getName().equals("geoLat"))
                    tmp.x = Double.parseDouble(attributeTmp.get(i).getValue());
                else if (attributeTmp.get(i).getName().equals("Username"))
                    tmp.username = attributeTmp.get(i).getValue();
                else if (attributeTmp.get(i).getName().equals("Location"))
                    tmp.location = attributeTmp.get(i).getValue();
                else
                    tmp.y = Double.parseDouble(attributeTmp.get(i).getValue());
            }
            result.add(tmp);
        }
    } while (nextToken != null);

    return result;
}

From source file:awskinesis.AmazonKinesisApplicationSample.java

License:Apache License

private static void init() {
    // Ensure the JVM will refresh the cached IP values of AWS resources (e.g. service endpoints).
    java.security.Security.setProperty("networkaddress.cache.ttl", "60");

    /*//from  www .  ja v  a 2s. c o m
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (~/.aws/credentials).
     */
    credentialsProvider = new ProfileCredentialsProvider();
    try {
        credentialsProvider.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);
    }
}

From source file:awskinesis.AmazonKinesisRecordProducerSample.java

License:Apache License

private static void init() throws Exception {
    /*//from w w w .j av a  2s.c  o  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);
    }

    kinesis = new AmazonKinesisClient(credentials);
    kinesis.setEndpoint("kinesis.cn-north-1.amazonaws.com.cn");
}

From source file:br.com.faccilitacorretor.middleware.dynamo.AmazonDynamoDBSample.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
 *//* w w w  .  j  a v  a 2  s  . c  om*/
private static void init() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (/home/turbiani/.aws/credentials).
     */
    AWSCredentials credentials = null;
    try {
        credentials = new BasicAWSCredentials(PropertiesConfig.getInstance().get("ACCESS_KEY"),
                PropertiesConfig.getInstance().get("SECRET_ACCESS_KEY"));
    } 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 (/home/turbiani/.aws/credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(usEast1);
}

From source file:br.com.ingenieux.mojo.aws.util.BeanstalkerS3Client.java

License:Apache License

@Override
public PutObjectResult putObject(PutObjectRequest req) throws AmazonClientException, AmazonServiceException {
    if (!multipartUpload) {
        return super.putObject(req);
    }//from  w  w w . j  av  a2s. c  o m

    final long contentLen = TransferManagerUtils.getContentLength(req);

    String tempFilename = req.getKey() + ".tmp";
    String origFilename = req.getKey();

    req.setKey(tempFilename);

    XProgressListener progressListener = new XProgressListener();

    req.setGeneralProgressListener(new ProgressListenerChain(progressListener));

    progressListener.setContentLen(contentLen);
    progressListener.setUpload(transferManager.upload(req));
    progressListener.setSilentUpload(silentUpload);

    try {
        progressListener.getUpload().waitForCompletion();
    } catch (InterruptedException e) {
        throw new AmazonClientException(e.getMessage(), e);
    }

    CopyObjectRequest copyReq = new CopyObjectRequest(req.getBucketName(), tempFilename, req.getBucketName(),
            origFilename);

    copyObject(copyReq);

    deleteObject(new DeleteObjectRequest(req.getBucketName(), tempFilename));

    return null;
}

From source file:Cloud.Tweets.SimpleQueueServiceSample.java

License:Open Source License

public AmazonSQS createSQSs() {
    System.out.println("helloooooooooooo");
    AWSCredentials credentials;//w  w w. j  av  a2  s .c om
    try {
        credentials = new PropertiesCredentials(
                SimpleQueueServiceSample.class.getResourceAsStream("AwsCredentials.Properties"));
        System.out.println("hello");

        //credentials = new ProfileCredentialsProvider("~/.aws/AwsCredentials.Properties").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/daniel/.aws/credentials), and is in valid format.", e);
    }

    AmazonSQS sqs = new AmazonSQSClient(credentials);
    System.out.println(sqs.toString());
    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");

    // Create a queue
    System.out.println("Creating a new SQS queue called MyQueue.\n");
    CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue");
    myQueueUrl = sqs.createQueue(createQueueRequest).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();
    return sqs;
}

From source file:cloudworker.RemoteWorker.java

License:Apache License

private static void init() throws Exception {
    /*/*w  w  w  .  j  a  va  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);
    }

    ec2 = new AmazonEC2Client(credentials);
    sqs = new AmazonSQSClient(credentials);

    Region usEast1 = Region.getRegion(Regions.US_EAST_1);

    ec2.setRegion(usEast1);
    sqs.setRegion(usEast1);

    dynamoDB = new DynamoDBService(credentials);

}

From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java

License:Open Source License

private void deleteMessagePayloadFromS3(String receiptHandle) {
    String s3MsgBucketName = getFromReceiptHandleByMarker(receiptHandle,
            SQSExtendedClientConstants.S3_BUCKET_NAME_MARKER);
    String s3MsgKey = getFromReceiptHandleByMarker(receiptHandle, SQSExtendedClientConstants.S3_KEY_MARKER);
    try {//  w w w. j a  v a 2s  .co m
        clientConfiguration.getAmazonS3Client().deleteObject(s3MsgBucketName, s3MsgKey);
    } catch (AmazonServiceException e) {
        String errorMessage = "Failed to delete the S3 object which contains the SQS message payload. SQS message was not deleted.";
        LOG.error(errorMessage, e);
        throw new AmazonServiceException(errorMessage, e);
    } catch (AmazonClientException e) {
        String errorMessage = "Failed to delete the S3 object which contains the SQS message payload. SQS message was not deleted.";
        LOG.error(errorMessage, e);
        throw new AmazonClientException(errorMessage, e);
    }
    LOG.info("S3 object deleted, Bucket name: " + s3MsgBucketName + ", Object key: " + s3MsgKey + ".");
}

From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java

License:Open Source License

private MessageS3Pointer readMessageS3PointerFromJSON(String messageBody) {

    MessageS3Pointer s3Pointer = null;//from   www.j  ava 2  s .c  o m
    try {
        JsonDataConverter jsonDataConverter = new JsonDataConverter();
        s3Pointer = jsonDataConverter.deserializeFromJson(messageBody, MessageS3Pointer.class);
    } catch (Exception e) {
        String errorMessage = "Failed to read the S3 object pointer from an SQS message. Message was not received.";
        LOG.error(errorMessage, e);
        throw new AmazonClientException(errorMessage, e);
    }
    return s3Pointer;
}

From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java

License:Open Source License

private String getTextFromS3(String s3BucketName, String s3Key) {
    GetObjectRequest getObjectRequest = new GetObjectRequest(s3BucketName, s3Key);
    String embeddedText = null;//  w  w w.j  a v  a  2s .  c o  m
    S3Object obj = null;
    try {
        obj = clientConfiguration.getAmazonS3Client().getObject(getObjectRequest);
    } catch (AmazonServiceException e) {
        String errorMessage = "Failed to get the S3 object which contains the message payload. Message was not received.";
        LOG.error(errorMessage, e);
        throw new AmazonServiceException(errorMessage, e);
    } catch (AmazonClientException e) {
        String errorMessage = "Failed to get the S3 object which contains the message payload. Message was not received.";
        LOG.error(errorMessage, e);
        throw new AmazonClientException(errorMessage, e);
    }
    try {
        InputStream objContent = obj.getObjectContent();
        java.util.Scanner objContentScanner = new java.util.Scanner(objContent, "UTF-8");
        objContentScanner.useDelimiter("\\A");
        embeddedText = objContentScanner.hasNext() ? objContentScanner.next() : "";
        objContentScanner.close();
        objContent.close();
    } catch (IOException e) {
        String errorMessage = "Failure when handling the message which was read from S3 object. Message was not received.";
        LOG.error(errorMessage, e);
        throw new AmazonClientException(errorMessage, e);
    }
    return embeddedText;
}