Example usage for com.amazonaws AmazonServiceException getMessage

List of usage examples for com.amazonaws AmazonServiceException getMessage

Introduction

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

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:com.dynamo.DynamoData.java

License:Open Source License

public List<MatchBean> getData() {

    try {//from w  w w  .j  a v a  2  s.c o m
        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 {//  ww  w .ja v  a 2  s.  com
        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 {//from   ww w  .jav a 2  s.  co 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   www . j ava2s .  c  o m
        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  ww.  ja  v  a 2  s .co  m*/
        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.ec2box.manage.action.EC2KeyAction.java

License:Apache License

@Action(value = "/manage/submitEC2Key", results = {
        @Result(name = "input", location = "/manage/view_ec2_keys.jsp"),
        @Result(name = "success", location = "/manage/viewEC2Keys.action", type = "redirect") })
public String submitEC2Key() {

    String retVal = SUCCESS;/*from  ww  w  .j a  v a  2 s.  c o m*/

    try {

        //get AWS credentials from DB
        AWSCred awsCred = AWSCredDB.getAWSCred(ec2Key.getAwsCredId());

        //set  AWS credentials for service
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(),
                awsCred.getSecretKey());

        //create service
        AmazonEC2 service = new AmazonEC2Client(awsCredentials, AWSClientConfig.getClientConfig());
        service.setEndpoint(ec2Key.getEc2Region());

        //create key pair request
        CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest();
        createKeyPairRequest.withKeyName(ec2Key.getKeyNm());

        //call service
        CreateKeyPairResult createKeyPairResult = service.createKeyPair(createKeyPairRequest);
        //get key pair result
        KeyPair keyPair = createKeyPairResult.getKeyPair();

        //set private key
        String privateKey = keyPair.getKeyMaterial();
        ec2Key.setPrivateKey(privateKey);

        //add to db
        EC2KeyDB.saveEC2Key(ec2Key);

    } catch (AmazonServiceException ex) {
        addActionError(ex.getMessage());
        retVal = INPUT;
    }

    return retVal;

}

From source file:com.ec2box.manage.action.EC2KeyAction.java

License:Apache License

@Action(value = "/manage/importEC2Key", results = {
        @Result(name = "input", location = "/manage/view_ec2_keys.jsp"),
        @Result(name = "success", location = "/manage/viewEC2Keys.action", type = "redirect") })
public String importEC2Key() {

    String retVal = SUCCESS;//from www .  ja  v a  2s .c  o  m

    try {
        //get AWS credentials from DB
        AWSCred awsCred = AWSCredDB.getAWSCred(ec2Key.getAwsCredId());

        //set  AWS credentials for service
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(),
                awsCred.getSecretKey());

        //create service
        AmazonEC2 service = new AmazonEC2Client(awsCredentials, AWSClientConfig.getClientConfig());
        service.setEndpoint(ec2Key.getEc2Region());

        //describe key pair request
        DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
        describeKeyPairsRequest.setKeyNames(Arrays.asList(ec2Key.getKeyNm()));

        //call service
        DescribeKeyPairsResult describeKeyPairsResult = service.describeKeyPairs(describeKeyPairsRequest);

        if (describeKeyPairsResult != null && describeKeyPairsResult.getKeyPairs().size() > 0) {
            //add to db
            EC2KeyDB.saveEC2Key(ec2Key);
        } else {
            addActionError("Imported key does not exist on AWS");
            retVal = INPUT;
        }

    } catch (AmazonServiceException ex) {
        addActionError(ex.getMessage());
        retVal = INPUT;

    }

    return retVal;

}

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

License:Open Source License

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

    try {//from w  w w .  jav  a  2  s .com
        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   www.ja v  a  2 s  . co  m
    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;
}