Example usage for com.amazonaws AmazonServiceException getStatusCode

List of usage examples for com.amazonaws AmazonServiceException getStatusCode

Introduction

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

Prototype

public int getStatusCode() 

Source Link

Document

Returns the HTTP status code that was returned with this service exception.

Usage

From source file:com.dynamo.DynamoData.java

License:Open Source License

public List<MatchBean> getData() {

    try {/* w w w.ja  v  a 2  s  .c  om*/
        List<MatchBean> dataList = new ArrayList<MatchBean>();
        String tableName = "Matches";

        ScanRequest scanRequest = new ScanRequest(tableName);
        ScanResult scanResult = dynamoDB.scan(scanRequest);

        List<Map<String, AttributeValue>> list = new ArrayList<Map<String, AttributeValue>>();
        list = scanResult.getItems();
        for (Map<String, AttributeValue> map : list) {
            String match_id = map.get("match_id").getN();
            String awayTeam = map.get("awayTeam").getS();
            String currentMatchState = map.get("currentMatchState").getS();
            if (currentMatchState.equals("$$")) {
                currentMatchState = "";
            }
            String homeTeam = map.get("homeTeam").getS();
            String isWom = map.get("isWomen").getS();
            String match_Type = map.get("match_type").getS();
            String name = map.get("name").getS();
            String series = map.get("series").getS();
            String status = map.get("status").getS();
            String awayOvers;
            String homeOvers;
            String homeScore;
            if (map.get("awayOvers") != null) {
                awayOvers = map.get("awayOvers").getS();
            } else {
                awayOvers = "";
            }

            if (map.get("homeOvers") != null) {
                homeOvers = map.get("homeOvers").getS();
            } else {
                homeOvers = "";
            }
            if (map.get("homeScore") != null) {
                homeScore = map.get("homeScore").getS();
            } else {
                homeScore = "";
            }

            String won;
            if (map.get("won") != null) {
                won = map.get("won").getS();
            } else {
                won = "";
            }

            MatchBean data = new MatchBean();
            data.setMatchId(match_id);
            data.setAwayTeam(awayTeam);
            data.setCurrentMatchesState(currentMatchState);
            data.setHomeTeam(homeTeam);
            data.setIsWom(isWom);
            data.setName(name);
            data.setSeries(series);
            data.setAwayOvers(awayOvers);
            data.setHomeOvers(homeOvers);
            data.setHomeScore(homeScore);
            data.setMatchType(match_Type);
            data.setWon(won);
            data.setStatus(status);
            dataList.add(data);
            System.out.println("Match :" + data.toString());
        }
        System.out.println("Result: " + scanResult);
        return dataList;
    } 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());
        return null;
    } 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());
        return null;
    }
}

From source file:com.dynamo.DynamoData.java

License:Open Source License

public List<SeriesBean> getSeriesData() {

    try {/* w ww.  ja  v  a2 s. c  o m*/
        List<SeriesBean> dataList = new ArrayList<SeriesBean>();
        String tableName = "series";

        ScanRequest scanRequest = new ScanRequest(tableName);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        dynamoDB.describeTable(tableName).getTable();
        List<Map<String, AttributeValue>> list = new ArrayList<Map<String, AttributeValue>>();
        list = scanResult.getItems();

        for (Map<String, AttributeValue> map : list) {
            String series_id = map.get("series_id").getN();
            String endDateTime = map.get("endDateTime").getS();
            String seriesName = map.get("name").getS();

            String startDateTime = map.get("startDateTime").getS();
            String status = map.get("status").getS();

            SeriesBean data = new SeriesBean();
            data.setSeriesId(series_id);
            data.setName(seriesName);
            data.setEndDatetime(endDateTime);
            data.setStartDateTime(startDateTime);
            data.setStatus(status);
            dataList.add(data);
            System.out.println(data.toString());
        }
        System.out.println("Result: " + scanResult);
        return dataList;
    } 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());
        return null;
    } 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());
        return null;
    }
}

From source file:com.dynamo.DynamoData.java

License:Open Source License

public List<Statistics> getPerfData() {

    try {//from   w  w  w .  j a  v a  2 s . c o m
        List<PerfBean> dataList = new ArrayList<PerfBean>();
        String tableName = "Performance";

        ScanRequest scanRequest = new ScanRequest(tableName);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        dynamoDB.describeTable(tableName).getTable();
        List<Map<String, AttributeValue>> list = new ArrayList<Map<String, AttributeValue>>();
        list = scanResult.getItems();
        String perf_id;
        for (Map<String, AttributeValue> map : list) {
            perf_id = map.get("perf_id").getS();
            String lambdaStart = map.get("lambdaStart").getS();
            String dynamoSave = map.get("dynamoStop").getS();
            String records = map.get("number_req").getN();
            System.out.println("records :********" + records);
            PerfBean data = new PerfBean();
            data.setDynamoStop(dynamoSave);
            data.setPerf_id(perf_id);
            data.setLambdaStart(lambdaStart);
            data.setRecords(records);

            dataList.add(data);
            System.out.println(data.toString());
        }
        List<Statistics> statistics = MyUI.stats;

        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS a");
        //  Date d = new Date(formatter);

        for (Statistics statistics2 : statistics) {
            for (PerfBean dataBean : dataList) {
                if (dataBean.getPerf_id().equals(statistics2.getKey())) {
                    Date lambdaStart;
                    Date dynamoComplete;
                    try {
                        dynamoComplete = formatter.parse(dataBean.getDynamoStop());
                        lambdaStart = formatter.parse(dataBean.getLambdaStart());
                        statistics2.setLambdaStart(lambdaStart);
                        statistics2.setDynamoComplete(dynamoComplete);
                        statistics2.setTotalRecords(dataBean.getRecords());
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
        System.out.println("Result: " + scanResult);
        return statistics;
    } 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());
        return null;
    } 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());
        return null;
    }
}

From source file:com.eBilling.util.S3Example.java

void uploadfile(AWSCredentials credentials) {
    AmazonS3 s3client = new AmazonS3Client(credentials);

    try {//  w  ww.  j a va2 s. c o m
        File file = new File(uploadFileName);
        PutObjectRequest p = new PutObjectRequest(bucketName, keyName, file);
        p.setCannedAcl(CannedAccessControlList.PublicRead);
        s3client.putObject(p);
        String _finalUrl = "https://" + bucketName + ".s3.amazonaws.com/" + keyName;
        System.out.println(_finalUrl);
    } 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());
    }
}

From source file:com.eBilling.util.S3Example.java

void deletefile(AWSCredentials credentials1) {
    AmazonS3 s3client = new AmazonS3Client(credentials1);
    try {/*from  w w  w.jav  a  2s .com*/
        s3client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException.");
        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.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.eBilling.util.S3Example.java

void downloadfile(AWSCredentials credentials2) throws IOException {
    AmazonS3 s3client = new AmazonS3Client(credentials2);
    try {//from  w  w w  .ja  va2 s  .  com
        System.out.println("Downloading an object");
        S3Object s3object = s3client.getObject(new GetObjectRequest(bucketName, keyName));
        System.out.println("Content-Type: " + s3object.getObjectMetadata().getContentType());
        InputStream input = s3object.getObjectContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        while (true) {
            String line = reader.readLine();
            if (line == null)
                break;

            System.out.println("    " + line);
        }
        System.out.println();
    } 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());
    }
}

From source file:com.erudika.para.queue.AWSQueueUtils.java

License:Apache License

private static void logException(AmazonServiceException ase) {
    logger.error("AmazonServiceException: error={}, statuscode={}, awserrcode={}, errtype={}, reqid={}",
            ase.toString(), ase.getStatusCode(), ase.getErrorCode(), ase.getErrorType(), ase.getRequestId());
}

From source file:com.espressologic.aws.sqs.SqsAmazonService.java

License:Open Source License

public static void main(String[] args) throws Exception {

    try {/*  ww  w .j a v  a 2 s. c  o m*/
        credentials = null;
        // SqsAmazonService sqsAmazonService = new SqsAmazonService("OUXKJKKW82ZX2IRMTPPBVYDQX","F99Sz5llVDM0Y4X7FVSZCgYGTos5rJ2/A5nPLkB476U");

        SqsAmazonService.myQueueUrl = createQueue("EspressoLogic9");
        listQueues();
        String msgID = sendMessage("My Message Test");
        System.out.println("Message ID " + msgID);
        String messageID = readMessage(msgID);
        //deleteMessages(messageID);
        deleteQueue();
    } 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());
    } finally {
        credentials = null;
    }
}

From source file:com.eucalyptus.blockstorage.S3SnapshotTransfer.java

License:Open Source License

private <F, T> T retryAfterRefresh(Function<F, T> function, F input, int retries)
        throws SnapshotTransferException {
    int failedAttempts = 0;
    T output = null;//from w  w  w .  ja va  2  s  .  c  om
    do {
        try {
            output = function.apply(input);
            break;
        } catch (AmazonServiceException e) {
            if (failedAttempts < retries && e.getStatusCode() == HttpResponseStatus.FORBIDDEN.getCode()) {
                LOG.debug("Snapshot transfer operation failed because of " + e.getMessage()
                        + ". Will refresh credentials and retry");
                failedAttempts++;
                initializeEucaS3Client();
                continue;
            } else {
                throw new SnapshotTransferException("Snapshot transfer operation failed because of", e);
            }
        } catch (Exception e) {
            throw new SnapshotTransferException("Snapshot transfer operation failed because of", e);
        }
    } while (failedAttempts <= retries);

    return output;
}

From source file:com.example.S3Sample02.java

License:Open Source License

public static void main(String[] args) throws IOException {

    /*/*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);
    }

    AmazonS3 s3 = new AmazonS3Client(credentials);

    //        AP_SOUTHEAST_2

    //       Region usWest2 = Region.getRegion(Regions.AP_SOUTHEAST_2 );
    //       s3.setRegion(usWest2);

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

    String bucketName = "imos-test-data-1";

    String key = "MyObjectKey" + UUID.randomUUID();

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

    try {
        /*
         * Create a new S3 bucket - Amazon S3 bucket names are globally unique,
         * so once a bucket name has been taken by any user, you can't create
         * another bucket with that same name.
         *
         * You can optionally specify a location for your bucket if you want to
         * keep your data closer to your applications or users.
         */
        //            System.out.println("Creating bucket " + bucketName + "\n");
        //            s3.createBucket(bucketName);

        /*
         * List the buckets in your account
         */
        /*            System.out.println("Listing buckets");
                    for (Bucket bucket : s3.listBuckets()) {
        System.out.println(" - " + bucket.getName());
                    }
                    System.out.println();
        */

        /*
         * 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");
        s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));

        System.out.println("done\n");

        /*
         * Download an object - When you download an object, you get all of
         * the object's metadata and a stream from which to read the contents.
         * It's important to read the contents of the stream as quickly as
         * possibly since the data is streamed directly from Amazon S3 and your
         * network connection will remain open until you read all the data or
         * close the input stream.
         *
         * GetObjectRequest also supports several other options, including
         * conditional downloading of objects based on modification times,
         * ETags, and selectively downloading a range of an object.
         */
        System.out.println("Downloading an object");
        S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        System.out.println("Content-Type: " + object.getObjectMetadata().getContentType());
        displayTextInputStream(object.getObjectContent());

        System.out.println("done\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();
        System.out.println("done\n");

        /*
         * Delete an object - Unless versioning has been turned on for your bucket,
         * there is no way to undelete an object, so use caution when deleting objects.
         */

        //            System.out.println("Deleting an object\n");
        //            s3.deleteObject(bucketName, key);

        /*
         * Delete a bucket - A bucket must be completely empty before it can be
         * deleted, so remember to delete any objects from your buckets before
         * you try to delete them.
         */
        /*
                    System.out.println("Deleting bucket " + bucketName + "\n");
                    s3.deleteBucket(bucketName);
        */

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