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 2021/02/26 08:31:15 UTC

[camel] 01/04: CAMEL-16171 - Add uri-endpoint-override options to all AWS2 components - AWS2-CW component

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 4b13e744db778d70a93e6ea6f63e995dd823e59f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Feb 26 09:15:14 2021 +0100

    CAMEL-16171 - Add uri-endpoint-override options to all AWS2 components - AWS2-CW component
---
 .../camel/component/aws2/cw/Cw2Configuration.java  | 27 ++++++++++++++++++++++
 .../camel/component/aws2/cw/Cw2Endpoint.java       |  3 +++
 .../aws2/cw/CwComponentConfigurationTest.java      | 18 +++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Configuration.java b/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Configuration.java
index fd9dae2..1833e40 100644
--- a/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Configuration.java
+++ b/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Configuration.java
@@ -57,6 +57,10 @@ public class Cw2Configuration implements Cloneable {
     private String region;
     @UriParam(defaultValue = "false")
     private boolean trustAllCertificates;
+    @UriParam(defaultValue = "false")
+    private boolean overrideEndpoint;
+    @UriParam
+    private String uriEndpointOverride;
 
     public String getAccessKey() {
         return accessKey;
@@ -202,6 +206,29 @@ public class Cw2Configuration implements Cloneable {
         this.trustAllCertificates = trustAllCertificates;
     }
 
+    public boolean isOverrideEndpoint() {
+        return overrideEndpoint;
+    }
+
+    /**
+     * Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride
+     * option
+     */
+    public void setOverrideEndpoint(boolean overrideEndpoint) {
+        this.overrideEndpoint = overrideEndpoint;
+    }
+
+    public String getUriEndpointOverride() {
+        return uriEndpointOverride;
+    }
+
+    /**
+     * Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option
+     */
+    public void setUriEndpointOverride(String uriEndpointOverride) {
+        this.uriEndpointOverride = uriEndpointOverride;
+    }
+
     // *************************************************
     //
     // *************************************************
diff --git a/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java b/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java
index 1951a7c..df154dd 100644
--- a/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java
+++ b/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Endpoint.java
@@ -128,6 +128,9 @@ public class Cw2Endpoint extends DefaultEndpoint {
         if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
             clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
         }
+        if (configuration.isOverrideEndpoint()) {
+            clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
+        }
         if (configuration.isTrustAllCertificates()) {
             SdkHttpClient ahc = ApacheHttpClient.builder().buildWithDefaults(AttributeMap
                     .builder()
diff --git a/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentConfigurationTest.java b/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentConfigurationTest.java
index d67e35c..1633ac1 100644
--- a/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentConfigurationTest.java
+++ b/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentConfigurationTest.java
@@ -27,6 +27,7 @@ import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class CwComponentConfigurationTest extends CamelTestSupport {
 
@@ -118,4 +119,21 @@ public class CwComponentConfigurationTest extends CamelTestSupport {
         assertEquals(Integer.valueOf(9000), endpoint.getConfiguration().getProxyPort());
         assertEquals(Protocol.HTTPS, endpoint.getConfiguration().getProxyProtocol());
     }
+
+    @Test
+    public void createEndpointWithEndpointOverride() throws Exception {
+        Cw2Component component = context.getComponent("aws2-cw", Cw2Component.class);
+        component.getConfiguration().setAccessKey("XXX");
+        component.getConfiguration().setSecretKey("YYY");
+        component.getConfiguration().setRegion(Region.US_WEST_1.toString());
+        Cw2Endpoint endpoint = (Cw2Endpoint) component
+                .createEndpoint("aws2-cw://camel.apache.org/test?overrideEndpoint=true&uriEndpointOverride=http://localhost:9090");
+
+        assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace());
+        assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
+        assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
+        assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
+        assertTrue(endpoint.getConfiguration().isOverrideEndpoint());
+        assertEquals("http://localhost:9090", endpoint.getConfiguration().getUriEndpointOverride());
+    }
 }