You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/08/21 14:54:50 UTC
[camel] 01/02: Camel-AWS-SQS: Moving the logic of doStart for
endpoint in doInit
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 993817b5f0f2c2287bd41947d3be06e82fd3cca7
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Aug 21 16:51:39 2019 +0200
Camel-AWS-SQS: Moving the logic of doStart for endpoint in doInit
---
.../camel/component/aws/sqs/SqsEndpoint.java | 75 +++++++++++-----------
.../aws/sqs/SqsEndpointExplicitQueueUrlTest.java | 2 +-
.../camel/component/aws/sqs/SqsEndpointTest.java | 4 +-
3 files changed, 41 insertions(+), 40 deletions(-)
diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
index 0007c32..ff8ac4e 100644
--- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
+++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
@@ -106,52 +106,53 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt
sqsConsumer.setScheduler(scheduler);
return sqsConsumer;
}
-
+
@Override
- protected void doStart() throws Exception {
+ protected void doInit() throws Exception {
+ super.doInit();
client = getConfiguration().getAmazonSQSClient() != null
- ? getConfiguration().getAmazonSQSClient() : getClient();
+ ? getConfiguration().getAmazonSQSClient() : getClient();
- // check the setting the headerFilterStrategy
- if (headerFilterStrategy == null) {
- headerFilterStrategy = new SqsHeaderFilterStrategy();
- }
+ // check the setting the headerFilterStrategy
+ if (headerFilterStrategy == null) {
+ headerFilterStrategy = new SqsHeaderFilterStrategy();
+ }
- if (configuration.getQueueUrl() != null) {
- queueUrl = configuration.getQueueUrl();
- } else {
- // If both region and Account ID is provided the queue URL can be built manually.
- // This allows accessing queues where you don't have permission to list queues or query queues
- if (configuration.getRegion() != null && configuration.getQueueOwnerAWSAccountId() != null) {
- String host = configuration.getAmazonAWSHost();
- host = FileUtil.stripTrailingSeparator(host);
- queueUrl = "https://sqs." + Regions.valueOf(configuration.getRegion()).getName() + "." + host + "/"
- + configuration.getQueueOwnerAWSAccountId() + "/" + configuration.getQueueName();
- } else if (configuration.getQueueOwnerAWSAccountId() != null) {
- GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest();
- getQueueUrlRequest.setQueueName(configuration.getQueueName());
- getQueueUrlRequest.setQueueOwnerAWSAccountId(configuration.getQueueOwnerAWSAccountId());
- GetQueueUrlResult getQueueUrlResult = client.getQueueUrl(getQueueUrlRequest);
- queueUrl = getQueueUrlResult.getQueueUrl();
+ if (configuration.getQueueUrl() != null) {
+ queueUrl = configuration.getQueueUrl();
} else {
- // check whether the queue already exists
- ListQueuesResult listQueuesResult = client.listQueues();
- for (String url : listQueuesResult.getQueueUrls()) {
- if (url.endsWith("/" + configuration.getQueueName())) {
- queueUrl = url;
- log.trace("Queue available at '{}'.", queueUrl);
- break;
+ // If both region and Account ID is provided the queue URL can be built manually.
+ // This allows accessing queues where you don't have permission to list queues or query queues
+ if (configuration.getRegion() != null && configuration.getQueueOwnerAWSAccountId() != null) {
+ String host = configuration.getAmazonAWSHost();
+ host = FileUtil.stripTrailingSeparator(host);
+ queueUrl = "https://sqs." + Regions.valueOf(configuration.getRegion()).getName() + "." + host + "/"
+ + configuration.getQueueOwnerAWSAccountId() + "/" + configuration.getQueueName();
+ } else if (configuration.getQueueOwnerAWSAccountId() != null) {
+ GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest();
+ getQueueUrlRequest.setQueueName(configuration.getQueueName());
+ getQueueUrlRequest.setQueueOwnerAWSAccountId(configuration.getQueueOwnerAWSAccountId());
+ GetQueueUrlResult getQueueUrlResult = client.getQueueUrl(getQueueUrlRequest);
+ queueUrl = getQueueUrlResult.getQueueUrl();
+ } else {
+ // check whether the queue already exists
+ ListQueuesResult listQueuesResult = client.listQueues();
+ for (String url : listQueuesResult.getQueueUrls()) {
+ if (url.endsWith("/" + configuration.getQueueName())) {
+ queueUrl = url;
+ log.trace("Queue available at '{}'.", queueUrl);
+ break;
+ }
}
}
}
- }
- if (queueUrl == null && configuration.isAutoCreateQueue()) {
- createQueue(client);
- } else {
- log.debug("Using Amazon SQS queue url: {}", queueUrl);
- updateQueueAttributes(client);
- }
+ if (queueUrl == null && configuration.isAutoCreateQueue()) {
+ createQueue(client);
+ } else {
+ log.debug("Using Amazon SQS queue url: {}", queueUrl);
+ updateQueueAttributes(client);
+ }
}
protected void createQueue(AmazonSQS client) {
diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java
index 5755296..d3db13c 100644
--- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java
+++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java
@@ -43,7 +43,7 @@ public class SqsEndpointExplicitQueueUrlTest extends Assert {
@Test
public void doStartWithExplicitQueueUrlInConfigShouldNotCallSqsClientListQueues() throws Exception {
- endpoint.doStart();
+ endpoint.doInit();
assertEquals(endpoint.getQueueUrl(), QUEUE_URL);
}
diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java
index 930b251..c35d53d 100644
--- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java
+++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java
@@ -55,7 +55,7 @@ public class SqsEndpointTest {
Mockito.when(amazonSQSClient.listQueues())
.thenReturn(new ListQueuesResult().withQueueUrls("https://sqs.us-east-1.amazonaws.com/ID/dummy-queue", "https://sqs.us-east-1.amazonaws.com/ID/test-queue"));
- endpoint.doStart();
+ endpoint.doInit();
Mockito.verify(amazonSQSClient).listQueues();
}
@@ -70,7 +70,7 @@ public class SqsEndpointTest {
.withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue"));
endpoint.getConfiguration().setQueueOwnerAWSAccountId("111222333");
- endpoint.doStart();
+ endpoint.doInit();
Mockito.verify(amazonSQSClient).getQueueUrl(expectedGetQueueUrlRequest);