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

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

Introduction

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

Prototype

@Deprecated
void setRegion(Region region);

Source Link

Document

An alternative to AmazonSNS#setEndpoint(String) , sets the regional endpoint for this client's service calls.

Usage

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.SnsTopic.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//from  w  w  w. ja v  a 2s  . co m

    try {

        AmazonSNS client = new AmazonSNSClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        buildUI(null);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving SNS details from AWS", e);
    }

    return response;
}

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

    String topicArn = null;//from  ww w .  j  a v  a  2  s.c o m

    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   w  w w  . jav  a 2  s  .c  om*/

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

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

License:Apache License

@Override
public void deleteTopic(INotificationEndpoint notificationEndpoint) {
    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 {//w  ww  . j av a2  s . co m
        DeleteTopicRequest request = new DeleteTopicRequest(notificationEndpoint.getTopicArn());
        sns.deleteTopic(request);
    } finally {
        sns.shutdown();
    }

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

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

License:Apache License

@Override
public void publish(INotificationEndpoint notificationEndpoint, String json) {
    Preconditions.checkArgument((notificationEndpoint != null), "Endpoint must not be null");

    Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null),
            "Endpoint is missing a notification URL definition");

    Preconditions.checkArgument((!notificationEndpoint.isPendingConfirmation()),
            "Endpoint has not yet been confirmed");

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

    try {/*  www.  j a  va2s  .  c  o m*/
        String subject = "SMART COSMOS Objects Event Notification";

        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(json);
            if (jsonObject.has(EVENT_TYPE)) {
                String eventType = jsonObject.getString(EVENT_TYPE);
                subject = "Objects Event: " + eventType;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PublishRequest request = new PublishRequest(notificationEndpoint.getTopicArn(), json, subject);
        PublishResult result = sns.publish(request);

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

    } finally {
        sns.shutdown();
    }
}

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

License:Apache License

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

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

    try {/*from w w w.j a va  2s .  co m*/

        UnsubscribeRequest request = new UnsubscribeRequest(notificationEndpoint.getSubscriptionArn());
        sns.unsubscribe(request);

        //
        // Event
        //
        INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account,
                notificationEndpoint.getAccount(), "");
        IEventService eventService = context.getServiceFactory()
                .getEventService(notificationEndpoint.getAccount());
        eventService.recordEvent(EventType.NotificationUnsubscribe, notificationEndpoint.getAccount(), null,
                nro);
    } finally {
        sns.shutdown();
    }
}

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

License:Apache License

@Override
public void confirmSubscription(INotificationEndpoint notificationEndpoint, String token) {
    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 {/*from  w  w w.j a v a  2 s  .  co  m*/
        ConfirmSubscriptionRequest request = new ConfirmSubscriptionRequest(notificationEndpoint.getTopicArn(),
                token);

        ConfirmSubscriptionResult result = sns.confirmSubscription(request);

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

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

License:Apache License

@Override
public boolean isHealthy() {
    try {//w ww. jav  a  2  s  . c  o  m
        AmazonSNS sns = new AmazonSNSClient(credentials);
        Region usEast1 = Region.getRegion(Regions.US_EAST_1);
        sns.setRegion(usEast1);
        sns.listTopics();
        return true;
    } catch (Exception e) {
        return false;
    }
}