This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch fix/CAMEL-24157
in repository https://gitbox.apache.org/repos/asf/camel.git

commit db2e61eb7d34a72ad1f9b43599fe7c8418384021
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jul 17 17:41:01 2026 +0200

    CAMEL-24157: camel-aws2-sns - Fix dead-code queueArn validation, SSE 
validation, and health check
    
    Fix subscribeSNStoSQS queueArn validation that was dead code due to
    nested isNotEmpty(isNotEmpty()) always returning true. Also update stale
    error message. Require kmsMasterKeyId when serverSideEncryptionEnabled
    is true instead of silently creating unencrypted topics. Fix health
    check NPE when region is unset and replace listSubscriptions (requires
    broad IAM) with getTopicAttributes (matches producer permissions).
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../java/org/apache/camel/component/aws2/sns/Sns2Endpoint.java |  9 ++++++---
 .../camel/component/aws2/sns/Sns2ProducerHealthCheck.java      | 10 ++++++++--
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Endpoint.java
 
b/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Endpoint.java
index 10e13d46e43d..3c64b5fa5c10 100644
--- 
a/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Endpoint.java
+++ 
b/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2Endpoint.java
@@ -140,8 +140,11 @@ public class Sns2Endpoint extends DefaultEndpoint 
implements HeaderFilterStrateg
             if (configuration.isServerSideEncryptionEnabled()) {
                 if 
(ObjectHelper.isNotEmpty(configuration.getKmsMasterKeyId())) {
                     attributes.put("KmsMasterKeyId", 
configuration.getKmsMasterKeyId());
-                    builder.attributes(attributes);
+                } else {
+                    throw new IllegalArgumentException(
+                            "The option kmsMasterKeyId is required when 
serverSideEncryptionEnabled is true");
                 }
+                builder.attributes(attributes);
             }
 
             if (configuration.isFifoTopic()) {
@@ -173,14 +176,14 @@ public class Sns2Endpoint extends DefaultEndpoint 
implements HeaderFilterStrateg
         }
 
         if (configuration.isSubscribeSNStoSQS()) {
-            if 
(ObjectHelper.isNotEmpty(ObjectHelper.isNotEmpty(configuration.getQueueArn()))) 
{
+            if (ObjectHelper.isNotEmpty(configuration.getQueueArn())) {
                 SubscribeResponse resp = 
snsClient.subscribe(SubscribeRequest.builder().topicArn(configuration.getTopicArn())
                         .protocol("sqs").endpoint(configuration.getQueueArn())
                         .returnSubscriptionArn(true).build());
                 LOG.trace("Subscription of SQS Queue to SNS Topic done with 
Amazon resource name: {}", resp.subscriptionArn());
             } else {
                 throw new IllegalArgumentException(
-                        "Using the SubscribeSNStoSQS option require both 
AmazonSQSClient and Queue URL options");
+                        "Using the SubscribeSNStoSQS option requires the 
queueArn option to be set");
             }
         }
 
diff --git 
a/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2ProducerHealthCheck.java
 
b/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2ProducerHealthCheck.java
index dfa21751b5d0..a54abbadd867 100644
--- 
a/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2ProducerHealthCheck.java
+++ 
b/components/camel-aws/camel-aws2-sns/src/main/java/org/apache/camel/component/aws2/sns/Sns2ProducerHealthCheck.java
@@ -20,9 +20,11 @@ import java.util.Map;
 
 import org.apache.camel.health.HealthCheckResultBuilder;
 import org.apache.camel.impl.health.AbstractHealthCheck;
+import org.apache.camel.util.ObjectHelper;
 import software.amazon.awssdk.awscore.exception.AwsServiceException;
 import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.sns.SnsClient;
+import software.amazon.awssdk.services.sns.model.GetTopicAttributesRequest;
 
 public class Sns2ProducerHealthCheck extends AbstractHealthCheck {
 
@@ -37,13 +39,17 @@ public class Sns2ProducerHealthCheck extends 
AbstractHealthCheck {
     protected void doCall(HealthCheckResultBuilder builder, Map<String, 
Object> options) {
         Sns2Configuration configuration = sns2Endpoint.getConfiguration();
         try {
-            if 
(!SnsClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion())))
 {
+            if (ObjectHelper.isNotEmpty(configuration.getRegion())
+                    && 
!SnsClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion())))
 {
                 builder.message("The service is not supported in this region");
                 builder.down();
                 return;
             }
             SnsClient client = sns2Endpoint.getSNSClient();
-            client.listSubscriptions();
+            if (ObjectHelper.isNotEmpty(configuration.getTopicArn())) {
+                client.getTopicAttributes(
+                        
GetTopicAttributesRequest.builder().topicArn(configuration.getTopicArn()).build());
+            }
         } catch (AwsServiceException e) {
             builder.message(e.getMessage());
             builder.error(e);

Reply via email to