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.pocketdealhunter.HotDealsMessagesUtil.java

License:Open Source License

public HotDealsMessagesUtil() {
    AWSCredentials credentials = new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY);
    Region region = Region.getRegion(Regions.US_WEST_2);

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

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

    // Find the Topic for this App or create one.
    this.topicARN = this.findTopicArn();
    if (topicARN == null) {
        this.topicARN = this.createTopic();
    }//from   w w w  .  java  2  s. c om

    // Find the Queue for this App or create one.
    this.queueUrl = this.findQueueUrl();
    if (this.queueUrl == null) {
        this.queueUrl = this.createQueue();

        // Allow time for the queue to be created.
        try {
            Thread.sleep(4 * 1000);
        } catch (Exception exception) {
        }

        this.subscribeQueue();
    }
}

From source file:com.trsvax.tapestry.aws.core.services.AWSCoreModule.java

License:Apache License

public static void bind(ServiceBinder binder) {
    //binder.bind(AWSMailTransport.class,AWSMailTransportImpl.class);

    binder.bind(AmazonS3.class, new ServiceBuilder<AmazonS3>() {
        public AmazonS3 buildService(ServiceResources serviceResources) {
            return new AmazonS3Client(serviceResources.getService(AWSCredentials.class));
        }// w  w  w.  j  a v a 2  s .c  o  m
    });
    binder.bind(AmazonDynamoDB.class, new ServiceBuilder<AmazonDynamoDB>() {
        public AmazonDynamoDB buildService(ServiceResources serviceResources) {
            return new AmazonDynamoDBClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonEC2.class, new ServiceBuilder<AmazonEC2>() {
        public AmazonEC2 buildService(ServiceResources serviceResources) {
            return new AmazonEC2Client(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonSimpleDB.class, new ServiceBuilder<AmazonSimpleDB>() {
        public AmazonSimpleDB buildService(ServiceResources serviceResources) {
            return new AmazonSimpleDBClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonSQS.class, new ServiceBuilder<AmazonSQS>() {
        public AmazonSQS buildService(ServiceResources serviceResources) {
            return new AmazonSQSClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonSNS.class, new ServiceBuilder<AmazonSNS>() {
        public AmazonSNS buildService(ServiceResources serviceResources) {
            return new AmazonSNSClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonRDS.class, new ServiceBuilder<AmazonRDS>() {
        public AmazonRDS buildService(ServiceResources serviceResources) {
            return new AmazonRDSClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonElasticMapReduce.class, new ServiceBuilder<AmazonElasticMapReduce>() {
        public AmazonElasticMapReduce buildService(ServiceResources serviceResources) {
            return new AmazonElasticMapReduceClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonSimpleEmailService.class, new ServiceBuilder<AmazonSimpleEmailService>() {
        public AmazonSimpleEmailService buildService(ServiceResources serviceResources) {
            return new AmazonSimpleEmailServiceClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonElasticLoadBalancing.class, new ServiceBuilder<AmazonElasticLoadBalancing>() {
        public AmazonElasticLoadBalancing buildService(ServiceResources serviceResources) {
            return new AmazonElasticLoadBalancingClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonCloudWatch.class, new ServiceBuilder<AmazonCloudWatch>() {
        public AmazonCloudWatch buildService(ServiceResources serviceResources) {
            return new AmazonCloudWatchClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonAutoScaling.class, new ServiceBuilder<AmazonAutoScaling>() {
        public AmazonAutoScaling buildService(ServiceResources serviceResources) {
            return new AmazonAutoScalingClient(serviceResources.getService(AWSCredentials.class));
        }
    });
    binder.bind(AmazonIdentityManagement.class, new ServiceBuilder<AmazonIdentityManagement>() {
        public AmazonIdentityManagement buildService(ServiceResources serviceResources) {
            return new AmazonIdentityManagementClient(serviceResources.getService(AWSCredentials.class));
        }
    });
}

From source file:com.zotoh.cloudapi.aws.AWSCloud.java

License:Open Source License

private void createAWSClients(Properties ps) {
    AWSCredentials cc = new BasicAWSCredentials(ps.getProperty(P_ID), ps.getProperty(P_PWD));
    AmazonWebServiceClient c;//  w w w  . ja v  a  2s  . c om

    _WEB.put("ec2", new AmazonEC2Client(cc));

    _WEB.put("s3", new AmazonS3Client(cc));

    // SIMPLE-DB
    c = new AmazonSimpleDBClient(cc);
    _WEB.put("sdb", c);
    c.setEndpoint("sdb.amazonaws.com");

    // LOAD BALANCER
    c = new AmazonElasticLoadBalancingClient(cc);
    _WEB.put("elb", c);
    c.setEndpoint("elasticloadbalancing.amazonaws.com");

    _WEB.put("cloudwatch", new AmazonCloudWatchClient(cc));
    _WEB.put("autoscale", new AmazonAutoScalingClient(cc));

    // NOTIFICATION
    c = new AmazonSNSClient(cc);
    _WEB.put("sns", c);
    c.setEndpoint("sns.us-east-1.amazonaws.com");

    _WEB.put("sqs", new AmazonSQSClient(cc));
    _WEB.put("rds", new AmazonRDSClient(cc));
    _WEB.put("s3s", new AmazonS3EncryptionClient(cc, new EncryptionMaterials((KeyPair) null)));

}

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

License:Open Source License

public AbstractCommand(final URL endpoint, final File credentials) throws IOException {
    this.log = LogFactory.getLog(this.getClass());

    if (credentials != null) {
        this.credentials = new PropertiesCredentials(credentials);
        this.client = new AmazonGlacierClient(this.credentials);
        this.sqs = new AmazonSQSClient(this.credentials);
        this.sns = new AmazonSNSClient(this.credentials);
    }//from   w w w .j  av  a 2 s.  c om

    if (endpoint != null) {
        this.setEndpoint(endpoint);
    }
}

From source file:edu.utn.frba.grupo5303.serverenviolibre.services.NotificacionesPushService.java

public NotificacionesPushService() {
    snsClient = new AmazonSNSClient(new ProfileCredentialsProvider());
}

From source file:io.ignitr.dispatchr.manager.Application.java

License:Apache License

@Autowired
@Bean/*from   w  w  w  .j  ava 2 s  .c o  m*/
public AmazonSNSClient amazonSNSClient(DeploymentContext deploymentContext) {
    AmazonSNSClient client = new AmazonSNSClient(new DefaultAWSCredentialsProviderChain());
    client.setRegion(Region.getRegion(Regions.fromName(deploymentContext.getRegion())));

    return client;
}

From source file:io.starter.messaging.SNSMobilePush.java

License:Open Source License

private static AmazonSNS getSNS() throws IOException {
    String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
    String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

    if (awsAccessKey == null)
        awsAccessKey = AWS_ACCESS_KEY;/*from   w  w  w .  ja v  a2  s. c  om*/
    if (awsSecretKey == null)
        awsSecretKey = AWS_SECRET_KEY;

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    AmazonSNS sns = new AmazonSNSClient(credentials);

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    return sns;
}

From source file:io.starter.messaging.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*  w w 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
     */

    String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
    String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

    if (awsAccessKey == null)
        awsAccessKey = AWS_ACCESS_KEY;
    if (awsSecretKey == null)
        awsSecretKey = AWS_SECRET_KEY;

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);

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

    // AmazonSNS sns = new AmazonSNSClient(credentials);

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Initializing Communication with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        /* TODO: Uncomment the services you wish to use. */
        // sample.starterAndroidAppNotification();
        // sample.starterKindleAppNotification();
        sample.starterAppleAppNotification();
        // sample.starterAppleSandboxAppNotification();
        // sample.starterBaiduAppNotification();
        // sample.starterWNSAppNotification();
        // sample.starterMPNSAppNotification();
    } 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:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java

License:Apache License

@Override
public String createTopic(INotificationEndpoint notificationEndpoint) {
    Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null");

    Preconditions.checkArgument((notificationEndpoint.getTopicArn() == null),
            "Notification already has a notification URL defined");

    AmazonSNS sns = new AmazonSNSClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    sns.setRegion(usEast1);/*www  .java 2 s  .  c  o  m*/

    String topicArn = null;

    try {
        String topicName = stripUrnUuidPrefix(notificationEndpoint.getAccount());

        LOG.info("Topic Name Assigned: " + topicName);

        CreateTopicRequest request = new CreateTopicRequest(topicName);
        CreateTopicResult result = sns.createTopic(request);

        topicArn = result.getTopicArn();

        //
        // Event
        //
        INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account,
                notificationEndpoint.getAccount(), result.getTopicArn());
        IEventService eventService = context.getServiceFactory()
                .getEventService(notificationEndpoint.getAccount());
        eventService.recordEvent(EventType.NotificationEnroll, notificationEndpoint.getAccount(), null, nro);

    } finally {
        sns.shutdown();
    }

    return topicArn;
}

From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java

License:Apache License

@Override
public String subscribe(INotificationEndpoint notificationEndpoint) {
    String subscriptionArn;//from   ww w  . ja va  2s.c  o m

    Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null");

    Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null),
            "Notification Topic ARN must not be null");

    AmazonSNS sns = new AmazonSNSClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    sns.setRegion(usEast1);

    try {
        SubscribeRequest request = new SubscribeRequest(notificationEndpoint.getTopicArn(), "https",
                notificationEndpoint.getNotificationEndpointUrl());

        SubscribeResult result = sns.subscribe(request);

        subscriptionArn = result.getSubscriptionArn();

        //
        // Event
        //
        INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account,
                notificationEndpoint.getAccount(), result.getSubscriptionArn());
        IEventService eventService = context.getServiceFactory()
                .getEventService(notificationEndpoint.getAccount());
        eventService.recordEvent(EventType.NotificationSubscribe, notificationEndpoint.getAccount(), null, nro);

    } finally {
        sns.shutdown();
    }

    return subscriptionArn;
}