Example usage for com.amazonaws.services.sns.model ListTopicsRequest ListTopicsRequest

List of usage examples for com.amazonaws.services.sns.model ListTopicsRequest ListTopicsRequest

Introduction

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

Prototype

public ListTopicsRequest(String nextToken) 

Source Link

Document

Constructs a new ListTopicsRequest object.

Usage

From source file:com.pocketdealhunter.HotDealsMessagesUtil.java

License:Open Source License

protected String findTopicArn() {
    try {/* ww  w .  j a v a2 s  . co m*/
        String topicNameToFind = ":" + Constants.TOPIC_NAME;
        String nextToken = null;
        do {
            ListTopicsRequest listTopicsRequest = new ListTopicsRequest(nextToken);
            ListTopicsResult result = this.snsClient.listTopics(listTopicsRequest);

            for (Topic topic : (List<Topic>) result.getTopics()) {
                if (topic.getTopicArn().endsWith(topicNameToFind)) {
                    return topic.getTopicArn();
                }
            }

            nextToken = result.getNextToken();
        } while (nextToken != null);

        return null;
    } catch (Exception exception) {
        System.out.println("Exception  = " + exception);
        return null;
    }
}

From source file:org.springframework.cloud.aws.messaging.support.destination.DynamicTopicDestinationResolver.java

License:Apache License

private String getTopicResourceName(String marker, String topicName) {
    ListTopicsResult listTopicsResult = this.amazonSns.listTopics(new ListTopicsRequest(marker));
    for (Topic topic : listTopicsResult.getTopics()) {
        if (AmazonResourceName.isValidAmazonResourceName(topicName)) {
            if (topic.getTopicArn().equals(topicName)) {
                return topic.getTopicArn();
            }/*from   w  w  w. ja va  2  s.c  o m*/
        } else {
            AmazonResourceName resourceName = AmazonResourceName.fromString(topic.getTopicArn());
            if (resourceName.getResourceType().equals(topicName)) {
                return topic.getTopicArn();
            }
        }
    }

    if (StringUtils.hasText(listTopicsResult.getNextToken())) {
        return getTopicResourceName(listTopicsResult.getNextToken(), topicName);
    } else {
        throw new IllegalArgumentException("No topic found for name :'" + topicName + "'");
    }
}