You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/12 07:16:41 UTC

[camel] branch master updated: CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - corda

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

davsclaus 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 b87d015  CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - corda
b87d015 is described below

commit b87d01519a35b2b47199285d6e1f9dbefc5b4529
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Dec 12 08:16:12 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - corda
---
 components/camel-corda/README.md                   |  3 -
 components/camel-corda/pom.xml                     |  4 -
 .../camel-corda/src/main/docs/corda-component.adoc | 15 ++--
 .../camel/component/corda/CordaComponent.java      | 23 +++---
 .../camel/component/corda/CordaConfiguration.java  | 78 +++++++++++++------
 .../camel/component/corda/CordaEndpoint.java       | 37 ++++-----
 .../endpoint/dsl/CordaEndpointBuilderFactory.java  | 87 ++++++++++++++++++++--
 .../springboot/CordaComponentConfiguration.java    | 52 ++++++++++++-
 8 files changed, 222 insertions(+), 77 deletions(-)

diff --git a/components/camel-corda/README.md b/components/camel-corda/README.md
deleted file mode 100644
index ddbbbad..0000000
--- a/components/camel-corda/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# camel-corda
-
-[Apache Camel](http://camel.apache.org/) connector for R3's [Corda](https://www.corda.net/) blockchain platform using corda-rpc library. 
diff --git a/components/camel-corda/pom.xml b/components/camel-corda/pom.xml
index f2fcd6b..86071f2 100644
--- a/components/camel-corda/pom.xml
+++ b/components/camel-corda/pom.xml
@@ -32,10 +32,6 @@
     <name>Camel :: Corda</name>
     <description>Camel Corda which is based on corda-rpc support</description>
 
-    <properties>
-    </properties>
-
-
     <dependencies>
         <dependency>
             <groupId>org.apache.camel</groupId>
diff --git a/components/camel-corda/src/main/docs/corda-component.adoc b/components/camel-corda/src/main/docs/corda-component.adoc
index 85df145..1ad6529 100644
--- a/components/camel-corda/src/main/docs/corda-component.adoc
+++ b/components/camel-corda/src/main/docs/corda-component.adoc
@@ -10,8 +10,8 @@
 
 *Since Camel 2.23*
 
-
-The Corda blockchain component uses the https://www.corda.net/[corda] rpc client
+Camel connector for R3's https://www.corda.net/[corda] blockchain platform using corda-rpc library.
+This component uses the corda rpc client.
 
 Maven users will need to add the following dependency to their `pom.xml`
 for this component:
@@ -44,7 +44,7 @@ The Corda component supports 4 options, which are listed below.
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *configuration* (common) | Default configuration |  | CordaConfiguration
+| *configuration* (common) | To use a shared configuration. |  | CordaConfiguration
 | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
@@ -56,7 +56,7 @@ The Corda component supports 4 options, which are listed below.
 The Corda endpoint is configured using URI syntax:
 
 ----
-corda:configuration
+corda:node
 ----
 
 with the following path and query parameters:
@@ -67,11 +67,11 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *configuration* | *Required* URL to the corda node |  | CordaConfiguration
+| *node* | *Required* The url for the corda node |  | String
 |===
 
 
-=== Query Parameters (6 parameters):
+=== Query Parameters (9 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -81,8 +81,11 @@ 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 option 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
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...]
+| *operation* (producer) | Operation to use |  | String
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+| *password* (security) | Password for login |  | String
+| *username* (security) | Username for login |  | String
 |===
 // endpoint options: END
 // spring-boot-auto-configure options: START
diff --git a/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaComponent.java b/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaComponent.java
index b27eb6b..ea1131d 100644
--- a/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaComponent.java
+++ b/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaComponent.java
@@ -24,26 +24,19 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
 
-/**
- * Represents the component that manages {@link CordaComponent}.
- */
 @Component("corda")
 public class CordaComponent extends DefaultComponent {
 
-    @Metadata(description = "Default configuration")
+    @Metadata
     private CordaConfiguration configuration;
 
-    public CordaComponent() {
-    }
-
-    public CordaComponent(CamelContext camelContext) {
-        super(camelContext);
-    }
-
     public CordaConfiguration getConfiguration() {
         return configuration;
     }
 
+    /**
+     * To use a shared configuration.
+     */
     public void setConfiguration(CordaConfiguration configuration) {
         this.configuration = configuration;
     }
@@ -51,8 +44,12 @@ public class CordaComponent extends DefaultComponent {
     @Override
     protected Endpoint createEndpoint(String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
         CordaConfiguration conf =  configuration != null ? configuration.copy() : new CordaConfiguration();
-        setProperties(conf, parameters);
-        return new CordaEndpoint(uri, remaining, this, conf);
+        conf.setNode(remaining);
+
+        CordaEndpoint endpoint = new CordaEndpoint(uri, this, conf);
+        setProperties(endpoint, parameters);
+        conf.configure();
+        return endpoint;
     }
 
 }
diff --git a/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaConfiguration.java b/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaConfiguration.java
index e9f981b..bbb2926 100644
--- a/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaConfiguration.java
+++ b/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaConfiguration.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.corda;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import net.corda.core.contracts.ContractState;
 import net.corda.core.flows.FlowLogic;
 import net.corda.core.node.services.vault.PageSpecification;
@@ -25,46 +28,70 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
 
 @UriParams
 public class CordaConfiguration implements Cloneable {
-    @UriParam
-    @Metadata(required = true)
-    private String operation;
 
-    @UriParam
-    @Metadata(required = true, secret = true)
-    private String username;
+    private transient String host;
+    private transient int port;
 
-    @UriParam
-    @Metadata(required = true, secret = true)
+    @UriPath @Metadata(required = true)
+    private String node;
+    @UriParam(label = "producer")
+    private String operation;
+    @UriParam(label = "security", secret = true)
+    private String username;
+    @UriParam(label = "security", secret = true)
     private String password;
-
-    @Metadata(required = true)
-    private String host;
-
-    @Metadata(required = true)
-    private int port;
-
-    @Metadata(required = false, defaultValue = "true")
+    @Metadata(label = "consumer", defaultValue = "true")
     private boolean processSnapshot = true;
 
     private Class<FlowLogic<?>> flowLociClass;
-
     private Object [] arguments;
-
     private Class<ContractState> contractStateClass;
-
     private QueryCriteria queryCriteria;
-
     private PageSpecification pageSpecification;
-
     private Sort sort;
 
+    public void configure() {
+        try {
+            URI nodeURI = new URI(node);
+            setHost(nodeURI.getHost());
+            setPort(nodeURI.getPort());
+
+            if (nodeURI.getUserInfo() != null) {
+                String[] creds = nodeURI.getUserInfo().split(":");
+                if (getUsername() == null) {
+                    setUsername(creds[0]);
+                }
+                if (getPassword() == null) {
+                    setPassword(creds.length > 1 ? creds[1] : "");
+                }
+            }
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Invalid URI: " + node, e);
+        }
+    }
+
+    public String getNode() {
+        return node;
+    }
+
+    /**
+     * The url for the corda node
+     */
+    public void setNode(String node) {
+        this.node = node;
+    }
+
     public String getOperation() {
         return operation;
     }
 
+    /**
+     * Operation to use
+     */
     public void setOperation(String operation) {
         this.operation = operation;
     }
@@ -73,6 +100,9 @@ public class CordaConfiguration implements Cloneable {
         return username;
     }
 
+    /**
+     * Username for login
+     */
     public void setUsername(String username) {
         this.username = username;
     }
@@ -81,6 +111,9 @@ public class CordaConfiguration implements Cloneable {
         return password;
     }
 
+    /**
+     * Password for login
+     */
     public void setPassword(String password) {
         this.password = password;
     }
@@ -105,6 +138,9 @@ public class CordaConfiguration implements Cloneable {
         return processSnapshot;
     }
 
+    /**
+     * Whether to process snapshots or not
+     */
     public void setProcessSnapshot(boolean processSnapshot) {
         this.processSnapshot = processSnapshot;
     }
diff --git a/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaEndpoint.java b/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaEndpoint.java
index 4e5d3a9..a4bc810 100644
--- a/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaEndpoint.java
+++ b/components/camel-corda/src/main/java/org/apache/camel/component/corda/CordaEndpoint.java
@@ -28,42 +28,25 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.support.DefaultEndpoint;
 
 /**
- * The corda component uses the corda-rpc to interact with corda nodes.
+ * The corda component uses corda-rpc to interact with corda nodes.
  */
-@UriEndpoint(firstVersion = "2.23.0", scheme = "corda", title = "Corda", syntax = "corda:configuration", label = "corda,blockchain")
+@UriEndpoint(firstVersion = "2.23.0", scheme = "corda", title = "Corda", syntax = "corda:node", label = "corda,blockchain")
 public class CordaEndpoint extends DefaultEndpoint {
 
-    @UriPath(description = "URL to the corda node")
-    @Metadata(required = true)
+    @UriParam
     private CordaConfiguration configuration;
+
     private CordaRPCConnection rpcConnection;
     private CordaRPCOps proxy;
 
-    public CordaEndpoint(String uri, String remaining, CordaComponent component, CordaConfiguration configuration) {
+    public CordaEndpoint(String uri, CordaComponent component, CordaConfiguration configuration) {
         super(uri, component);
         this.configuration = configuration;
-
-        try {
-            URI nodeURI = new URI(uri);
-            configuration.setHost(nodeURI.getHost());
-            configuration.setPort(nodeURI.getPort());
-
-            if (nodeURI.getUserInfo() != null) {
-                String[] creds = nodeURI.getUserInfo().split(":");
-                if (configuration.getUsername() == null) {
-                    configuration.setUsername(creds[0]);
-                }
-                if (configuration.getPassword() == null) {
-                    configuration.setPassword(creds.length > 1 ? creds[1] : "");
-                }
-            }
-        } catch (URISyntaxException e) {
-            throw new IllegalArgumentException("Invalid URI: " + remaining, e);
-        }
     }
 
     @Override
@@ -78,6 +61,14 @@ public class CordaEndpoint extends DefaultEndpoint {
         return consumer;
     }
 
+    public CordaConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(CordaConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
     @Override
     protected void doStart() throws Exception {
         NetworkHostAndPort rpcAddress = new NetworkHostAndPort(configuration.getHost(), configuration.getPort());
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/CordaEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/CordaEndpointBuilderFactory.java
index 4032d48..0d4fe22 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/CordaEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/CordaEndpointBuilderFactory.java
@@ -24,7 +24,7 @@ import org.apache.camel.builder.endpoint.AbstractEndpointBuilder;
 import org.apache.camel.spi.ExceptionHandler;
 
 /**
- * The corda component uses the corda-rpc to interact with corda nodes.
+ * The corda component uses corda-rpc to interact with corda nodes.
  * 
  * Generated by camel-package-maven-plugin - do not edit this file!
  */
@@ -77,6 +77,28 @@ public interface CordaEndpointBuilderFactory {
             doSetProperty("bridgeErrorHandler", bridgeErrorHandler);
             return this;
         }
+        /**
+         * Password for login.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         */
+        default CordaEndpointConsumerBuilder password(String password) {
+            doSetProperty("password", password);
+            return this;
+        }
+        /**
+         * Username for login.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         */
+        default CordaEndpointConsumerBuilder username(String username) {
+            doSetProperty("username", username);
+            return this;
+        }
     }
 
     /**
@@ -248,6 +270,39 @@ public interface CordaEndpointBuilderFactory {
             doSetProperty("lazyStartProducer", lazyStartProducer);
             return this;
         }
+        /**
+         * Operation to use.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: producer
+         */
+        default CordaEndpointProducerBuilder operation(String operation) {
+            doSetProperty("operation", operation);
+            return this;
+        }
+        /**
+         * Password for login.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         */
+        default CordaEndpointProducerBuilder password(String password) {
+            doSetProperty("password", password);
+            return this;
+        }
+        /**
+         * Username for login.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         */
+        default CordaEndpointProducerBuilder username(String username) {
+            doSetProperty("username", username);
+            return this;
+        }
     }
 
     /**
@@ -322,6 +377,28 @@ public interface CordaEndpointBuilderFactory {
         default AdvancedCordaEndpointBuilder advanced() {
             return (AdvancedCordaEndpointBuilder) this;
         }
+        /**
+         * Password for login.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         */
+        default CordaEndpointBuilder password(String password) {
+            doSetProperty("password", password);
+            return this;
+        }
+        /**
+         * Username for login.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         */
+        default CordaEndpointBuilder username(String username) {
+            doSetProperty("username", username);
+            return this;
+        }
     }
 
     /**
@@ -386,16 +463,16 @@ public interface CordaEndpointBuilderFactory {
     }
     /**
      * Corda (camel-corda)
-     * The corda component uses the corda-rpc to interact with corda nodes.
+     * The corda component uses corda-rpc to interact with corda nodes.
      * 
      * Category: corda,blockchain
      * Since: 2.23
      * Maven coordinates: org.apache.camel:camel-corda
      * 
-     * Syntax: <code>corda:configuration</code>
+     * Syntax: <code>corda:node</code>
      * 
-     * Path parameter: configuration (required)
-     * URL to the corda node
+     * Path parameter: node (required)
+     * The url for the corda node
      */
     default CordaEndpointBuilder corda(String path) {
         class CordaEndpointBuilderImpl extends AbstractEndpointBuilder implements CordaEndpointBuilder, AdvancedCordaEndpointBuilder {
diff --git a/platforms/spring-boot/components-starter/camel-corda-starter/src/main/java/org/apache/camel/component/corda/springboot/CordaComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-corda-starter/src/main/java/org/apache/camel/component/corda/springboot/CordaComponentConfiguration.java
index 15e1cc9..2606c04 100644
--- a/platforms/spring-boot/components-starter/camel-corda-starter/src/main/java/org/apache/camel/component/corda/springboot/CordaComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-corda-starter/src/main/java/org/apache/camel/component/corda/springboot/CordaComponentConfiguration.java
@@ -24,7 +24,7 @@ import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
 /**
- * The corda component uses the corda-rpc to interact with corda nodes.
+ * The corda component uses corda-rpc to interact with corda nodes.
  * 
  * Generated by camel-package-maven-plugin - do not edit this file!
  */
@@ -40,7 +40,7 @@ public class CordaComponentConfiguration
      */
     private Boolean enabled;
     /**
-     * Default configuration
+     * To use a shared configuration.
      */
     private CordaConfigurationNestedConfiguration configuration;
     /**
@@ -104,19 +104,67 @@ public class CordaComponentConfiguration
 
     public static class CordaConfigurationNestedConfiguration {
         public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.corda.CordaConfiguration.class;
+        /**
+         * The url for the corda node
+         */
+        private String node;
+        /**
+         * Operation to use
+         */
         private String operation;
+        /**
+         * Username for login
+         */
         private String username;
+        /**
+         * Password for login
+         */
         private String password;
+        /**
+         * Password for login
+         */
         private String host;
+        /**
+         * Password for login
+         */
         private Integer port;
+        /**
+         * Whether to process snapshots or not
+         */
         private Boolean processSnapshot;
+        /**
+         * Whether to process snapshots or not
+         */
         private Class flowLociClass;
+        /**
+         * Whether to process snapshots or not
+         */
         private Object[] arguments;
+        /**
+         * Whether to process snapshots or not
+         */
         private Class contractStateClass;
+        /**
+         * Whether to process snapshots or not
+         */
         private QueryCriteria queryCriteria;
+        /**
+         * Whether to process snapshots or not
+         */
         private PageSpecification pageSpecification;
+        /**
+         * Whether to process snapshots or not
+         */
         private Sort sort;
 
+        public String getNode() {
+            return node;
+        }
+
+        public void setNode(String node) {
+            this.node = node;
+        }
+
         public String getOperation() {
             return operation;
         }