Example usage for com.amazonaws AmazonServiceException getErrorType

List of usage examples for com.amazonaws AmazonServiceException getErrorType

Introduction

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

Prototype

public ErrorType getErrorType() 

Source Link

Document

Indicates who is responsible for this exception (caller, service, or unknown).

Usage

From source file:cloudExplorer.Delete.java

License:Open Source License

public void run() {
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);/*from  w w  w . j ava 2  s  . com*/

    try {

        if (version != null) {
            s3Client.deleteVersion(new DeleteVersionRequest(bucket, what, version));
        } else {
            s3Client.deleteObject(new DeleteObjectRequest(bucket, what));
        }
        if (!debug) {
            NewJFrame.jTextArea1.append("\nDeleted object: " + what);
        }
        calibrate();
    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }
    } catch (Exception delete) {
    }
}

From source file:cloudExplorer.Get.java

License:Open Source License

public void run() {
    String message = null;//from w  ww .  j  a v a  2  s . c  o  m
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    File file = new File(what);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        long t1 = System.currentTimeMillis();
        S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, what, version));
        InputStream objectData = s3object.getObjectContent();
        this.writeFile(objectData, destination);
        long t2 = System.currentTimeMillis();
        long diff = t2 - t1;

        if (!mainFrame.perf) {
            if (terminal) {
                System.out.print("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).\n");
            } else {
                mainFrame.jTextArea1.append("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).");
                mainFrame.calibrateTextArea();
            }
        }

    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }
    } catch (Exception get) {
    }
    calibrate();
}

From source file:cloudExplorer.Put.java

License:Open Source License

public void run() {
    try {//from  w w w  .  j  av  a  2s.  c  o m
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        TransferManager tx = new TransferManager(s3Client);
        File file = new File(what);
        PutObjectRequest putRequest;
        if (!rrs) {
            putRequest = new PutObjectRequest(bucket, ObjectKey, file);
        } else {
            putRequest = new PutObjectRequest(bucket, ObjectKey, file)
                    .withStorageClass(StorageClass.ReducedRedundancy);
        }
        MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
        String mimeType = mimeTypesMap.getContentType(file);
        mimeType = mimeTypesMap.getContentType(file);
        ObjectMetadata objectMetadata = new ObjectMetadata();
        if (encrypt) {
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
        }
        if ((ObjectKey.contains(".html")) || ObjectKey.contains(".txt")) {
            objectMetadata.setContentType("text/html");
        } else {
            objectMetadata.setContentType(mimeType);
        }
        long t1 = System.currentTimeMillis();
        putRequest.setMetadata(objectMetadata);
        Upload myUpload = tx.upload(putRequest);
        myUpload.waitForCompletion();
        tx.shutdownNow();
        long t2 = System.currentTimeMillis();
        long diff = t2 - t1;

        if (!mainFrame.perf) {
            if (terminal) {
                System.out.print("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).\n");
            } else {
                mainFrame.jTextArea1
                        .append("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).");
            }
        }
    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }
    } catch (Exception put) {
    }

    calibrate();
}

From source file:cloudworker.DynamoDBService.java

License:Apache License

private static void createTable() throws Exception {
    try {//w w w  .  j  av  a 2 s . c  o m
        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, TABLE_NAME)) {
            //System.out.println("Table " + TABLE_NAME + " is already ACTIVE");
        } else {
            // Create a table with a primary hash key named 'taskID', which holds a string
            CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(TABLE_NAME)
                    .withKeySchema(new KeySchemaElement().withAttributeName("taskID").withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(new AttributeDefinition().withAttributeName("taskID")
                            .withAttributeType(ScalarAttributeType.S))
                    .withProvisionedThroughput(
                            new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));

            TableDescription tableDescription = dynamoDB.createTable(createTableRequest).getTableDescription();
            //System.out.println("Created Table: " + tableDescription);

            // Wait for it to become active
            //System.out.println("Waiting for " + TABLE_NAME + " to become ACTIVE...");
            Tables.waitForTableToBecomeActive(dynamoDB, TABLE_NAME);
        }

        // Describe our new table
        //            DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(TABLE_NAME);
        //            TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        //            System.out.println("Table Description: " + tableDescription);
    } 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());
    } 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());
    }

}

From source file:com.amazon.photosharing.facade.ContentFacade.java

License:Open Source License

public Media uploadPictureToS3(User p_user, String p_file_name, InputStream p_file_stream,
        String p_content_type, Comment... _comments) throws IOException {
    Media media = null;/* w  w w .  j  a va  2 s . com*/

    try {

        ContentHelper.getInstance()
                .createS3BucketIfNotExists(ContentHelper.getInstance().getConfiguredBucketName());

        beginTx();

        String s3Key = S3Helper.createS3Key(p_file_name, p_user.getUserName(), new Date());
        String s3ThumbKey = S3Helper.createS3Key("thumb_" + p_file_name, p_user.getUserName(), new Date());

        byte[] original_bytes = null;
        byte[] thumb_bytes = null;

        //clone a byte[] of the input original for image resize and thumb clone
        ByteArrayOutputStream byte_worker = new ByteArrayOutputStream();
        ImageIO.write(ImageIO.read(p_file_stream), p_file_name.substring(p_file_name.lastIndexOf(".") + 1),
                byte_worker);

        original_bytes = byte_worker.toByteArray();
        try {
            thumb_bytes = new MediaResizeTask(new ByteArrayInputStream(original_bytes), p_file_name).call();
        } catch (Exception e) {
            _logger.error(e.getMessage(), e);
        }

        User u = em().find(User.class, p_user.getId());

        media = new Media();
        media.setS3Bucket(ContentHelper.getInstance().getConfiguredBucketName());
        media.setS3FileName(s3Key);
        media.setS3ThumbFileName(s3ThumbKey);
        media.setName(p_file_name);
        media.setUser(u);

        if (_comments != null) {
            for (Comment comment : _comments) {
                comment.setMedia(media);
                media.getComments().add(comment);
            }
        }

        u.getMedia().add(media);

        em().persist(u);

        commitTx();

        ContentHelper.getInstance().uploadContent(p_content_type, thumb_bytes.length,
                ContentHelper.getInstance().getConfiguredBucketName(), s3ThumbKey,
                new ByteArrayInputStream(thumb_bytes));
        ContentHelper.getInstance().uploadContent(p_content_type, original_bytes.length,
                ContentHelper.getInstance().getConfiguredBucketName(), s3Key,
                new ByteArrayInputStream(original_bytes));

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            //do some sleeping here..
        }

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

        try {
            rollbackTx();
        } catch (Exception ex) {
        }

        ase.printStackTrace();

    } catch (AmazonClientException ace) {
        _logger.info("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.");
        _logger.info("Error Message: " + ace.getMessage());

        ace.printStackTrace();

        rollbackTx();
    }

    return media;
}

From source file:com.amazon.util.ImageUploader.java

public static void uploadImage(String imageURL, String imageName, String folderName, String bucketName)
        throws MalformedURLException, IOException {
    // credentials object identifying user for authentication

    AWSCredentials credentials = new BasicAWSCredentials(System.getenv("AWS_S3_ACCESS_KEY"),
            System.getenv("AWS_S3_SECRET_ACCESS_KEY"));

    // create a client connection based on credentials
    AmazonS3 s3client = new AmazonS3Client(credentials);

    try {/*  w w w.j ava 2  s  . c o  m*/
        if (!(s3client.doesBucketExist(bucketName))) {
            s3client.setRegion(Region.getRegion(Regions.US_EAST_1));
            // Note that CreateBucketRequest does not specify region. So bucket is 
            // created in the region specified in the client.
            s3client.createBucket(new CreateBucketRequest(bucketName));
        }

        //Enabe CORS:
        //     <?xml version="1.0" encoding="UTF-8"?>
        //<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
        //    <CORSRule>
        //        <AllowedOrigin>http://ask-ifr-download.s3.amazonaws.com</AllowedOrigin>
        //        <AllowedMethod>GET</AllowedMethod>
        //    </CORSRule>
        //</CORSConfiguration>
        BucketCrossOriginConfiguration configuration = new BucketCrossOriginConfiguration();

        CORSRule corsRule = new CORSRule()
                .withAllowedMethods(
                        Arrays.asList(new CORSRule.AllowedMethods[] { CORSRule.AllowedMethods.GET }))
                .withAllowedOrigins(Arrays.asList(new String[] { "http://ask-ifr-download.s3.amazonaws.com" }));
        configuration.setRules(Arrays.asList(new CORSRule[] { corsRule }));
        s3client.setBucketCrossOriginConfiguration(bucketName, configuration);

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

    String fileName = folderName + SUFFIX + imageName + ".png";
    URL url = new URL(imageURL);

    ObjectMetadata omd = new ObjectMetadata();
    omd.setContentType("image/png");
    omd.setContentLength(url.openConnection().getContentLength());
    // upload file to folder and set it to public
    s3client.putObject(new PutObjectRequest(bucketName, fileName, url.openStream(), omd)
            .withCannedAcl(CannedAccessControlList.PublicRead));
}

From source file:com.app.dynamoDb.DynamoUserAuthority.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/* w w  w .  j  av  a2s.  c o  m*/

    try {
        String tableName = "UserAuthority";

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);

        // Add an item
        insert("1003", "https://s3-us-west-2.amazonaws.com/photoscloudbox/ship.jpg", "1002");

        // Add another item
        insert("1004", "https://s3-us-west-2.amazonaws.com/photoscloudbox/assignment.docx", "1001");

        //read("1004");

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

From source file:com.arc.cloud.aws.s3.S3Sample.java

License:Open Source License

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

    /*/* w ww.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);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);

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

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

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

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

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

From source file:com.athena.sqs.MessageDispatcher.java

License:Apache License

/**
 * Send message to amazon sqs/*  ww  w . j  av  a 2  s.c  o  m*/
 * @param queueName
 * @param messages
 * @throws MessageException
 */
public void doSend(String queueName, String jsonString) throws MessageException {
    String transactionId = UUID.randomUUID().toString();

    try {

        logger.debug("Getting Queue URL from Amazon [" + queueName + "]");
        String queueUrl = messageContext.getQueue(queueName);
        logger.debug("Sending a message to [" + queueName + "][" + queueUrl + "]");

        // if message is small enough to be sent as one message, do it
        if (jsonString.getBytes(MessageSplitter.UTF_8).length <= MessageSplitter.SQS_MAX_MESSAGE_SIZE) {
            String header = makeHeader(MessageTransferType.JSON, "athena", transactionId, true, 1, 1);

            logger.debug("This is smaller message");
            logger.debug("[HEADER] : " + header);

            String singleMessage = header + encoder.encodeBuffer(jsonString.getBytes());
            client.sendMessage(new SendMessageRequest(queueUrl, singleMessage));
            logger.debug("Single message sent successfully");

        } else {
            logger.debug("This is larger than " + MessageSplitter.SQS_MAX_MESSAGE_SIZE);
            List<String> messageList = MessageSplitter.split(encoder.encodeBuffer(jsonString.getBytes()));

            int current = 1;
            int total = messageList.size();

            String header = null;
            String chunkedMessage = null;
            for (String target : messageList) {
                header = makeHeader(MessageTransferType.JSON, "athena", transactionId, false, current++, total);
                chunkedMessage = header + target;
                client.sendMessage(new SendMessageRequest(queueUrl, chunkedMessage));
                logger.debug(chunkedMessage);
            }
            logger.debug("Complex message sent successfully");
        }
    } catch (AmazonServiceException ase) {
        logger.error("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SQS, but was rejected with an error response for some reason.");
        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());
        throw new MessageException(
                MessageFormat.format(MessageErrors.AMAZON_ERROR.getDescription(), ase.getMessage()));
    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
        throw new MessageException(
                MessageFormat.format(MessageErrors.AMAZON_ERROR.getDescription(), ace.getMessage()));
    } catch (IOException ioe) {
        throw new MessageException(
                MessageFormat.format(MessageErrors.INTERNAL_ERROR.getDescription(), ioe.getMessage()));
    } catch (Exception e) {
        throw new MessageException(
                MessageFormat.format(MessageErrors.INTERNAL_ERROR.getDescription(), e.getMessage()));
    } finally {

    }
}

From source file:com.aws.sns.service.notifications.sns.SNSMobilePush.java

License:Open Source License

public static void sendPushNotifications(NotificationTaskWorkerInput input) {
    try {/*from   w ww . j a v  a 2s .  c  o  m*/

        System.out.println("===========================================\n");
        System.out.println("Getting Started with Amazon SNS");
        System.out.println("===========================================\n");
        try {
            SNSMobilePush sample = new SNSMobilePush(sns);
            if (SNSPlatformHelper.Platform.GCM.name() == input.getPlatform().name()) {
                sample.demoAndroidAppNotification(input.getToken(), input.getMessage(), input.getAction(),
                        input.getCollapseKey());
            } else if (SNSPlatformHelper.Platform.APNS.name() == input.getPlatform().name()) {
                sample.demoAppleAppNotification(input.getToken(), input.getMessage(), input.getAction(),
                        input.getCollapseKey());
            } else {
                LOGGER.error("Unsupported SNS Notification Service :" + input.getPlatform().name());
            }

            // sample.demoKindleAppNotification();
            // sample.demoAppleAppNotification();
            // sample.demoAppleSandboxAppNotification();
            // sample.demoBaiduAppNotification();
            // sample.demoWNSAppNotification();
            // sample.demoMPNSAppNotification();
        } catch (AmazonServiceException ase) {
            System.out.println("Caught an AmazonServiceException, which means your request made it "
                    + "to Amazon SNS, 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 SNS, such as not "
                    + "being able to access the network.");
            System.out.println("Error Message: " + ace.getMessage());
        }
    } catch (Exception e) {
        LOGGER.error("Error in sendPushNofifications :", e);
    }

}