use of com.amazonaws.services.sns.model.SetTopicAttributesRequest 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");
}
}
Aggregations