Search in sources :

Example 1 with Topic

use of com.amazonaws.services.sns.model.Topic in project camel by apache.

the class AmazonSNSClientMock method listTopics.

@Override
public ListTopicsResult listTopics(String nextToken) {
    ListTopicsResult res = new ListTopicsResult();
    Topic topic = new Topic();
    topic.setTopicArn(DEFAULT_TOPIC_ARN);
    List<Topic> list = new ArrayList<Topic>();
    list.add(topic);
    res.setTopics(list);
    return res;
}
Also used : ListTopicsResult(com.amazonaws.services.sns.model.ListTopicsResult) ArrayList(java.util.ArrayList) Topic(com.amazonaws.services.sns.model.Topic)

Example 2 with Topic

use of com.amazonaws.services.sns.model.Topic in project camel by apache.

the class SnsEndpoint method doStart.

@Override
public void doStart() throws Exception {
    super.doStart();
    snsClient = configuration.getAmazonSNSClient() != null ? configuration.getAmazonSNSClient() : createSNSClient();
    // Override the setting Endpoint from url
    if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint())) {
        LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
        snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
    }
    // check the setting the headerFilterStrategy
    if (headerFilterStrategy == null) {
        headerFilterStrategy = new SnsHeaderFilterStrategy();
    }
    if (configuration.getTopicArn() == null) {
        try {
            String nextToken = null;
            final String arnSuffix = ":" + configuration.getTopicName();
            do {
                final ListTopicsResult response = snsClient.listTopics(nextToken);
                nextToken = response.getNextToken();
                for (final Topic topic : response.getTopics()) {
                    if (topic.getTopicArn().endsWith(arnSuffix)) {
                        configuration.setTopicArn(topic.getTopicArn());
                        break;
                    }
                }
            } while (nextToken != null);
        } catch (final AmazonServiceException ase) {
            LOG.trace("The list topics operation return the following error code {}", ase.getErrorCode());
            throw ase;
        }
    }
    if (configuration.getTopicArn() == null) {
        // creates a new topic, or returns the URL of an existing one
        CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
        LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(), request);
        CreateTopicResult result = snsClient.createTopic(request);
        configuration.setTopicArn(result.getTopicArn());
        LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
    }
    if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
        LOG.trace("Updating topic [{}] with policy [{}]", configuration.getTopicArn(), configuration.getPolicy());
        snsClient.setTopicAttributes(new SetTopicAttributesRequest(configuration.getTopicArn(), "Policy", configuration.getPolicy()));
        LOG.trace("Topic policy updated");
    }
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) ListTopicsResult(com.amazonaws.services.sns.model.ListTopicsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) SetTopicAttributesRequest(com.amazonaws.services.sns.model.SetTopicAttributesRequest) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Topic(com.amazonaws.services.sns.model.Topic)

Example 3 with Topic

use of com.amazonaws.services.sns.model.Topic in project Synapse-Stack-Builder by Sage-Bionetworks.

the class StackInstanceNotificationSetup method describeResources.

public void describeResources() {
    String topicName;
    String subscriptionEndpoint;
    ListTopicsResult res;
    List<Topic> topics;
    topicName = config.getRDSAlertTopicName();
    subscriptionEndpoint = config.getRDSAlertSubscriptionEndpoint();
    res = client.listTopics();
    // TopicArn ends with topic name
    topics = res.getTopics();
    for (Topic topic : topics) {
        if (topic.getTopicArn().endsWith(topicName)) {
            resources.setStackInstanceNotificationTopicArn(topic.getTopicArn());
            break;
        }
    }
}
Also used : ListTopicsResult(com.amazonaws.services.sns.model.ListTopicsResult) Topic(com.amazonaws.services.sns.model.Topic)

Aggregations

ListTopicsResult (com.amazonaws.services.sns.model.ListTopicsResult)3 Topic (com.amazonaws.services.sns.model.Topic)3 AmazonServiceException (com.amazonaws.AmazonServiceException)1 CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)1 CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)1 SetTopicAttributesRequest (com.amazonaws.services.sns.model.SetTopicAttributesRequest)1 ArrayList (java.util.ArrayList)1