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:controllers.s3modify.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*//from  w  w w .  j av a2 s. com
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (/home/sravya/.aws/credentials).
     *
     * TransferManager manages a pool of threads, so we create a
     * single instance and share it throughout our application.
     */
    try {
        credentials = new ProfileCredentialsProvider("default").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 (/home/sravya/.aws/credentials), and is in valid format.", e);
    }

    int argLen = args.length;
    Region reg = Region.getRegion(Regions.US_WEST_2);

    int hack = 0;
    int userrequests;

    try {
        userrequests = Integer.parseInt(args[argLen - 1]);
    } catch (NumberFormatException e) {
        userrequests = 1;
        String use = args[argLen - 1];
        if (use.equals("Australia")) {
            hack = 0;
        } else if (use.equals("SouthAfrica")) {
            hack = 1;
        } else if (use.equals("India")) {
            hack = 2;
        } else if (use.equals("UnitedKingdom")) {
            hack = 3;
        } else if (use.equals("China")) {
            hack = 4;
        } else if (use.equals("Germany")) {
            hack = 5;
        } else if (use.equals("France")) {
            hack = 6;
        } else if (use.equals("Japan")) {
            hack = 7;
        } else if (use.equals("Thailand")) {
            hack = 8;
        } else if (use.equals("Spain")) {
            hack = 9;
        }
    }

    int filecount = 0;
    for (int m = 0; m < argLen - 1; m++) {
        filecount = filecount + 1;
    }

    int numphotos = filecount;
    int numIDCs = numphotos;

    int locationInd = 0;
    long[] cusize = new long[6];
    long photosspace = 0;

    for (int mm = 0; mm < userrequests; mm++) {
        for (int i = 0; i < cusize.length; i++)
            cusize[i] = 0;

        ArrayList<Integer> originalgarph = new ArrayList<Integer>();

        loadObj ob = calculateload();
        long[] regionload = new long[5];
        regionload = ob.load;
        for (int i = 0; i < regionload.length; i++) {
            if (regionload[i] == 0) {
                regionload[i] = 1000;
            }
        }
        for (int i = 0; i < 5; i++) {
            System.out.println(regionload[i]);
            double diffload = 0;
            double avgload = 0;
            int count = 0;

            for (int j = 0; j < 5; j++) {
                if (j != i) {
                    avgload = avgload + regionload[j];
                    count++;

                }

            }

            avgload = (avgload / count);
            diffload = (regionload[i] / avgload);
            System.out.println("avgload: " + avgload);
            System.out.println("diffload: " + diffload);
            if (diffload < 1.8) {

                originalgarph.add(i + 1);
            }

        }

        availSpaceNorthCal = maxsize - regionload[0];
        photosspace = numphotos * 6000;
        if (availSpaceNorthCal < photosspace) {
            availSpaceNorthCal = maxsize;
            cusize[1] = availSpaceNorthCal / 6000;

        } else {
            cusize[1] = availSpaceNorthCal / 6000;
        }
        availSpaceOregon = maxsize - regionload[1];
        photosspace = numphotos * 6000;
        if (availSpaceOregon < photosspace) {
            availSpaceOregon = maxsize;
            cusize[2] = availSpaceOregon / 6000;

        } else {
            cusize[2] = availSpaceOregon / 6000;
        }
        availSpaceSingapore = maxsize - regionload[2];
        photosspace = numphotos * 6000;
        if (availSpaceSingapore < photosspace) {
            availSpaceSingapore = maxsize;
            cusize[3] = availSpaceSingapore / 6000;

        } else {
            cusize[3] = availSpaceSingapore / 6000;
        }
        availSpaceTokyo = maxsize - regionload[3];
        photosspace = numphotos * 6000;
        if (availSpaceTokyo < photosspace) {
            availSpaceTokyo = maxsize;
            cusize[4] = availSpaceTokyo / 6000;

        } else {
            cusize[4] = availSpaceTokyo / 6000;
        }
        availSpaceSydney = maxsize - regionload[4];
        photosspace = numphotos * 6000;
        if (availSpaceSydney < photosspace) {
            availSpaceSydney = maxsize;
            cusize[5] = availSpaceSydney / 6000;

        } else {
            cusize[5] = availSpaceSydney / 6000;
        }

        int cou = originalgarph.size();
        String fileName = algorithmPath + "request.alg";
        PrintWriter writer = new PrintWriter(fileName, "UTF-8");

        for (int i = 0; i < cou; i++) {
            int value = originalgarph.get(i);
            writer.print(value + " ");
            System.out.println(" IDC " + String.valueOf(value));
        }
        writer.println();
        for (int i = 0; i < originalgarph.size(); i++) {
            int j = originalgarph.get(i);

            writer.print(cusize[j] + " ");

        }
        writer.println();
        writer.println(1);
        if (userrequests != 1) {
            locationInd = randInt(0, 9);

        } else {
            locationInd = hack;
        }
        writer.println(locationInd);
        System.out.println(" locationInd " + String.valueOf(locationInd));
        writer.println(numphotos);
        System.out.println(" numphotos " + String.valueOf(numphotos));
        writer.println(numIDCs);
        System.out.println(" numIDCs " + String.valueOf(numIDCs));
        writer.close();
        originalgarph.clear();

        try {

            String prg = "import sys\nprint int(sys.argv[1])+int(sys.argv[2])\n";
            String pythonCmd = "/usr/bin/python " + algorithmPath + "ramd.py";
            Process p = Runtime.getRuntime().exec(pythonCmd);

            try {
                Thread.sleep(2000); //1000 milliseconds is one second.
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
            String fileName1 = algorithmPath + "work.alg";
            File log = new File(fileName1);

            int filenumber = 0;

            String fileName2 = algorithmPath + "filenumber.alg";
            Scanner numberscan = new Scanner(new File(fileName2));

            if (numberscan.hasNextLine()) {
                filenumber = numberscan.nextInt();

            } else {
                filenumber = 1;

            }
            numberscan.close();

            ArrayList<String> photofnames = new ArrayList<String>();
            ArrayList<String> argFNames = new ArrayList<String>();
            for (int ll = 0; ll < argLen - 1; ll++) {

                photofnames.add(photosPath + args[ll] + ".bmp");
                argFNames.add(args[ll]);
                System.out.println("Will upload " + photosPath + args[ll] + ".bmp");
            }

            String sCurrentLine;
            BufferedReader br = null;
            br = new BufferedReader(new FileReader(fileName1));
            int currLine = 0;
            Integer userNumber = 0;
            ArrayList<Integer> idcSet = new ArrayList<Integer>();
            ArrayList<Integer> photonos = new ArrayList<Integer>();
            int currU = 0;

            while ((sCurrentLine = br.readLine()) != null) {

                if (currLine % 3 == 0) {
                    userNumber = Integer.parseInt(sCurrentLine);
                    idcSet.clear();
                    photonos.clear();
                }
                if (currLine % 3 == 1) {
                    String[] idcnums = sCurrentLine.split(" ");
                    String regions = "";
                    String regionsFileName = algorithmPath + "regions.alg";
                    PrintWriter regionwriter = new PrintWriter(regionsFileName, "UTF-8");

                    for (int numIdcs = 0; numIdcs < idcnums.length; numIdcs++) {
                        idcSet.add(Integer.parseInt(idcnums[numIdcs]));

                        if (idcnums[numIdcs].equals("1")) {
                            regions = "region1";
                            regionwriter.print(regions + " ");
                        } else if (idcnums[numIdcs].equals("2")) {
                            regions = "region2";
                            regionwriter.print(regions + " ");

                        } else if (idcnums[numIdcs].equals("3")) {
                            regions = "region3";
                            regionwriter.print(regions + " ");

                        } else if (idcnums[numIdcs].equals("4")) {
                            regions = "region4";
                            regionwriter.print(regions + " ");

                        } else if (idcnums[numIdcs].equals("5")) {

                            regions = "region5";
                            regionwriter.print(regions + " ");
                        }

                        System.out.println("IDCs: " + idcnums[numIdcs]);
                    }
                    regionwriter.close();
                }
                if (currLine % 3 == 2) {
                    String[] idcpnums = sCurrentLine.split(" ");
                    for (int numIdcs = 0; numIdcs < idcpnums.length; numIdcs++) {
                        photonos.add(Integer.parseInt(idcpnums[numIdcs]));

                    }
                    ArrayList<String> smallestBnames = new ArrayList<String>();
                    ArrayList<String> bucketnames = new ArrayList<String>();
                    for (int tot = 0; tot < idcSet.size(); tot++) {
                        smallestBnames.add(ob.bnames[idcSet.get(tot) - 1]);
                    }
                    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
                    int currPno = 0;
                    ArrayList<String> transferThese = new ArrayList<String>();
                    ArrayList<Integer> transferThesebno = new ArrayList<Integer>();
                    System.out.println(String.valueOf(idcpnums.length));
                    //upload everything to 1 bucket
                    for (int numIdcs = 0; numIdcs < idcpnums.length; numIdcs++) {
                        for (int numP = 0; numP < photonos.get(numIdcs); numP++) {
                            String uploadFileName = photofnames.get(currPno);
                            String keyName = String.valueOf(userNumber) + "_" + argFNames.get(currPno) + '_'
                                    + filenumber++ + ".bmp";
                            if (numIdcs > 0) {
                                transferThese.add(keyName);
                                transferThesebno.add(numIdcs);

                            }
                            try {
                                System.out.println("Uploading " + uploadFileName + " to "
                                        + smallestBnames.get(0) + " with keyname " + keyName);
                                File file = new File(uploadFileName);
                                s3client.putObject(new PutObjectRequest(smallestBnames.get(0), keyName, file));

                            } 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());
                            }
                            currPno++;
                        }
                    }
                    //transfer other files
                    System.out.println("Number of files to transfer " + String.valueOf(transferThese.size()));
                    for (int tot = 0; tot < transferThese.size(); tot++) {
                        String source = smallestBnames.get(0);
                        String dest = smallestBnames.get(transferThesebno.get(tot));
                        String fname = transferThese.get(tot);
                        String src = "s3://" + source + "/" + fname;
                        String d = "s3://" + dest;
                        String cmd = "aws s3 mv " + src + " " + d + "\n";
                        System.out.println("Moving " + src + " to " + d + "\n");
                        Process p1 = Runtime.getRuntime().exec(cmd);

                    }
                    currU++;
                    if (currU >= 1) {
                        transferThese.clear();
                        transferThesebno.clear();
                        photofnames.clear();
                        argFNames.clear();
                        smallestBnames.clear();
                        break;
                    }
                }
                currLine++;

            }
            String fileNumberFilePath = algorithmPath + "filenumber.alg";
            PrintWriter numberwriter = new PrintWriter(fileNumberFilePath, "UTF-8");

            numberwriter.println(filenumber);
            numberwriter.close();

        } catch (Exception e) {
        }
    }
    //        String s = null;
    //        Process p1 = Runtime.getRuntime().exec("ls -alrt");
    //        
    //        BufferedReader stdInput = new BufferedReader(new
    //             InputStreamReader(p1.getInputStream()));
    //
    //        BufferedReader stdError = new BufferedReader(new
    //             InputStreamReader(p1.getErrorStream()));
    //
    //        // read the output from the command
    //        System.out.println("Here is the standard output of the command:\n");
    //        while ((s = stdInput.readLine()) != null) {
    //            System.out.println(s);
    //        }
}

From source file:Database.CustomerData.java

License:Open Source License

/**
 *
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.ProfilesConfigFile
 * @see com.amazonaws.ClientConfiguration
 *//*  w ww .  java2  s. co m*/
private static void init() throws Exception {

    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);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
    dynamoDB.setEndpoint("http://localhost:8000");
}

From source file:de.kopis.glacier.commands.UploadMultipartArchiveCommand.java

License:Open Source License

private String uploadParts(String uploadId, File file, final String vaultName, final Long partSize)
        throws AmazonServiceException, NoSuchAlgorithmException, AmazonClientException, IOException {
    FileInputStream fileToUpload = null;
    String checksum = "";
    try {//ww  w .j  a  va 2  s  .com
        long currentPosition = 0;
        List<byte[]> binaryChecksums = new LinkedList<byte[]>();
        fileToUpload = new FileInputStream(file);
        int counter = 1;
        int total = (int) Math.ceil(file.length() / (double) partSize);
        while (currentPosition < file.length()) {
            long length = partSize;
            if (currentPosition + partSize > file.length()) {
                length = file.length() - currentPosition;
            }

            Exception failedException = null;
            boolean completed = false;
            int tries = 0;

            while (!completed && tries < 5) {
                tries++;
                InputStream inputSubStream = newInputSubstream(file, currentPosition, length);
                inputSubStream.mark(-1);
                checksum = TreeHashGenerator.calculateTreeHash(inputSubStream);
                byte[] binaryChecksum = BinaryUtils.fromHex(checksum);
                inputSubStream.reset();
                String range = "bytes " + currentPosition + "-" + (currentPosition + length - 1) + "/*";
                UploadMultipartPartRequest req = new UploadMultipartPartRequest().withChecksum(checksum)
                        .withBody(inputSubStream).withRange(range).withUploadId(uploadId)
                        .withVaultName(vaultName);
                try {
                    UploadMultipartPartResult partResult = client.uploadMultipartPart(req);
                    log.info(String.format("Part %d/%d (%s) uploaded, checksum: %s", counter, total, range,
                            partResult.getChecksum()));
                    completed = true;
                    binaryChecksums.add(binaryChecksum);
                } catch (Exception e) {
                    failedException = e;
                } finally {
                    if (inputSubStream != null) {
                        try {
                            inputSubStream.close();
                        } catch (IOException ex) {
                            log.debug("Ignore failure in closing the Closeable", ex);
                        }
                    }
                }
            }
            if (!completed && failedException != null)
                throw new AmazonClientException("Failed operation", failedException);
            currentPosition += partSize;
            ++counter;
        }

        checksum = TreeHashGenerator.calculateTreeHash(binaryChecksums);
    } finally {
        if (fileToUpload != null) {
            fileToUpload.close();
        }
    }

    return checksum;
}

From source file:de.kopis.glacier.commands.UploadMultipartArchiveCommand.java

License:Open Source License

private InputSubstream newInputSubstream(File file, long startingPosition, long length) {
    try {//from   w  w  w . ja  v a  2  s  . c o  m
        return new InputSubstream(new RepeatableFileInputStream(file), startingPosition, length, true);
    } catch (FileNotFoundException e) {
        throw new AmazonClientException("Unable to find file '" + file.getAbsolutePath() + "'", e);
    }
}

From source file:DynamicProvisioning.Requests.java

License:Open Source License

private void init() throws Exception {

    AWSCredentials credentials = null;/*from www  .  j  a v a2s  .c  o  m*/
    try {
        credentials = new ProfileCredentialsProvider("default").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 (/home/jay2106/.aws/credentials), and is in valid format.", e);
    }

    ec2 = new AmazonEC2Client(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    ec2.setRegion(usWest2);
}

From source file:DynamicProvisioning.SecGroupCreate.java

License:Open Source License

public static void main(String[] args) {

    AWSCredentials credentials = null;//from  w  w  w.ja  va2s  .  c  o  m
    try {

        credentials = new ProfileCredentialsProvider("default").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 (/home/jay2106/.aws/credentials), and is in valid format.", e);
    }

    // Create the AmazonEC2Client object so we can call various APIs.
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    ec2.setRegion(usWest2);

    // Create a new security group.
    try {
        CreateSecurityGroupRequest securityGroupRequest = new CreateSecurityGroupRequest("launch-wizard-3",
                "launch-wizard-3");
        CreateSecurityGroupResult result = ec2.createSecurityGroup(securityGroupRequest);
        System.out.println(String.format("Security group created: [%s]", result.getGroupId()));
    } catch (AmazonServiceException ase) {
        // Likely this means that the group is already created, so ignore.
        System.out.println(ase.getMessage());
    }

    String ipAddr = "0.0.0.0/0";

    // Create a range that you would like to populate.
    List<String> ipRanges = Collections.singletonList(ipAddr);

    List<IpPermission> ipPermission = new ArrayList<IpPermission>();
    ipPermission.add(new IpPermission().withIpProtocol("tcp").withFromPort(new Integer(0))
            .withToPort(new Integer(65535)).withIpRanges(ipRanges));
    ipPermission.add(new IpPermission().withIpProtocol("tcp").withFromPort(new Integer(22))
            .withToPort(new Integer(22)).withIpRanges(ipRanges));
    ipPermission.add(new IpPermission().withIpProtocol("udp").withFromPort(new Integer(0))
            .withToPort(new Integer(65535)).withIpRanges(ipRanges));

    // Open up port 23 for TCP traffic to the associated IP from above (e.g. ssh traffic).
    // IpPermission ipPermission = new IpPermission()

    //ipPermission.
    List<IpPermission> ipPermissions = new ArrayList<IpPermission>(ipPermission);

    try {
        // Authorize the ports to the used.
        AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSecurityGroupIngressRequest(
                "launch-wizard-3", ipPermissions);
        ec2.authorizeSecurityGroupIngress(ingressRequest);
        System.out.println(String.format("Ingress port authroized: [%s]", ipPermissions.toString()));
    } catch (AmazonServiceException ase) {
        // Ignore because this likely means the zone has already been authorized.
        System.out.println(ase.getMessage());
    }
}

From source file:edu.hawaii.kscmfeedprocessor.AmazonKinesisApplicationSample.java

License:Open Source License

private void init() {
    logger.info("init");
    logger.info("Profile: {}", profile);

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

    /*/*www  .  j  a  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(profile);
    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:gov.usgs.cida.iplover.util.ImageStorage.java

public static AmazonS3 prepS3Client() {

    AWSCredentials credentials = null;//from  w  w w.  j  a  v  a 2 s  .co m
    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);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);

    return s3;
}

From source file:hu.cloud.edu.SimpleQueueServiceSample.java

License:Open Source License

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

    /*/*  w  w w  .  j  a va 2s  .  co  m*/
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (C:\\Users\\Isaac\\.aws\\credentials).
     */
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider("default").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 (C:\\Users\\Isaac\\.aws\\credentials), and is in valid format.", e);
    }

    AmazonSQS sqs = new AmazonSQSClient(credentials);
    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");

    try {
        // Create a queue
        System.out.println("Creating a new SQS queue called MyQueue.\n");
        CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue");
        String 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();

        // Send a message
        System.out.println("Sending a message to MyQueue.\n");
        sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text."));

        // Receive messages
        System.out.println("Receiving messages from MyQueue.\n");
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
        List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
        for (Message message : messages) {
            System.out.println("  Message");
            System.out.println("    MessageId:     " + message.getMessageId());
            System.out.println("    ReceiptHandle: " + message.getReceiptHandle());
            System.out.println("    MD5OfBody:     " + message.getMD5OfBody());
            System.out.println("    Body:          " + message.getBody());
            for (Entry<String, String> entry : message.getAttributes().entrySet()) {
                System.out.println("  Attribute");
                System.out.println("    Name:  " + entry.getKey());
                System.out.println("    Value: " + entry.getValue());
            }
        }
        System.out.println();

        // Delete a message
        System.out.println("Deleting a message.\n");
        String messageRecieptHandle = messages.get(0).getReceiptHandle();
        sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle));

        // Delete a queue
        System.out.println("Deleting the test queue.\n");
        sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl));
    } 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:hudson.plugins.ec2.EC2Cloud.java

License:Open Source License

/**
 * Connects to EC2 and returns {@link AmazonEC2}, which can then be used to communicate with EC2.
 *//*w w w  .ja  va2 s.co m*/
public synchronized AmazonEC2 connect() throws AmazonClientException {
    try {
        if (connection == null) {
            connection = connect(createCredentialsProvider(), getEc2EndpointUrl());
        }
        return connection;
    } catch (IOException e) {
        throw new AmazonClientException("Failed to retrieve the endpoint", e);
    }
}