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 2018/06/27 12:50:48 UTC

[camel] 01/02: CAMEL-12600 - Camel-Twilio: the credentials can be set only at component level

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 89a9f42f12c5da57ccdc53c483cf5454145b731c
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Jun 27 13:57:07 2018 +0200

    CAMEL-12600 - Camel-Twilio: the credentials can be set only at component level
---
 .../src/main/docs/twilio-component.adoc            | 10 +--
 .../camel/component/twilio/TwilioComponent.java    | 50 ++++++++++++++-
 .../component/twilio/TwilioConfiguration.java      | 42 -------------
 .../component/twilio/AccountIntegrationTest.java   |  4 +-
 .../springboot/TwilioComponentConfiguration.java   | 72 +++++++++++-----------
 5 files changed, 89 insertions(+), 89 deletions(-)

diff --git a/components/camel-twilio/src/main/docs/twilio-component.adoc b/components/camel-twilio/src/main/docs/twilio-component.adoc
index 4087db8..e08a1f5 100644
--- a/components/camel-twilio/src/main/docs/twilio-component.adoc
+++ b/components/camel-twilio/src/main/docs/twilio-component.adoc
@@ -22,7 +22,7 @@ for this component:
 ### Twilio Options
 
 // component options: START
-The Twilio component supports 3 options, which are listed below.
+The Twilio component supports 6 options, which are listed below.
 
 
 
@@ -31,6 +31,9 @@ The Twilio component supports 3 options, which are listed below.
 | Name | Description | Default | Type
 | *configuration* (advanced) | To use the shared configuration |  | TwilioConfiguration
 | *restClient* (advanced) | To use the shared REST client |  | TwilioRestClient
+| *username* (security) | The account to use. |  | String
+| *password* (security) | Auth token for the account. |  | String
+| *accountSid* (security) | The account SID to use. |  | String
 | *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
@@ -55,7 +58,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (8 parameters):
+==== Query Parameters (5 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -66,9 +69,6 @@ with the following path and query parameters:
 | *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
-| *accountSid* (security) | The account SID to use. |  | String
-| *password* (security) | Auth token for the account. |  | String
-| *username* (security) | The account to use. |  | String
 |===
 // endpoint options: END
 
diff --git a/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioComponent.java b/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioComponent.java
index 58031df..a769b2d 100644
--- a/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioComponent.java
+++ b/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioComponent.java
@@ -22,6 +22,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.component.twilio.internal.TwilioApiCollection;
 import org.apache.camel.component.twilio.internal.TwilioApiName;
 import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.component.AbstractApiComponent;
 
 /**
@@ -34,6 +35,15 @@ public class TwilioComponent extends AbstractApiComponent<TwilioApiName, TwilioC
 
     @Metadata(label = "advanced")
     private TwilioRestClient restClient;
+    
+    @Metadata(label = "common,security", secret = true)
+    private String username;
+
+    @Metadata(label = "common,security", secret = true)
+    private String password;
+
+    @Metadata(label = "common,security", secret = true)
+    private String accountSid;
 
     public TwilioComponent() {
         super(TwilioEndpoint.class, TwilioApiName.class, TwilioApiCollection.getCollection());
@@ -61,11 +71,12 @@ public class TwilioComponent extends AbstractApiComponent<TwilioApiName, TwilioC
         super.doStart();
 
         if (restClient == null) {
-            if (configuration == null) {
+            if (ObjectHelper.isEmpty(username) && ObjectHelper.isEmpty(password)) {
                 throw new IllegalStateException("Unable to initialise Twilio, Twilio component configuration is missing");
             }
-            restClient = new TwilioRestClient.Builder(configuration.getUsername(), configuration.getPassword())
-                .accountSid(configuration.getAccountSid())
+
+            restClient = new TwilioRestClient.Builder(username, password)
+                .accountSid(accountSid)
                 .build();
         }
     }
@@ -97,4 +108,37 @@ public class TwilioComponent extends AbstractApiComponent<TwilioApiName, TwilioC
     public void setRestClient(TwilioRestClient restClient) {
         this.restClient = restClient;
     }
+    
+    public String getUsername() {
+        return username;
+    }
+
+    /**
+     * The account to use.
+     */
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    /**
+     * Auth token for the account.
+     */
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getAccountSid() {
+        return accountSid == null ? username : accountSid;
+    }
+
+    /**
+     * The account SID to use.
+     */
+    public void setAccountSid(String accountSid) {
+        this.accountSid = accountSid;
+    }
 }
diff --git a/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioConfiguration.java b/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioConfiguration.java
index 4ff4427..98b8f7b 100644
--- a/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioConfiguration.java
+++ b/components/camel-twilio/src/main/java/org/apache/camel/component/twilio/TwilioConfiguration.java
@@ -37,15 +37,6 @@ public class TwilioConfiguration implements Cloneable {
     @Metadata(required = "true")
     private String methodName;
 
-    @UriParam(label = "common,security", secret = true)
-    private String username;
-
-    @UriParam(label = "common,security", secret = true)
-    private String password;
-
-    @UriParam(label = "common,security", secret = true)
-    private String accountSid;
-
     /**
      * Returns a copy of this configuration
      */
@@ -94,37 +85,4 @@ public class TwilioConfiguration implements Cloneable {
     public void setMethodName(String methodName) {
         this.methodName = methodName;
     }
-
-    public String getUsername() {
-        return username;
-    }
-
-    /**
-     * The account to use.
-     */
-    public void setUsername(String username) {
-        this.username = username;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    /**
-     * Auth token for the account.
-     */
-    public void setPassword(String password) {
-        this.password = password;
-    }
-
-    public String getAccountSid() {
-        return accountSid == null ? username : accountSid;
-    }
-
-    /**
-     * The account SID to use.
-     */
-    public void setAccountSid(String accountSid) {
-        this.accountSid = accountSid;
-    }
 }
diff --git a/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/AccountIntegrationTest.java b/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/AccountIntegrationTest.java
index 266ba53..46e3068 100644
--- a/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/AccountIntegrationTest.java
+++ b/components/camel-twilio/src/test/java/org/apache/camel/component/twilio/AccountIntegrationTest.java
@@ -47,10 +47,8 @@ public class AccountIntegrationTest extends AbstractTwilioTestSupport {
 
     @Test
     public void testFetcherWithPathSid() throws Exception {
-        TwilioConfiguration configuration = ((TwilioComponent) context().getComponent("twilio"))
-            .getConfiguration();
         final Account result = requestBodyAndHeaders("direct://FETCHER", null,
-            headers("CamelTwilioPathSid", configuration.getAccountSid()));
+            headers("CamelTwilioPathSid", ((TwilioComponent) context().getComponent("twilio")).getAccountSid()));
 
         assertNotNull("fetcher result not null", result);
         assertNotNull("fetcher result sid not null", result.getSid());
diff --git a/platforms/spring-boot/components-starter/camel-twilio-starter/src/main/java/org/apache/camel/component/twilio/springboot/TwilioComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-twilio-starter/src/main/java/org/apache/camel/component/twilio/springboot/TwilioComponentConfiguration.java
index 8e4f77e..2e850b8 100644
--- a/platforms/spring-boot/components-starter/camel-twilio-starter/src/main/java/org/apache/camel/component/twilio/springboot/TwilioComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-twilio-starter/src/main/java/org/apache/camel/component/twilio/springboot/TwilioComponentConfiguration.java
@@ -45,6 +45,18 @@ public class TwilioComponentConfiguration
     @NestedConfigurationProperty
     private TwilioRestClient restClient;
     /**
+     * The account to use.
+     */
+    private String username;
+    /**
+     * Auth token for the account.
+     */
+    private String password;
+    /**
+     * The account SID to use.
+     */
+    private String accountSid;
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
@@ -68,6 +80,30 @@ public class TwilioComponentConfiguration
         this.restClient = restClient;
     }
 
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getAccountSid() {
+        return accountSid;
+    }
+
+    public void setAccountSid(String accountSid) {
+        this.accountSid = accountSid;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }
@@ -93,18 +129,6 @@ public class TwilioComponentConfiguration
          *            methodName to set
          */
         private String methodName;
-        /**
-         * The account to use.
-         */
-        private String username;
-        /**
-         * Auth token for the account.
-         */
-        private String password;
-        /**
-         * The account SID to use.
-         */
-        private String accountSid;
 
         public TwilioApiName getApiName() {
             return apiName;
@@ -121,29 +145,5 @@ public class TwilioComponentConfiguration
         public void setMethodName(String methodName) {
             this.methodName = methodName;
         }
-
-        public String getUsername() {
-            return username;
-        }
-
-        public void setUsername(String username) {
-            this.username = username;
-        }
-
-        public String getPassword() {
-            return password;
-        }
-
-        public void setPassword(String password) {
-            this.password = password;
-        }
-
-        public String getAccountSid() {
-            return accountSid;
-        }
-
-        public void setAccountSid(String accountSid) {
-            this.accountSid = accountSid;
-        }
     }
 }
\ No newline at end of file