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:jp.dqneo.amazons3.sample.S3Sample.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*  w w w  .  ja  v  a  2s . c o m*/
     * 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
     */
    AmazonS3 s3 = new AmazonS3Client(
            new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties")));

    s3.setEndpoint("https://s3-ap-northeast-1.amazonaws.com");

    String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String key = "2/foo/bar";

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

    try {

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
         */
        System.out.println("Uploading a new object to S3 from a file\n");
        PutObjectRequest p = new PutObjectRequest(bucketName, key, createSampleFile());
        s3.putObject(p);
        System.out.println("ok\n");

    } 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:main.java.ddb.loader.DDBLoaderUtils.java

License:Apache License

static void createTable() throws Exception {
    try {/*w  ww  .j av  a  2s  . c o  m*/
        CreateTableRequest create_req = new CreateTableRequest().withTableName(DDBSampleLoader.TBL_NAME)
                .withKeySchema(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Id")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(DDBSampleLoader.RCU)
                                .withWriteCapacityUnits(DDBSampleLoader.WCU));

        DDBSampleLoader.log.info("Creating a new table ...");
        TableUtils.createTableIfNotExists(DDBSampleLoader.ddb_client, create_req);

        DDBSampleLoader.log.info("Waiting for the table status to be 'ACTIVE' ...");
        TableUtils.waitUntilActive(DDBSampleLoader.ddb_client, DDBSampleLoader.TBL_NAME);

    } catch (AmazonServiceException e) {
        DDBSampleLoader.log.error("Caught an AmazonServiceException ...");
        DDBSampleLoader.log.error("Error Message:    " + e.getMessage());
        DDBSampleLoader.log.error("HTTP Status Code: " + e.getStatusCode());
        DDBSampleLoader.log.error("AWS Error Code:   " + e.getErrorCode());
        DDBSampleLoader.log.error("Error Type:       " + e.getErrorType());
        DDBSampleLoader.log.error("Request ID:       " + e.getRequestId());

    } catch (AmazonClientException e) {
        DDBSampleLoader.log.error("Caught an AmazonClientException ...");
        DDBSampleLoader.log.error("Error Message:    " + e.getMessage());
    }
}

From source file:modules.storage.AmazonS3Storage.java

License:Open Source License

private void logAmazonServiceException(AmazonServiceException ase) {
    logger.error("Caught an AmazonServiceException, which " + "means your request made it "
            + "to Amazon S3, but was rejected with an error response " + "for some reason." + " Error Message: "
            + ase.getMessage() + " HTTP Status Code: " + ase.getStatusCode() + " AWS Error Code: "
            + ase.getErrorCode() + " Error Type: " + ase.getErrorType() + " Request ID: " + ase.getRequestId(),
            ase);/*from w w w.  ja va  2  s .c o  m*/
}

From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java

License:Open Source License

@Override
public Set<S3ObjectReference> listObjects(String prefix) throws IOException {
    AmazonS3 client = getClient();//from   w ww. j  a  v a2 s  .  c o  m
    Set<S3ObjectReference> result = new LinkedHashSet<>(100);
    try {
        final ListObjectsV2Request req = new ListObjectsV2Request();
        req.setBucketName(bucketName);
        req.setMaxKeys(maximumKeysPerRequest);
        req.setPrefix(prefix);
        ListObjectsV2Result listResult;
        do {
            listResult = client.listObjectsV2(req);

            for (S3ObjectSummary objectSummary : listResult.getObjectSummaries()) {
                result.add(new S3ObjectReference(objectSummary.getKey(), objectSummary.getSize(),
                        objectSummary.getLastModified()));
            }
            req.setContinuationToken(listResult.getNextContinuationToken());
        } while (listResult.isTruncated() == true);

    } catch (AmazonServiceException e) {
        log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(),
                e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId());
        throw new RemoteServiceException("Error listing S3 objects at " + prefix, e);
    } catch (AmazonClientException e) {
        log.debug("Error communicating with AWS: {}", e.getMessage());
        throw new IOException("Error communicating with AWS", e);
    }
    return result;
}

From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java

License:Open Source License

@Override
public String getObjectAsString(String key) throws IOException {
    AmazonS3 client = getClient();/*from w ww  .j  a  v  a 2s  .c  o m*/
    try {
        return client.getObjectAsString(bucketName, key);
    } catch (AmazonServiceException e) {
        log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(),
                e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId());
        throw new RemoteServiceException("Error getting S3 object at " + key, e);
    } catch (AmazonClientException e) {
        log.debug("Error communicating with AWS: {}", e.getMessage());
        throw new IOException("Error communicating with AWS", e);
    }
}

From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java

License:Open Source License

@Override
public S3Object getObject(String key) throws IOException {
    AmazonS3 client = getClient();/*ww  w.  ja v  a  2 s.c  om*/
    try {
        return client.getObject(bucketName, key);
    } catch (AmazonServiceException e) {
        log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(),
                e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId());
        throw new RemoteServiceException("Error getting S3 object at " + key, e);
    } catch (AmazonClientException e) {
        log.debug("Error communicating with AWS: {}", e.getMessage());
        throw new IOException("Error communicating with AWS", e);
    }
}

From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java

License:Open Source License

@Override
public S3ObjectReference putObject(String key, InputStream in, ObjectMetadata objectMetadata)
        throws IOException {
    AmazonS3 client = getClient();//w  ww.  j  av  a 2  s .  c om
    try {
        PutObjectRequest req = new PutObjectRequest(bucketName, key, in, objectMetadata);
        client.putObject(req);
        return new S3ObjectReference(key, objectMetadata.getContentLength(), objectMetadata.getLastModified());
    } catch (AmazonServiceException e) {
        log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(),
                e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId());
        throw new RemoteServiceException("Error putting S3 object at " + key, e);
    } catch (AmazonClientException e) {
        log.debug("Error communicating with AWS: {}", e.getMessage());
        throw new IOException("Error communicating with AWS", e);
    }
}

From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java

License:Open Source License

@Override
public void deleteObjects(Set<String> keys) throws IOException {
    AmazonS3 client = getClient();//from w w  w.j a v a  2s  .c  o  m
    try {
        DeleteObjectsRequest req = new DeleteObjectsRequest(bucketName)
                .withKeys(keys.stream().map(k -> new KeyVersion(k)).collect(Collectors.toList()));
        client.deleteObjects(req);
    } catch (AmazonServiceException e) {
        log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(),
                e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId());
        throw new RemoteServiceException("Error deleting S3 objects " + keys, e);
    } catch (AmazonClientException e) {
        log.debug("Error communicating with AWS: {}", e.getMessage());
        throw new IOException("Error communicating with AWS", e);
    }
}

From source file:org.akvo.flow.deploy.Deploy.java

License:Open Source License

public static void main(String[] args) throws IOException {
    if (args.length != 7) {
        System.err.println("Missing argument, please provide S3 access key, S3 secret key, "
                + "instanceId , apkPath, version, GAE username and GAE password");
        return;/*from   w w w.  ja  v  a 2  s. co m*/
    }

    File file = new File(args[APK_PATH]);
    if (!file.exists()) {
        System.err.println("Can't find apk at " + args[APK_PATH]);
        return;
    }

    final String accessKey = args[S3_ACCESS_KEY];
    final String secretKey = args[S3_SECRET_KEY];
    final String instance = args[INSTANCE_ID];
    final String accountId = args[ACCOUNT_ID];
    final String accountSecret = args[ACCOUNT_SECRET];
    final String version = args[VERSION];

    final String s3Path = "apk/" + instance + "/" + file.getName();
    final String s3Url = "http://akvoflow.s3.amazonaws.com/apk/" + instance + '/' + file.getName();
    final String host = instance + ".appspot.com";

    try {
        uploadS3(accessKey, secretKey, s3Path, file);
        updateVersion(host, accountId, accountSecret, s3Url, version, getMD5Checksum(file));
    } catch (AmazonServiceException ase) {
        System.err.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.err.println("Error Message:    " + ase.getMessage());
        System.err.println("HTTP Status Code: " + ase.getStatusCode());
        System.err.println("AWS Error Code:   " + ase.getErrorCode());
        System.err.println("Error Type:       " + ase.getErrorType());
        System.err.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.err.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.err.println("Error Message: " + ace.getMessage());
    } catch (IOException e) {
        System.err.println("Error updating APK version in GAE");
        e.printStackTrace();
    }

}

From source file:org.apache.airavata.gfac.ec2.AmazonInstanceScheduler.java

License:Apache License

/**
 * Monitors the CPU Utilization using Amazon Cloud Watch. In order to monitor the instance, Cloud Watch Monitoring
 * should be enabled for the running instance.
 *
 * @param credential EC2 credentials/* w  ww .j ava  2  s.c  o m*/
 * @param instanceId instance id
 * @return average CPU utilization of the instance
 */
public static double monitorInstance(AWSCredentials credential, String instanceId) {
    try {
        AmazonCloudWatchClient cw = new AmazonCloudWatchClient(credential);

        long offsetInMilliseconds = 1000 * 60 * 60 * 24;
        GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
                .withStartTime(new Date(new Date().getTime() - offsetInMilliseconds)).withNamespace("AWS/EC2")
                .withPeriod(60 * 60)
                .withDimensions(new Dimension().withName("InstanceId").withValue(instanceId))
                .withMetricName("CPUUtilization").withStatistics("Average", "Maximum").withEndTime(new Date());
        GetMetricStatisticsResult getMetricStatisticsResult = cw.getMetricStatistics(request);

        double avgCPUUtilization = 0;
        List dataPoint = getMetricStatisticsResult.getDatapoints();
        for (Object aDataPoint : dataPoint) {
            Datapoint dp = (Datapoint) aDataPoint;
            avgCPUUtilization = dp.getAverage();
            log.info(instanceId + " instance's average CPU utilization : " + dp.getAverage());
        }

        return avgCPUUtilization;

    } catch (AmazonServiceException ase) {
        log.error("Caught an AmazonServiceException, which means the request was made  "
                + "to Amazon EC2, but was rejected with an error response for some reason.");
        log.error("Error Message:    " + ase.getMessage());
        log.error("HTTP Status Code: " + ase.getStatusCode());
        log.error("AWS Error Code:   " + ase.getErrorCode());
        log.error("Error Type:       " + ase.getErrorType());
        log.error("Request ID:       " + ase.getRequestId());

    }
    return 0;
}