Example usage for com.amazonaws.services.sns AmazonSNSClient AmazonSNSClient

List of usage examples for com.amazonaws.services.sns AmazonSNSClient AmazonSNSClient

Introduction

In this page you can find the example usage for com.amazonaws.services.sns AmazonSNSClient AmazonSNSClient.

Prototype

AmazonSNSClient(AwsSyncClientParams clientParams) 

Source Link

Document

Constructs a new client to invoke service methods on Amazon SNS using the specified parameters.

Usage

From source file:com.hrt.modules.aws.sns.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*// www .ja  v  a  2s.  c o  m
     * TODO: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */
    //      AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
    //            SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties")));

    AmazonSNS sns = new AmazonSNSClient(
            new AccessCredentials("AKIAJGE6YKV7ZOB2BU2Q", "VHNI9fZcMQirkslT9juVpodG4Mf94ixv7CXRuc4s"));

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Getting Started with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        /* TODO: Uncomment the services you wish to use. */
        // sample.demoAndroidAppNotification();
        // 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());
    }
}

From source file:com.leverno.ysbos.archive.example.AmazonGlacierDownloadInventoryWithSQSPolling.java

License:Open Source License

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

    AWSCredentials credentials = AwsUtil.getCredentials();

    client = new AmazonGlacierClient(credentials);
    client.setEndpoint("https://glacier." + region + ".amazonaws.com");
    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setEndpoint("https://sqs." + region + ".amazonaws.com");
    snsClient = new AmazonSNSClient(credentials);
    snsClient.setEndpoint("https://sns." + region + ".amazonaws.com");

    try {// w  w w .  java2 s.  com
        setupSQS();

        setupSNS();

        String jobId = initiateJobRequest();
        System.out.println("Jobid = " + jobId);

        Boolean success = waitForJobToComplete(jobId, sqsQueueURL);
        if (!success) {
            throw new Exception("Job did not complete successfully.");
        }

        downloadJobOutput(jobId);

        cleanUp();

    } catch (Exception e) {
        System.err.println("Inventory retrieval failed.");
        System.err.println(e);
    }
}

From source file:com.leverno.ysbos.archive.example.ArchiveDownloadHighLevel.java

License:Open Source License

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

    AWSCredentials credentials = getCredentials();
    AmazonSQSClient sqs = new AmazonSQSClient(credentials);
    AmazonSNSClient sns = new AmazonSNSClient(credentials);

    glacier = new AmazonGlacierClient(credentials);
    glacier.setEndpoint(Constants.endpoint);
    sqs.setEndpoint(Constants.endpoint);
    sns.setEndpoint(Constants.endpoint);

    try {//from w w  w .j  ava 2 s.  co  m
        ArchiveTransferManager atm = new ArchiveTransferManager(glacier, sqs, sns);

        atm.download(vaultName, archiveId, new File(downloadFilePath));

    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:com.logpig.mweagle.rolling.S3RollingFileAppender.java

License:Apache License

private void writeErrorMessage(String message) {
    final String __subject = "[ERROR] S3RollingFileAppender";
    System.err.println(String.format("%s - %s", __subject, message));
    try {// ww  w .  j a v  a 2 s.c om
        final AmazonSNS snsClient = new AmazonSNSClient(s3Settings.getAWSCredentials());
        final PublishRequest __request = new PublishRequest().withTopicArn(s3Settings.getSnsTopicArn())
                .withMessage(message).withSubject(__subject);
        snsClient.publish(__request);
    } catch (Exception e) {
        System.err.println(String.format(
                "[ERROR] Unable to send notification of S3RollingFileAppender failure. %s", e.getMessage()));
    }
}

From source file:com.netflix.metacat.main.configs.SNSNotificationsConfig.java

License:Apache License

/**
 * If SNS notifications are desired and no existing client has been created elsewhere
 * in the application create a default client here.
 *
 * @return The configured SNS client//from w  w w.j  ava  2s .co m
 */
//TODO: See what spring-cloud-aws would provide automatically...
@Bean
@ConditionalOnMissingBean(AmazonSNS.class)
public AmazonSNS amazonSNS() {
    return new AmazonSNSClient(DefaultAWSCredentialsProviderChain.getInstance());
}

From source file:com.ninetoseven.inmuebles.AmazonClientManager.java

License:Open Source License

private void initClients() {
    AWSCredentials credentials = AmazonSharedPreferencesWrapper
            .getCredentialsFromSharedPreferences(this.sharedPreferences);

    Region region = Region.getRegion(Regions.US_EAST_1);

    s3Client = new AmazonS3Client(credentials);
    s3Client.setRegion(region);/*from www .ja  va 2s .  c o m*/

    sqsClient = new AmazonSQSClient(credentials);
    sqsClient.setRegion(region);

    sdbClient = new AmazonSimpleDBClient(credentials);
    sdbClient.setRegion(region);

    snsClient = new AmazonSNSClient(credentials);
    snsClient.setRegion(region);
}

From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java

License:Open Source License

public static void pushIOSNotification(String message, String deviceToken, Map<String, Object> customData,
        int badge) throws IOException {

    AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
            SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties")));

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    if (logger.isDebugEnabled()) {
        logger.debug("===========================================\n");
        logger.debug("Getting Started with Amazon SNS  IOS");
        logger.debug("===========================================\n");
    }//from   w  ww  .  ja v a2  s .  c o m

    try {
        SNSMobilePush push = new SNSMobilePush(sns);
        String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu");
        String _message = MessageGenerator.getAppleMessage(message, null, badge, customData);
        boolean isSandBox = Boolean.parseBoolean(ConfigCache.getValue(ConfigKey.IS_SAND_BOX, "true"));
        Platform platform = null;
        String Certificate = null;
        String Private_Key = null;
        if (isSandBox) {
            platform = Platform.APNS_SANDBOX;
            Certificate = S_Certificate;
            Private_Key = S_Private_Key;
        } else {
            platform = Platform.APNS;
            Certificate = P_Certificate;
            Private_Key = P_Private_Key;
        }

        push.snsClientWrapper.notification(platform, Certificate, Private_Key, deviceToken, applicationName,
                attributesMap, _message);

    } catch (AmazonServiceException ase) {
        logger.error("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SNS, 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());
    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
    }
}

From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java

License:Open Source License

public static void pushAndroidNotification(String message, String deviceToken, Map<String, Object> customData)
        throws IOException {

    AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
            SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties")));

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    if (logger.isDebugEnabled()) {
        logger.debug("===========================================\n");
        logger.debug("Getting Started with Amazon SNS android");
        logger.debug("===========================================\n");
    }/*from  ww  w  .ja  v a2s  .c  o m*/

    try {
        SNSMobilePush push = new SNSMobilePush(sns);
        String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu");
        String serverAPIKey = "";
        String _message = MessageGenerator.getSampleAndroidMessage("NewOrder", message, customData);
        push.snsClientWrapper.notification(Platform.GCM, "", serverAPIKey, deviceToken, applicationName,
                attributesMap, _message);

    } catch (AmazonServiceException ase) {
        logger.error("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SNS, 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());
    } catch (AmazonClientException ace) {
        logger.error("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.");
        logger.error("Error Message: " + ace.getMessage());
    }
}

From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*from   w  ww  . j a v a2s.c  om*/
     * TODO: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials(
            SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties")));

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Getting Started with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        sample.demoAppleSandboxAppNotification();
    } 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());
    }
}

From source file:com.oneops.antenna.senders.aws.SNSService.java

License:Apache License

/**
 * Sends using the sns publisher//  ww  w .j  a v a2  s.  c  o m
 */
@Override
public boolean postMessage(NotificationMessage nMsg, BasicSubscriber subscriber) {

    SNSSubscriber sub;
    if (subscriber instanceof SNSSubscriber) {
        sub = (SNSSubscriber) subscriber;
    } else {
        throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName());
    }

    SNSMessage msg = buildSNSMessage(nMsg);
    AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey()));
    if (sub.getSnsEndpoint() != null) {
        sns.setEndpoint(sub.getSnsEndpoint());
    }

    CreateTopicRequest tRequest = new CreateTopicRequest();
    tRequest.setName(msg.getTopicName());
    CreateTopicResult result = sns.createTopic(tRequest);

    PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage())
            .withSubject(msg.getSubject());

    try {
        PublishResult pubresult = sns.publish(pr);
        logger.info("Published msg with id - " + pubresult.getMessageId());
    } catch (AmazonClientException ace) {
        logger.error(ace.getMessage());
        return false;
    }
    return true;
}