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:org.gytheio.content.handler.s3.S3ContentReferenceHandlerImpl.java

License:Open Source License

@Override
public boolean isContentReferenceExists(ContentReference contentReference) {
    if (!isContentReferenceSupported(contentReference)) {
        return false;
    }/* w w  w . j  a  va  2 s .  c  o  m*/
    try {
        String s3Url = getS3UrlFromHttpUrl(contentReference.getUri());

        if (logger.isDebugEnabled()) {
            logger.debug("Checking existence of reference: " + s3Url);
        }
        // Get the object and retrieve the input stream
        S3Object object = s3.getObject(new GetObjectRequest(s3BucketName, getRelativePath(s3Url)));
        return object != null;
    } catch (AmazonServiceException e) {
        throw new ContentIOException("Failed to check existence of content: " + e.getMessage(), e);
    } catch (Throwable t) {
        // Otherwise don't really care why, just that it doesn't exist
        return false;
    }
}

From source file:org.hashbang.util.AutoDiscoverQueue.java

License:Open Source License

public static boolean sendInfo(String msg) {

    try {//www  . jav a2s. c  o  m
        AmazonSQS sqs = init();
        //"To be filled by JobTracker"
        sqs.sendMessage(new SendMessageRequest(QUEUE_URL, msg));
        return true;

    } 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 {
        return false;
    }

}

From source file:org.hashbang.util.AutoDiscoverQueue.java

License:Open Source License

public static String getInfo() {

    Message message = null;//w w w .  j a  v a 2s  .  c om
    String msg = null;

    try {
        // Receive messages
        AmazonSQS sqs = init();
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(QUEUE_URL);
        sqs.receiveMessage(receiveMessageRequest);
        message = sqs.receiveMessage(receiveMessageRequest).getMessages().get(0);

        msg = message.getBody();
        sqs.deleteMessage(new DeleteMessageRequest(QUEUE_URL, message.getReceiptHandle()));

    } 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 {
        return msg;
    }
}

From source file:org.jdamico.s3.components.S3Component.java

License:Apache License

public void upload(AppProperties appProperties, File uploadFile, String keyName) throws TopLevelException {
    AmazonS3 s3client = getS3Client(appProperties);
    try {// w  ww . j  a v  a2 s.co  m

        Utils.getInstance().handleVerboseLog(appProperties, 'i', "Uploading a new object to S3 from a file\n");
        s3client.putObject(new PutObjectRequest(appProperties.getBucketnName(), keyName, uploadFile));

    } catch (AmazonServiceException ase) {
        Utils.getInstance().handleVerboseLog(appProperties, 'e',
                "Caught an AmazonServiceException, which " + "means your request made it "
                        + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        Utils.getInstance().handleVerboseLog(appProperties, 'e', "Error Message:    " + ase.getMessage());
        Utils.getInstance().handleVerboseLog(appProperties, 'e', "HTTP Status Code: " + ase.getStatusCode());
        Utils.getInstance().handleVerboseLog(appProperties, 'e', "AWS Error Code:   " + ase.getErrorCode());
        Utils.getInstance().handleVerboseLog(appProperties, 'e', "Error Type:       " + ase.getErrorType());
        Utils.getInstance().handleVerboseLog(appProperties, 'e', "Request ID:       " + ase.getRequestId());

        throw new TopLevelException(appProperties, ase);

    } catch (AmazonClientException ace) {
        throw new TopLevelException(appProperties,
                "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. Error Message: " + ace.getMessage());

    }
}

From source file:org.jenkinsci.plugins.appio.service.S3Service.java

License:Open Source License

/**
 * @param bucketName//from   w  ww . j  av  a2  s.c o m
 * @param keyName
 * @param uploadFile
 * @return
 */
public String getUploadUrl(String bucketName, String keyName, File uploadFile)
        throws AmazonServiceException, AmazonClientException {

    try {
        s3client.putObject(new PutObjectRequest(bucketName, keyName, uploadFile)
                .withCannedAcl(CannedAccessControlList.PublicRead));

    } catch (AmazonServiceException ase) {
        LOGGER.fine("AmazonServiceException");
        LOGGER.fine("Error Message:    " + ase.getMessage());
        LOGGER.fine("HTTP Status Code: " + ase.getStatusCode());
        LOGGER.fine("AWS Error Code:   " + ase.getErrorCode());
        LOGGER.fine("Error Type:       " + ase.getErrorType());
        LOGGER.fine("Request ID:       " + ase.getRequestId());
        throw ase;
    } catch (AmazonClientException ace) {
        LOGGER.fine("AmazonClientException");
        LOGGER.fine("Error Message: " + ace.getMessage());
        throw ace;
    }

    String s3PublicUrl = "https://s3.amazonaws.com/" + bucketName + "/" + keyName;
    LOGGER.fine("S3 public URL: " + s3PublicUrl);
    return s3PublicUrl;
}

From source file:org.jumpmind.symmetric.io.RedshiftBulkDatabaseWriter.java

License:Open Source License

protected void flush() {
    if (loadedRows > 0) {
        stagedInputFile.close();//from  w ww.  j av a  2 s  .  co m
        statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
        AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
        if (isNotBlank(s3Endpoint)) {
            s3client.setEndpoint(s3Endpoint);
        }
        String objectKey = stagedInputFile.getFile().getName();
        try {
            s3client.putObject(bucket, objectKey, stagedInputFile.getFile());
        } catch (AmazonServiceException ase) {
            log.error("Exception from AWS service: " + ase.getMessage());
        } catch (AmazonClientException ace) {
            log.error("Exception from AWS client: " + ace.getMessage());
        }

        try {
            JdbcSqlTransaction jdbcTransaction = (JdbcSqlTransaction) transaction;
            Connection c = jdbcTransaction.getConnection();
            String sql = "COPY " + getTargetTable().getFullyQualifiedTableName() + " ("
                    + Table.getCommaDeliminatedColumns(table.getColumns()) + ") FROM 's3://" + bucket + "/"
                    + objectKey + "' CREDENTIALS 'aws_access_key_id=" + accessKey + ";aws_secret_access_key="
                    + secretKey + "' CSV DATEFORMAT 'YYYY-MM-DD HH:MI:SS' "
                    + (needsExplicitIds ? "EXPLICIT_IDS" : "")
                    + (isNotBlank(appendToCopyCommand) ? (" " + appendToCopyCommand) : "");
            Statement stmt = c.createStatement();

            log.debug(sql);
            stmt.execute(sql);
            stmt.close();
            transaction.commit();
        } catch (SQLException ex) {
            throw platform.getSqlTemplate().translate(ex);
        } finally {
            statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS);
        }

        stagedInputFile.delete();
        try {
            s3client.deleteObject(bucket, objectKey);
        } catch (AmazonServiceException ase) {
            log.error("Exception from AWS service: " + ase.getMessage());
        } catch (AmazonClientException ace) {
            log.error("Exception from AWS client: " + ace.getMessage());
        }

        createStagingFile();
        loadedRows = 0;
        loadedBytes = 0;
    }
}

From source file:org.juneja.eventdemo.utils.AmazonSimpleQueueService.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
     * (~/.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);
    }

    AmazonSQS sqs = new AmazonSQSClient(credentials);
    Region usWest2 = Region.getRegion(Regions.DEFAULT_REGION);
    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("TestQueue_EventDriven_2");
        // String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();

        GetQueueUrlResult queueResult = sqs.getQueueUrl("TestQueue_EventDriven_2");
        String myQueueUrl = queueResult.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 new text."));

        // Receive messages
        System.out.println("Receiving messages from MyQueue.\n");
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl);
        List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

        System.out.println("Number of messages : " + messages.size());

        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:org.mobicents.servlet.restcomm.amazonS3.S3AccessTool.java

License:Open Source License

public URI uploadFile(final String fileToUpload) {
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, securityKey);
    AmazonS3 s3client = new AmazonS3Client(credentials);
    try {//from  www.  ja v a  2 s  . c o  m
        StringBuffer bucket = new StringBuffer();
        bucket.append(bucketName);
        if (folder != null && !folder.isEmpty())
            bucket.append("/").append(folder);
        URI fileUri = URI.create(fileToUpload);
        logger.info("File to upload to S3: " + fileUri.toString());
        File file = new File(fileUri);
        //            while (!file.exists()){}
        //            logger.info("File exist: "+file.exists());
        //First generate the Presigned URL, buy some time for the file to be written on the disk
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        if (daysToRetainPublicUrl > 0) {
            cal.add(Calendar.DATE, daysToRetainPublicUrl);
        } else {
            //By default the Public URL will be valid for 180 days
            cal.add(Calendar.DATE, 180);
        }
        date = cal.getTime();
        GeneratePresignedUrlRequest generatePresignedUrlRequestGET = new GeneratePresignedUrlRequest(
                bucket.toString(), file.getName());
        generatePresignedUrlRequestGET.setMethod(HttpMethod.GET);
        generatePresignedUrlRequestGET.setExpiration(date);

        URL downloadUrl = s3client.generatePresignedUrl(generatePresignedUrlRequestGET);

        //Second upload the file to S3
        //            while (!file.exists()){}
        while (!FileUtils.waitFor(file, 30)) {
        }
        if (file.exists()) {
            PutObjectRequest putRequest = new PutObjectRequest(bucket.toString(), file.getName(), file);
            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentType(new MimetypesFileTypeMap().getContentType(file));
            putRequest.setMetadata(metadata);
            if (reducedRedundancy)
                putRequest.setStorageClass(StorageClass.ReducedRedundancy);
            s3client.putObject(putRequest);

            if (removeOriginalFile) {
                removeLocalFile(file);
            }
            return downloadUrl.toURI();
        } else {
            logger.error("Timeout waiting for the recording file: " + file.getAbsolutePath());
            return null;
        }
    } catch (AmazonServiceException ase) {
        logger.error("Caught an AmazonServiceException");
        logger.error("Error Message:    " + ase.getMessage());
        logger.error("HTTP Status Code: " + ase.getStatusCode());
        logger.error("AWS Error Code:   " + ase.getErrorCode());
        logger.error("Error Type:       " + ase.getErrorType());
        logger.error("Request ID:       " + ase.getRequestId());
        return null;
    } catch (AmazonClientException ace) {
        logger.error("Caught an AmazonClientException, which ");
        logger.error("Error Message: " + ace.getMessage());
        return null;
    } catch (URISyntaxException e) {
        logger.error("URISyntaxException: " + e.getMessage());
        return null;
    }
}

From source file:org.nuxeo.aws.elastictranscoder.GenericAWSClient.java

License:Open Source License

/**
 * Utility method returning formatted details about the error. It the error
 * is not AmazonServiceException or AmazonClientException, the method just
 * returns <code>e.getMessage()</code>
 *
 * @param e, an AmazonServiceException or AmazonClientException
 * @return/*from w  w  w.  j  av a2  s  .c om*/
 *
 * @since 7.1
 */
public static String buildDetailedMessageFromAWSException(Exception e) {

    String message = "";

    if (e instanceof AmazonServiceException) {
        AmazonServiceException ase = (AmazonServiceException) e;
        message = "Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.";
        message += "\nError Message:    " + ase.getMessage();
        message += "\nHTTP Status Code: " + ase.getStatusCode();
        message += "\nAWS Error Code:   " + ase.getErrorCode();
        message += "\nError Type:       " + ase.getErrorType();
        message += "\nRequest ID:       " + ase.getRequestId();

    } else if (e instanceof AmazonClientException) {
        AmazonClientException ace = (AmazonClientException) e;
        message = "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.";
        message += "\nError Message: " + ace.getMessage();

    } else {
        message = e.getMessage();
    }

    return message;
}

From source file:org.openflamingo.fs.s3.S3ObjectProvider.java

License:Apache License

@Override
public boolean copy(String from, String to) {
    //        Assert.hasLength(from, " ?? ?  'from'?  .");
    Assert.hasLength(from, "Please enter the source path.");
    //        Assert.hasLength(to, " ?  'to'  .");
    Assert.hasLength(to, "Please enter the destination path.");

    String fromBucket = S3Utils.getBucket(from);
    String toBucket = S3Utils.getBucket(to);
    String fromKey = StringUtils.remove(from, "/" + fromBucket + "/");
    String toKey = S3Utils.getObjectKey(to);
    String fileName = getFileName(fromKey);

    try {//  ww w  .j a va 2 s.c o m
        CopyObjectRequest copyObjectRequest = new CopyObjectRequest(fromBucket, fromKey, toBucket,
                toKey + fileName);
        awsClient.copyObject(copyObjectRequest);
        return true;
    } 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());

        //            throw new FileSystemException("??    . ? ? ? .", ase);
        throw new FileSystemException("Cannot copy the file.", ase);
    } 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());
        //            throw new FileSystemException("??    . ? ? ? .", ace);
        throw new FileSystemException("Cannot copy the file.", ace);
    }
}