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 2017/10/24 08:42:09 UTC

[camel] branch master updated: CAMEL-11925: Migrate atmos properties file configuration to component properties

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


The following commit(s) were added to refs/heads/master by this push:
     new 00e443b  CAMEL-11925: Migrate atmos properties file configuration to component properties
00e443b is described below

commit 00e443b9ed6da8a5518a432345f497d8bd869ce1
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Oct 24 08:37:32 2017 +0100

    CAMEL-11925: Migrate atmos properties file configuration to component properties
---
 .../camel-atmos/src/main/docs/atmos-component.adoc | 14 +++-
 .../camel/component/atmos/AtmosComponent.java      | 73 ++++++++++++++++---
 .../component/atmos/util/AtmosPropertyManager.java | 63 ----------------
 .../camel/component/atmos/AtmosComponentTest.java  | 85 ++++++++++++++++++++++
 .../camel/component/atmos/AtmosConsumerTest.java   | 13 ++--
 .../atmos/integration/AtmosTestSupport.java        | 43 ++++-------
 .../src/test/resources/atmos.properties            |  5 +-
 .../springboot/AtmosComponentConfiguration.java    | 48 ++++++++++++
 8 files changed, 234 insertions(+), 110 deletions(-)

diff --git a/components/camel-atmos/src/main/docs/atmos-component.adoc b/components/camel-atmos/src/main/docs/atmos-component.adoc
index 9dcbd37..1db769c 100644
--- a/components/camel-atmos/src/main/docs/atmos-component.adoc
+++ b/components/camel-atmos/src/main/docs/atmos-component.adoc
@@ -15,7 +15,19 @@ from("atmos:foo/get?remotePath=/path").to("mock:test");
 
 
 // component options: START
-The Atmos component has no options.
+The Atmos component supports 5 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *fullTokenId* (security) | The token id to pass to the Atmos client |  | String
+| *secretKey* (security) | The secret key to pass to the Atmos client |  | String
+| *uri* (advanced) | The URI of the server for the Atmos client to connect to |  | String
+| *sslValidation* (security) | Whether the Atmos client should perform SSL validation | false | boolean
+| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
+|===
 // component options: END
 
 
diff --git a/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/AtmosComponent.java b/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/AtmosComponent.java
index 19e8233..95125fb 100644
--- a/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/AtmosComponent.java
+++ b/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/AtmosComponent.java
@@ -18,19 +18,32 @@ package org.apache.camel.component.atmos;
 
 import java.util.Map;
 
-import org.apache.camel.Endpoint;
+import org.apache.camel.CamelContext;
 import org.apache.camel.component.atmos.util.AtmosOperation;
-import org.apache.camel.component.atmos.util.AtmosPropertyManager;
 import org.apache.camel.component.atmos.validator.AtmosConfigurationValidator;
 import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.Metadata;
 
 public class AtmosComponent extends UriEndpointComponent {
 
+    @Metadata(label = "security")
+    private String fullTokenId;
+    @Metadata(label = "security")
+    private String secretKey;
+    @Metadata(label = "advanced")
+    private String uri;
+    @Metadata(label = "security")
+    private boolean sslValidation;
+
     public AtmosComponent() {
         super(AtmosEndpoint.class);
     }
 
-    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+    public AtmosComponent(CamelContext context) {
+        super(context, AtmosEndpoint.class);
+    }
+
+    protected AtmosEndpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
         AtmosConfiguration configuration = new AtmosConfiguration();
 
         String name = null;
@@ -46,19 +59,19 @@ public class AtmosComponent extends UriEndpointComponent {
 
         // set options from component
         configuration.setUri(parameters.get("uri") == null
-                ? AtmosPropertyManager.getInstance().getProperty("uri")
+                ? this.uri
                 : (String) parameters.get("uri"));
         configuration.setSecretKey(parameters.get("secretKey") == null
-                ? AtmosPropertyManager.getInstance().getProperty("secretKey")
+                ? this.secretKey
                 : (String) parameters.get("secretKey"));
         configuration.setLocalPath((String) parameters.get("localPath"));
         configuration.setRemotePath((String) parameters.get("remotePath"));
         configuration.setNewRemotePath((String) parameters.get("newRemotePath"));
         configuration.setQuery((String) parameters.get("query"));
         configuration.setFullTokenId(parameters.get("fullTokenId") == null
-                ? AtmosPropertyManager.getInstance().getProperty("fullTokenId")
+                ? this.fullTokenId
                 : (String) parameters.get("fullTokenId"));
-        configuration.setEnableSslValidation(Boolean.parseBoolean(AtmosPropertyManager.getInstance().getProperty("sslValidation")));
+        configuration.setEnableSslValidation(this.sslValidation);
 
         //pass validation test
         AtmosConfigurationValidator.validate(configuration);
@@ -66,8 +79,50 @@ public class AtmosComponent extends UriEndpointComponent {
         // and then override from parameters
         setProperties(configuration, parameters);
 
-        Endpoint endpoint = new AtmosEndpoint(uri, this, configuration);
-        return endpoint;
+        return new AtmosEndpoint(uri, this, configuration);
+    }
+
+    public String getFullTokenId() {
+        return fullTokenId;
+    }
+
+    /**
+     * The token id to pass to the Atmos client
+     */
+    public void setFullTokenId(String fullTokenId) {
+        this.fullTokenId = fullTokenId;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
     }
 
+    /**
+     * The secret key to pass to the Atmos client
+     */
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+
+    /**
+     * The URI of the server for the Atmos client to connect to
+     */
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public boolean isSslValidation() {
+        return sslValidation;
+    }
+
+    /**
+     * Whether the Atmos client should perform SSL validation
+     */
+    public void setSslValidation(boolean sslValidation) {
+        this.sslValidation = sslValidation;
+    }
 }
diff --git a/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/util/AtmosPropertyManager.java b/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/util/AtmosPropertyManager.java
deleted file mode 100644
index b510064..0000000
--- a/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/util/AtmosPropertyManager.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.atmos.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Properties;
-
-public final class AtmosPropertyManager {
-
-    // TODO: this is wrong, this should be configured on the component instead
-    // and no static code please!
-
-    private static Properties properties;
-    private static AtmosPropertyManager instance;
-
-    private AtmosPropertyManager() { }
-
-    public static synchronized AtmosPropertyManager getInstance() throws Exception {
-        if (instance == null) {
-            instance = new AtmosPropertyManager();
-            properties = loadProperties();
-        }
-        return instance;
-    }
-
-    public String getProperty(String key) {
-        return properties.getProperty(key);
-    }
-
-
-    private static Properties loadProperties() throws Exception {
-        URL url = AtmosPropertyManager.class.getResource("/atmos.properties");
-        InputStream inStream;
-        try {
-            inStream = url.openStream();
-        } catch (IOException e) {
-            throw new AtmosException("atmos.properties could not be found");
-        }
-        properties = new Properties();
-        try {
-            properties.load(inStream);
-        } catch (IOException e) {
-            throw new AtmosException("atmos.properties can't be read");
-        }
-        return properties;
-    }
-}
diff --git a/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosComponentTest.java b/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosComponentTest.java
new file mode 100644
index 0000000..5d341d9
--- /dev/null
+++ b/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosComponentTest.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.atmos;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.URISupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AtmosComponentTest {
+
+    private static final String FAKE_REMOTE_PATH = "/remote";
+    private static final String FAKE_SECRET = "fake-secret";
+    private static final String FAKE_TOKEN = "fake-token";
+    private static final String FAKE_URI = "http://fake/uri";
+
+    @Mock
+    private CamelContext context;
+
+    @Test
+    public void testComponentOptions() throws Exception {
+        AtmosComponent component = new AtmosComponent(context);
+        component.setFullTokenId(FAKE_TOKEN);
+        component.setSecretKey(FAKE_SECRET);
+        component.setSslValidation(false);
+        component.setUri(FAKE_URI);
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("remotePath", FAKE_REMOTE_PATH);
+
+        AtmosEndpoint endpoint = component.createEndpoint("atmos://foo?remotePath=/remote", "foo/get", parameters);
+        AtmosConfiguration configuration = endpoint.getConfiguration();
+
+        assertEquals(FAKE_TOKEN, configuration.getFullTokenId());
+        assertEquals(FAKE_SECRET, configuration.getSecretKey());
+        assertEquals(false, configuration.isEnableSslValidation());
+        assertEquals(FAKE_URI, configuration.getUri());
+    }
+
+    @Test
+    public void testUriParamsOverrideComponentOptions() throws Exception {
+        AtmosComponent component = new AtmosComponent(context);
+        component.setFullTokenId("fakeTokenToBeOverridden");
+        component.setSecretKey("fakeSecretToBeOverridden");
+        component.setSslValidation(true);
+        component.setUri("http://fake/uri/to/be/overridden");
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("remotePath", FAKE_REMOTE_PATH);
+        parameters.put("fullTokenId", FAKE_TOKEN);
+        parameters.put("secretKey", FAKE_SECRET);
+        parameters.put("enableSslValidation", false);
+        parameters.put("uri", FAKE_URI);
+
+        String uri = URISupport.appendParametersToURI("atmos://foo", parameters);
+        AtmosEndpoint endpoint = component.createEndpoint(uri, "foo/get", parameters);
+        AtmosConfiguration configuration = endpoint.getConfiguration();
+
+        assertEquals(FAKE_TOKEN, configuration.getFullTokenId());
+        assertEquals(FAKE_SECRET, configuration.getSecretKey());
+        assertEquals(false, configuration.isEnableSslValidation());
+        assertEquals(FAKE_URI, configuration.getUri());
+    }
+}
diff --git a/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosConsumerTest.java b/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosConsumerTest.java
index 3bf9b7c..cb587a4 100644
--- a/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosConsumerTest.java
+++ b/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/AtmosConsumerTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.atmos;
 
 import org.apache.camel.Consumer;
+import org.apache.camel.EndpointInject;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.atmos.integration.consumer.AtmosScheduledPollGetConsumer;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -25,25 +26,23 @@ import org.junit.Test;
 
 public class AtmosConsumerTest extends CamelTestSupport {
 
+    @EndpointInject(uri = "atmos:foo/get?remotePath=/path&fullTokenId=fakeToken&secretKey=fakeSecret&uri=https://fake/uri")
+    private AtmosEndpoint atmosEndpoint;
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("atmos:foo/get?remotePath=/path").to("mock:test");
+                from(atmosEndpoint)
+                    .to("mock:test");
             }
         };
     }
 
     @Test
     public void shouldCreateGetConsumer() throws Exception {
-        // Given
-        AtmosEndpoint atmosEndpoint = context.getEndpoint("atmos:foo/get?remotePath=/path", AtmosEndpoint.class);
-
-        // When
         Consumer consumer = atmosEndpoint.createConsumer(null);
-
-        // Then
         Assert.assertTrue(consumer instanceof AtmosScheduledPollGetConsumer);
         assertEquals("foo", atmosEndpoint.getConfiguration().getName());
     }
diff --git a/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/integration/AtmosTestSupport.java b/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/integration/AtmosTestSupport.java
index 8a9a193..80dbdac 100644
--- a/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/integration/AtmosTestSupport.java
+++ b/components/camel-atmos/src/test/java/org/apache/camel/component/atmos/integration/AtmosTestSupport.java
@@ -16,40 +16,29 @@
  */
 package org.apache.camel.component.atmos.integration;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
 import java.util.Properties;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.atmos.AtmosComponent;
 import org.apache.camel.test.junit4.CamelTestSupport;
 
 
 public class AtmosTestSupport extends CamelTestSupport {
 
-    protected final Properties properties;
-
-    protected AtmosTestSupport() throws Exception {
-        URL url = getClass().getResource("/test-options.properties");
-
-        InputStream inStream;
-        try {
-            inStream = url.openStream();
-        } catch (IOException e) {
-            e.printStackTrace();
-            throw new IllegalAccessError("test-options.properties could not be found");
-        }
-
-        properties = new Properties();
-        try {
-            properties.load(inStream);
-        } catch (IOException e) {
-            e.printStackTrace();
-            throw new IllegalAccessError("test-options.properties could not be found");
-        }
-    }
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        Properties properties = new Properties();
+        properties.load(getClass().getResourceAsStream("/atmos.properties"));
+
+        AtmosComponent component = new AtmosComponent();
+        component.setFullTokenId(properties.getProperty("fullTokenId"));
+        component.setSecretKey(properties.getProperty("secretKey"));
+        component.setUri(properties.getProperty("uri"));
+        component.setSslValidation(Boolean.parseBoolean(properties.getProperty("sslValidation")));
+        context.addComponent("atmos", component);
 
-    protected String getAuthParams() {
-        return "accessToken=" + properties.get("accessToken")
-                + "&clientIdentifier=" + properties.get("clientIdentifier");
+        return camelContext;
     }
 }
diff --git a/components/camel-atmos/src/test/resources/atmos.properties b/components/camel-atmos/src/test/resources/atmos.properties
index 24eafb8..28a0eb3 100644
--- a/components/camel-atmos/src/test/resources/atmos.properties
+++ b/components/camel-atmos/src/test/resources/atmos.properties
@@ -17,6 +17,5 @@
 
 fullTokenId=<Subtentant_ID/UID>
 secretKey=<UID_shared_secret>
-# The uri need to valide value
-uri=http://atmos_host
-sslValidation=<true|false>
+uri=https://atmos_host
+sslValidation=true
diff --git a/platforms/spring-boot/components-starter/camel-atmos-starter/src/main/java/org/apache/camel/component/atmos/springboot/AtmosComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-atmos-starter/src/main/java/org/apache/camel/component/atmos/springboot/AtmosComponentConfiguration.java
index 6ccf0bb..6683196 100644
--- a/platforms/spring-boot/components-starter/camel-atmos-starter/src/main/java/org/apache/camel/component/atmos/springboot/AtmosComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-atmos-starter/src/main/java/org/apache/camel/component/atmos/springboot/AtmosComponentConfiguration.java
@@ -32,12 +32,60 @@ public class AtmosComponentConfiguration
             ComponentConfigurationPropertiesCommon {
 
     /**
+     * The token id to pass to the Atmos client
+     */
+    private String fullTokenId;
+    /**
+     * The secret key to pass to the Atmos client
+     */
+    private String secretKey;
+    /**
+     * The URI of the server for the Atmos client to connect to
+     */
+    private String uri;
+    /**
+     * Whether the Atmos client should perform SSL validation
+     */
+    private Boolean sslValidation = false;
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
      */
     private Boolean resolvePropertyPlaceholders = true;
 
+    public String getFullTokenId() {
+        return fullTokenId;
+    }
+
+    public void setFullTokenId(String fullTokenId) {
+        this.fullTokenId = fullTokenId;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public Boolean getSslValidation() {
+        return sslValidation;
+    }
+
+    public void setSslValidation(Boolean sslValidation) {
+        this.sslValidation = sslValidation;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].