Example usage for com.amazonaws AmazonServiceException getErrorType

List of usage examples for com.amazonaws AmazonServiceException getErrorType

Introduction

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

Prototype

public ErrorType getErrorType() 

Source Link

Document

Indicates who is responsible for this exception (caller, service, or unknown).

Usage

From source file:S3Controller.UploadImages.java

public void UploadToS3(String bucketname, String filename, String filepath) {
    //  public static void main(String[] args) {

    AWSCredentials credentials = null;/*from   www . j a  v a2 s.co  m*/
    String aws_access_key_id = "PUT_YOUR_aws_access_key_id_HERE";
    String aws_secret_access_key = "PUT_YOUR_aws_secret_access_key_HERE";
    String bucketName = bucketname; //"zillionbucket";
    String fileName = filename; //"javaee_duke_image.jpg";
    String localpath = filepath; //"C:\\Users\\Hariom\\Documents\\NetBeansProjects\\JavaApplication9\\src\\ProcessedImages\\javaee_duke_image.jpg";
    try {
        credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);//.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 AP_SOUTHEAST_1 = Region.getRegion(Regions.AP_SOUTHEAST_1);
    s3.setRegion(AP_SOUTHEAST_1);

    try {

        s3.putObject(new PutObjectRequest(bucketName, fileName, new File(localpath))
                .withCannedAcl(CannedAccessControlList.PublicRead));

        System.out.println("File Uploaded to S3: " + fileName);

    }

    catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, 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 S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}

From source file:sample.AmazonDynamoDBSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from   w w  w.  j  a va2  s . c o  m*/

    try {
        String tableName = "my-favorite-movies-table";

        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
        TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                .getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        waitForTableToBecomeAvailable(tableName);

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);

        // Add an item
        Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James",
                "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Add another item
        item = newItem("Airplane", 1980, "*****", "James", "Billy Bob");
        putItemRequest = new PutItemRequest(tableName, item);
        putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);

        // Scan items for movies with a year attribute greater than 1985
        HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
                .withAttributeValueList(new AttributeValue().withN("1985"));
        scanFilter.put("year", condition);
        ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        System.out.println("Result: " + scanResult);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, 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 AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:scheduler.SQSService.java

License:Apache License

public void batchSend(List<SendMessageBatchRequestEntry> entries) {

    try {/*from   w  w  w  .j  a va  2s. c o  m*/
        // Send batch messages
        //System.out.println("\nSending a message to jobQueue.\n");

        SendMessageBatchRequest batchRequest = new SendMessageBatchRequest().withQueueUrl(queueUrl);
        batchRequest.setEntries(entries);

        SendMessageBatchResult batchResult = sqs.sendMessageBatch(batchRequest);

        // sendMessageBatch can return successfully, and yet individual batch
        // items fail. So, make sure to retry the failed ones.
        if (!batchResult.getFailed().isEmpty()) {
            //System.out.println("Retry sending failed messages...");

            List<SendMessageBatchRequestEntry> failedEntries = new ArrayList<SendMessageBatchRequestEntry>();
            Iterator<SendMessageBatchRequestEntry> iter = entries.iterator();

            while (iter.hasNext()) {
                if (batchResult.getFailed().contains(iter.next())) {
                    failedEntries.add((SendMessageBatchRequestEntry) iter.next());
                }
            }

            batchRequest.setEntries(failedEntries);
            sqs.sendMessageBatch(batchRequest);
        }

    } 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:se252.jan15.calvinandhobbes.project0.IIScCampusMapGETProxyService.java

License:Open Source License

private static String getCategoryData(String category) {
    AmazonSQS queueClient = Queues.getQueue();
    String resp = null;// w  w  w .ja va 2s.  c  om
    try {
        // Send a message
        queueClient.sendMessage(new SendMessageRequest(Queues.req, category));

        // Receive messages
        Boolean flag = true;
        while (flag) {
            ReceiveMessageRequest receiveReq = new ReceiveMessageRequest(Queues.resp);
            receiveReq.setWaitTimeSeconds(10);
            List<Message> messages = queueClient.receiveMessage(receiveReq).getMessages();
            for (Message message : messages) {
                String[] strs = message.getBody().split("\\$");
                if (strs[0].equals(category)) {
                    flag = false;
                    resp = strs[1];
                    queueClient
                            .deleteMessage(new DeleteMessageRequest(Queues.resp, message.getReceiptHandle()));
                    break;
                }
            }
        }
    } 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());
    }
    return resp;
}

From source file:searchengine.WordToDoc.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from  w  w w .  j  ava 2 s  .  c om*/

    try {
        String tableName = "my-favorite-movies-table";

        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is already ACTIVE");
        } else {
            // Create a table with a primary hash key named 'name', which holds a string
            CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                    .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name")
                            .withAttributeType(ScalarAttributeType.S))
                    .withProvisionedThroughput(
                            new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
            TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                    .getTableDescription();
            System.out.println("Created Table: " + createdTableDescription);

            // Wait for it to become active
            System.out.println("Waiting for " + tableName + " to become ACTIVE...");
            Tables.awaitTableToBecomeActive(dynamoDB, tableName);
        }

        /*// Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);
                
        // Add an item
        Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara");
        PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);*/

        /*// Add another item
        item = newItem("Airplane", 1980, "*****", "James", "Billy Bob");
        putItemRequest = new PutItemRequest(tableName, item);
        putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);
                
        item = newItem("Billrplane", 1980, "*****", "James", "Billy Bob");
        putItemRequest = new PutItemRequest(tableName, item);
        putItemResult = dynamoDB.putItem(putItemRequest);
        System.out.println("Result: " + putItemResult);*/

        // Scan items for movies with a year attribute greater than 1985
        HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.BEGINS_WITH)
                .withAttributeValueList(new AttributeValue().withS("Bill"));
        scanFilter.put("name", condition);
        ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        for (int i = 0; i < 2; i++) {

            System.out.println("Result: " + scanResult.getItems().get(i).get("year"));
        }

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, 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 AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:services.SQSQueue.java

License:Open Source License

/**
 * This function create a queue//from  w w  w.  j  a  v  a 2 s . com
 * @param QueueName the Queue  Name
 * @param status 0 to create a queue 
       1 to connect to exist queue
 */
public void createQueue(String QueueName) {
    try {
        System.out.println("Creating a new SQS queue called " + QueueName);
        sqs.setEndpoint("sqs.us-east-1.amazonaws.com");
        CreateQueueRequest createQueueRequest = new CreateQueueRequest(QueueName);
        queueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();
    }

    catch (AmazonServiceException ase) {
        queueUrl = "";
        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) {
        queueUrl = "";
        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:services.SQSQueue.java

License:Open Source License

public String isExists(String QueueName) {
    try {/*from w ww  .j a v a2 s  . c o m*/
        System.out.println("connecting to existing SQS queue called " + QueueName + "\n");
        GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(QueueName);
        this.queueUrl = this.sqs.getQueueUrl(getQueueUrlRequest).getQueueUrl();
    }

    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());
        this.queueUrl = null;
    }

    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());
        this.queueUrl = null;
    }

    return this.queueUrl;
}

From source file:services.SQSQueue.java

License:Open Source License

/**
 * This function sends message to queue.
 * @param msg the message to send/* w w  w . j  a  v  a  2 s . c o  m*/
 */
public int sendMsg(String msg) {
    try {
        System.out.println("Sending a message to " + QueueName + ".\n");
        sqs.sendMessage(new SendMessageRequest(queueUrl, msg));
        this.numberOfMsg++;
    }

    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("Org message" + this.QueueName + " m is " + msg);
        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());
        numberOfMsg--;
        return -1;
    }

    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());
        numberOfMsg--;
        return -1;
    }

    return 0;
}

From source file:services.SQSQueue.java

License:Open Source License

/**
 * This function delete the queue//from w w  w  . j  a  v a2  s . c  o  m
 */
public void deleteQueue() {
    try {
        System.out.println("Deleting the test queue.\n");
        sqs.deleteQueue(new DeleteQueueRequest(queueUrl));
        this.queueUrl = "";
        this.numberOfMsg = 0;
    }

    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:servlet.FileUploadServlet.java

private void putInBucket(String fileName, String id) throws IOException {

    AWSCredentials awsCreds = new PropertiesCredentials(
            new File("/Users/paulamontojo/Desktop/AwsCredentials.properties"));
    AmazonS3 s3client = new AmazonS3Client(awsCreds);

    try {/* ww  w .  j a  v a  2 s  .c om*/
        System.out.println("Uploading a new object to S3 from a file\n");
        File file = new File(uploadFileName);
        s3client.putObject(new PutObjectRequest(bucketName, fileName, file));

        GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName,
                fileName);
        generatePresignedUrlRequest.setMethod(HttpMethod.GET); // Default.

        URL s = s3client.generatePresignedUrl(generatePresignedUrlRequest);
        insertUrl(s.toString(), id);
        System.out.println(s);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, 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 "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}