[ 
https://issues.apache.org/jira/browse/CAMEL-11925?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16216540#comment-16216540
 ] 

ASF GitHub Bot commented on CAMEL-11925:
----------------------------------------

oscerd closed pull request #2056: CAMEL-11925: Migrate atmos properties file 
configuration to component properties
URL: https://github.com/apache/camel/pull/2056
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/components/camel-atmos/src/main/docs/atmos-component.adoc 
b/components/camel-atmos/src/main/docs/atmos-component.adoc
index 9dcbd371756..1db769c8a43 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 19e8233c9ea..95125fb60c2 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 @@
 
 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 @@ protected Endpoint createEndpoint(String uri, String 
remaining, Map<String, Obje
 
         // 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 @@ protected Endpoint createEndpoint(String uri, String 
remaining, Map<String, Obje
         // 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 b510064861c..00000000000
--- 
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 00000000000..5d341d90ab9
--- /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 3bf9b7c7b25..cb587a45a03 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 @@
 
 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 8a9a1934a31..80dbdac3514 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 24eafb84ecd..28a0eb34140 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 6ccf0bb04a4..6683196bf59 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 @@
             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;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Atmos component fails to load atmos.properties in a modular class loading 
> environment 
> --------------------------------------------------------------------------------------
>
>                 Key: CAMEL-11925
>                 URL: https://issues.apache.org/jira/browse/CAMEL-11925
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-atmos
>    Affects Versions: 2.20.0
>            Reporter: James Netherton
>            Assignee: James Netherton
>             Fix For: 2.20.1, 2.21.0
>
>
> The atmos component has a AtmosPropertyManager class which attempts to do:
> {code}
> AtmosPropertyManager.class.getResource("/atmos.properties");
> {code}
> This assumes the resource is available to the ClassLoader of 
> AtmosPropertyManager. This may not be the case in OSGi or JavaEE containers.
> I see there's a [TODO 
> comment|https://github.com/apache/camel/blob/master/components/camel-atmos/src/main/java/org/apache/camel/component/atmos/util/AtmosPropertyManager.java#L26]
>  at the top of this class. So maybe we remove this class and make it so we 
> configure these properties on the component instead?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to