Example usage for com.amazonaws.services.sns AmazonSNS setEndpoint

List of usage examples for com.amazonaws.services.sns AmazonSNS setEndpoint

Introduction

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

Prototype

@Deprecated
void setEndpoint(String endpoint);

Source Link

Document

Overrides the default endpoint for this client ("https://sns.us-east-1.amazonaws.com").

Usage

From source file:SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/* ww  w . j  av a2  s  . 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")));

    sns.setEndpoint("https://sns.us-east-1.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:ch.admin.isb.hermes5.tools.filebackup.FileBackup.java

License:Apache License

private AmazonSNS sns(String accessKey, String secretKey, String snsEndpoint) {
    AmazonSNS sns = accessKey == null || "".equals(accessKey) ? new AmazonSNSClient()
            : new AmazonSNSClient(new BasicAWSCredentials(accessKey, secretKey));
    sns.setEndpoint(snsEndpoint);
    return sns;//from   w w w . j a v a2s. c o m
}

From source file:com.aipo.aws.sns.SNS.java

License:Open Source License

public static AmazonSNS getClient() {
    AWSContext awsContext = AWSContext.get();
    if (awsContext == null) {
        throw new IllegalStateException("AWSContext is not initialized.");
    }/*from ww w.  j av a2  s.  com*/
    AmazonSNS client = new AmazonSNSClient(awsContext.getAwsCredentials());
    String endpoint = awsContext.getSnsEndpoint();
    if (endpoint != null && endpoint != "") {
        client.setEndpoint(endpoint);
    }
    return client;
}

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

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*from ww  w .  j a  va  2  s  .co 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")));

    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. */
        String registrationId = "APA91bEzO4gs7gqC0PPaw1RKzlDY5cEmRwGzV4k5DPzc_uxp8aLyNVGS3Wx7G6O3lj9v17aqUBtoTyg3JZvbsOVt81mdUDTDDiXoiWLJt9PtcWUUNKYyJsiaq1OlPnSNRx2djcfPS7Pp";
        sample.demoAndroidAppNotification(registrationId, "Test Message", "payload action", "Moonfrog");
        // sample.demoKindleAppNotification();
        //   sample.demoAppleAppNotification("c522823644bf4e799d94adc7bc4c1f1dd57066a38cc72b7d37cf48129379c13b", "APNS Welcome !!!", "apns", "Moonfrog");
        // 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.clicktravel.infrastructure.runtime.config.aws.AwsConfiguration.java

License:Apache License

@Bean
@Autowired/*from   www .j  a  v a2  s .com*/
public AmazonSNS amazonSnsClient(final AWSCredentials awsCredentials,
        @Value("${aws.sns.client.endpoint}") final String endpoint) {
    final AmazonSNS amazonSnsClient = new AmazonSNSClient(awsCredentials);
    logger.info("Setting AWS SNS endpoint to: " + endpoint);
    amazonSnsClient.setEndpoint(endpoint);
    return amazonSnsClient;
}

From source file:com.dev.appx.sns.SNSMobilePush.java

License:Open Source License

public static void igniteSNS() throws IOException {
    /*//from  w  w w  .j  a  v a 2 s .com
     * 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")));

    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();
        sample.createTopic("test");
    } 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.hrt.modules.aws.sns.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*//w w  w . j  av a 2 s .co 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.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 w  w  .ja v  a2 s .c om

    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");
    }/* ww  w .j  av  a 2 s . co  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 av  a  2s . 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());
    }
}