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

davsclaus pushed a commit to branch properties
in repository https://gitbox.apache.org/repos/asf/camel.git

commit edb3f43a299b246500e152eaf1e8394fa2d7ecec
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Jul 3 12:41:30 2019 +0200

    CAMEL-13721: Properties component - Make it simpler by removing not often 
used stuff
---
 .../src/main/docs/properties-component.adoc        |  79 +++++++++++-
 .../component/properties/PropertiesComponent.java  |  19 ++-
 .../component/properties/PropertiesEndpoint.java   |  86 +++++++++++++
 .../dsl/PropertiesEndpointBuilderFactory.java      | 141 ---------------------
 4 files changed, 174 insertions(+), 151 deletions(-)

diff --git 
a/components/camel-properties/src/main/docs/properties-component.adoc 
b/components/camel-properties/src/main/docs/properties-component.adoc
index a602d4e..f80a0b2 100644
--- a/components/camel-properties/src/main/docs/properties-component.adoc
+++ b/components/camel-properties/src/main/docs/properties-component.adoc
@@ -43,6 +43,37 @@ The Properties component supports 16 options, which are 
listed below.
 
 
 // endpoint options: START
+The Properties endpoint is configured using URI syntax:
+
+----
+properties:key
+----
+
+with the following path and query parameters:
+
+==== Path Parameters (1 parameters):
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *key* | *Required* Property key to use as placeholder |  | String
+|===
+
+
+==== Query Parameters (6 parameters):
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *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
+| *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 [...]
+| *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
+|===
 // endpoint options: END
 
 // spring-boot-auto-configure options: START
@@ -302,8 +333,9 @@ properties for the Registry.
 
 === Examples using properties component
 
-When using property placeholders in the endpoint URIs you use the placeholders
-directly in the endpoint uri using the `{{ key }}` style as shown below:
+When using property placeholders in the endpoint URIs you can either use
+the `properties:` component or define the placeholders directly in the
+URI. We will show example of both cases, starting with the former.
 
 [source,java]
 ----
@@ -311,7 +343,7 @@ directly in the endpoint uri using the `{{ key }}` style as 
shown below:
 cool.end=mock:result
 
 // route
-from("direct:start").to("{{cool.end}}");
+from("direct:start").to("properties:{{cool.end}}");
 ----
 
 You can also use placeholders as a part of the endpoint uri:
@@ -322,7 +354,7 @@ You can also use placeholders as a part of the endpoint uri:
 cool.foo=result
 
 // route
-from("direct:start").to("mock:{{cool.foo}}");
+from("direct:start").to("properties:mock:{{cool.foo}}");
 ----
 
 In the example above the to endpoint will be resolved to `mock:result`.
@@ -336,11 +368,48 @@ cool.foo=result
 cool.concat=mock:{{cool.foo}}
 
 // route
-from("direct:start").to("mock:{{cool.concat}}");
+from("direct:start").to("properties:mock:{{cool.concat}}");
 ----
 
 Notice how `cool.concat` refer to another property.
 
+=== Examples
+
+You can also use property placeholders directly in the endpoint uris
+without having to use `properties:`.
+
+[source,java]
+----
+// properties
+cool.foo=result
+
+// route
+from("direct:start").to("mock:{{cool.foo}}");
+----
+
+And you can use them in multiple wherever you want them:
+
+[source,java]
+----
+// properties
+cool.start=direct:start
+cool.showid=true
+cool.result=result
+
+// route
+from("{{cool.start}}")
+    .to("log:{{cool.start}}?showBodyType=false&showExchangeId={{cool.showid}}")
+    .to("mock:{{cool.result}}");
+----
+
+You can also your property placeholders when using
+ProducerTemplate for example:
+
+[source,java]
+----
+template.sendBody("{{cool.start}}", "Hello World");
+----
+
 === Example with xref:simple-language.adoc[Simple] language
 
 The xref:simple-language.adoc[Simple] language now also support using property
diff --git 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 53efb27..e9a3638 100644
--- 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -18,12 +18,14 @@ package org.apache.camel.component.properties;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
@@ -147,6 +149,18 @@ public class PropertiesComponent extends DefaultComponent 
implements org.apache.
         setLocations(locations);
     }
 
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+        String endpointUri = parseUri(remaining);
+        log.debug("Endpoint uri parsed as: {}", endpointUri);
+
+        Endpoint delegate = getCamelContext().getEndpoint(endpointUri);
+        PropertiesEndpoint answer = new PropertiesEndpoint(uri, delegate, 
this);
+
+        setProperties(answer, parameters);
+        return answer;
+    }
+
     public String parseUri(String uri) {
         // optimise to only load properties once as we use the configured 
locations
         if (cache) {
@@ -569,11 +583,6 @@ public class PropertiesComponent extends DefaultComponent 
implements org.apache.
         ServiceHelper.stopAndShutdownServices(locationSources, sources);
     }
 
-    @Override
-    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
-        throw new UnsupportedOperationException("Properties component does not 
support endpoints");
-    }
-
     private void addPropertiesLocationsAsPropertiesSource(PropertiesLocation 
location) {
         if ("ref".equals(location.getResolver())) {
             addPropertiesSource(new RefPropertiesSource(this, location, 
ignoreMissingLocation));
diff --git 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
new file mode 100644
index 0000000..c336e31
--- /dev/null
+++ 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
@@ -0,0 +1,86 @@
+/*
+ * 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.properties;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.DelegateEndpoint;
+import org.apache.camel.Endpoint;
+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.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
+
+/**
+ * The properties component is used for using property placeholders in 
endpoint uris.
+ */
+@UriEndpoint(firstVersion = "2.3.0", scheme = "properties", title = 
"Properties", syntax = "properties:key", label = "core,endpoint")
+public class PropertiesEndpoint extends DefaultEndpoint implements 
DelegateEndpoint {
+
+    private volatile Endpoint endpoint;
+
+    @UriPath
+    @Metadata(required = true)
+    private String key;
+
+    public PropertiesEndpoint(String endpointUri, Endpoint delegate, Component 
component) {
+        super(endpointUri, component);
+        this.endpoint = delegate;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    /**
+     * Property key to use as placeholder
+     */
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return endpoint.createProducer();
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return endpoint.createConsumer(processor);
+    }
+
+    @Override
+    public Endpoint getEndpoint() {
+        return endpoint;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        // add the endpoint as a service so Camel can manage the endpoint and 
enlist the endpoint in JMX etc.
+        getCamelContext().addService(endpoint);
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        // noop
+    }
+
+}
diff --git 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PropertiesEndpointBuilderFactory.java
 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PropertiesEndpointBuilderFactory.java
index 8c50a36..fdee497 100644
--- 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PropertiesEndpointBuilderFactory.java
+++ 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/PropertiesEndpointBuilderFactory.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.builder.endpoint.dsl;
 
-import java.util.List;
 import javax.annotation.Generated;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.builder.EndpointConsumerBuilder;
@@ -53,53 +52,6 @@ public interface PropertiesEndpointBuilderFactory {
             return this;
         }
         /**
-         * Whether to silently ignore if a location cannot be located, such as 
a
-         * properties file not found.
-         * The option is a <code>boolean</code> type.
-         * @group common
-         */
-        default PropertiesEndpointConsumerBuilder ignoreMissingLocation(
-                boolean ignoreMissingLocation) {
-            setProperty("ignoreMissingLocation", ignoreMissingLocation);
-            return this;
-        }
-        /**
-         * Whether to silently ignore if a location cannot be located, such as 
a
-         * properties file not found.
-         * The option will be converted to a <code>boolean</code> type.
-         * @group common
-         */
-        default PropertiesEndpointConsumerBuilder ignoreMissingLocation(
-                String ignoreMissingLocation) {
-            setProperty("ignoreMissingLocation", ignoreMissingLocation);
-            return this;
-        }
-        /**
-         * A list of locations to load properties. You can use comma to 
separate
-         * multiple locations. This option will override any default locations
-         * and only use the locations from this option.
-         * The option is a
-         * 
<code>java.util.List&lt;org.apache.camel.component.properties.PropertiesLocation&gt;</code>
 type.
-         * @group common
-         */
-        default PropertiesEndpointConsumerBuilder locations(
-                List<Object> locations) {
-            setProperty("locations", locations);
-            return this;
-        }
-        /**
-         * A list of locations to load properties. You can use comma to 
separate
-         * multiple locations. This option will override any default locations
-         * and only use the locations from this option.
-         * The option will be converted to a
-         * 
<code>java.util.List&lt;org.apache.camel.component.properties.PropertiesLocation&gt;</code>
 type.
-         * @group common
-         */
-        default PropertiesEndpointConsumerBuilder locations(String locations) {
-            setProperty("locations", locations);
-            return this;
-        }
-        /**
          * 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
@@ -256,53 +208,6 @@ public interface PropertiesEndpointBuilderFactory {
             return this;
         }
         /**
-         * Whether to silently ignore if a location cannot be located, such as 
a
-         * properties file not found.
-         * The option is a <code>boolean</code> type.
-         * @group common
-         */
-        default PropertiesEndpointProducerBuilder ignoreMissingLocation(
-                boolean ignoreMissingLocation) {
-            setProperty("ignoreMissingLocation", ignoreMissingLocation);
-            return this;
-        }
-        /**
-         * Whether to silently ignore if a location cannot be located, such as 
a
-         * properties file not found.
-         * The option will be converted to a <code>boolean</code> type.
-         * @group common
-         */
-        default PropertiesEndpointProducerBuilder ignoreMissingLocation(
-                String ignoreMissingLocation) {
-            setProperty("ignoreMissingLocation", ignoreMissingLocation);
-            return this;
-        }
-        /**
-         * A list of locations to load properties. You can use comma to 
separate
-         * multiple locations. This option will override any default locations
-         * and only use the locations from this option.
-         * The option is a
-         * 
<code>java.util.List&lt;org.apache.camel.component.properties.PropertiesLocation&gt;</code>
 type.
-         * @group common
-         */
-        default PropertiesEndpointProducerBuilder locations(
-                List<Object> locations) {
-            setProperty("locations", locations);
-            return this;
-        }
-        /**
-         * A list of locations to load properties. You can use comma to 
separate
-         * multiple locations. This option will override any default locations
-         * and only use the locations from this option.
-         * The option will be converted to a
-         * 
<code>java.util.List&lt;org.apache.camel.component.properties.PropertiesLocation&gt;</code>
 type.
-         * @group common
-         */
-        default PropertiesEndpointProducerBuilder locations(String locations) {
-            setProperty("locations", locations);
-            return this;
-        }
-        /**
          * 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
@@ -413,52 +318,6 @@ public interface PropertiesEndpointBuilderFactory {
             setProperty("key", key);
             return this;
         }
-        /**
-         * Whether to silently ignore if a location cannot be located, such as 
a
-         * properties file not found.
-         * The option is a <code>boolean</code> type.
-         * @group common
-         */
-        default PropertiesEndpointBuilder ignoreMissingLocation(
-                boolean ignoreMissingLocation) {
-            setProperty("ignoreMissingLocation", ignoreMissingLocation);
-            return this;
-        }
-        /**
-         * Whether to silently ignore if a location cannot be located, such as 
a
-         * properties file not found.
-         * The option will be converted to a <code>boolean</code> type.
-         * @group common
-         */
-        default PropertiesEndpointBuilder ignoreMissingLocation(
-                String ignoreMissingLocation) {
-            setProperty("ignoreMissingLocation", ignoreMissingLocation);
-            return this;
-        }
-        /**
-         * A list of locations to load properties. You can use comma to 
separate
-         * multiple locations. This option will override any default locations
-         * and only use the locations from this option.
-         * The option is a
-         * 
<code>java.util.List&lt;org.apache.camel.component.properties.PropertiesLocation&gt;</code>
 type.
-         * @group common
-         */
-        default PropertiesEndpointBuilder locations(List<Object> locations) {
-            setProperty("locations", locations);
-            return this;
-        }
-        /**
-         * A list of locations to load properties. You can use comma to 
separate
-         * multiple locations. This option will override any default locations
-         * and only use the locations from this option.
-         * The option will be converted to a
-         * 
<code>java.util.List&lt;org.apache.camel.component.properties.PropertiesLocation&gt;</code>
 type.
-         * @group common
-         */
-        default PropertiesEndpointBuilder locations(String locations) {
-            setProperty("locations", locations);
-            return this;
-        }
     }
 
     /**

Reply via email to