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
commit eec9e6765563020013371d499782cac903eb748d Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Jun 8 06:53:28 2020 +0200 CAMEL-15155: camel-core - PropertyBindingSupport - Add # syntax to refer to property placeholder by id --- .../faq/pages/how-do-i-configure-endpoints.adoc | 70 ++++++++++++++++++---- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/docs/user-manual/modules/faq/pages/how-do-i-configure-endpoints.adoc b/docs/user-manual/modules/faq/pages/how-do-i-configure-endpoints.adoc index f630049..0063600 100644 --- a/docs/user-manual/modules/faq/pages/how-do-i-configure-endpoints.adoc +++ b/docs/user-manual/modules/faq/pages/how-do-i-configure-endpoints.adoc @@ -118,23 +118,47 @@ pop3://host:port?password=foo [[HowdoIconfigureendpoints-ReferringbeansfromEndpointURIs]] === Referring beans from Endpoint URIs -*Since Camel 2.0* - When configuring endpoints using URI syntax you can now refer to beans -in the Registry using the `#` notation. +in the Registry using the `#bean:id` notation. + +NOTE: The older syntax with just `#id` has been deprecated due to ambiguity +as Camel supports a number of additional functions that start with the # notation. -If the parameter value starts with a `#` sign then Camel will lookup in +If the parameter value starts with a `#bean:` sign then Camel will lookup in the Registry for a bean of the given type. For instance: [source] ---- -file://inbox?sorter=#mySpecialFileSorter +file://inbox?sorter=#bean:mySpecialFileSorter ---- Will lookup a bean with the id `mySpecialFileSorter` in the Registry. +Camel also supports to refer to beans by their class type. + +[[HowdoIconfigureendpoints-ReferringbeansbytypefromEndpointURIs]] +=== Referring beans by type from Endpoint URIs + +When configuring endpoints using URI syntax you can now refer to bean by type (class name) +using the `#type:fullyQualifiedName` notation. + +If the parameter value starts with a `#type:` sign then Camel will load the +class with the given name, and create an instanace of the bean using its _no-arg_ constructor: + +[source] +---- +file://inbox?sorter=#type:com.foo.MySpecialSorter +---- + +If you need to provide parameters to the constructor, then you should use `#class:` notation instead: + +[source] +---- +file://inbox?sorter=#class:com.foo.MySpecialSorter(10, 'Hello world', true) +---- + [[HowdoIconfigureendpoints-Configuringparametervaluesusingrawvalues,egsuchaspasswords]] === Configuring parameter values using raw values, eg such as passwords @@ -162,7 +186,7 @@ actual password would be as typed, eg `se+re?t&23`. [[HowdoIconfigureendpoints-Usingpropertyplaceholders]] === Using property placeholders -Camel have extensive support for using property placeholders, which you +Camel has extensive support for using property placeholders, which you can read more about here. For example in the ftp example above we can externalize the password to a `.properties` file. @@ -174,7 +198,7 @@ documentation for more details. [source,xml] ---- -<camelContext ...> +<camelContext> <propertyPlaceholder id="properties" location="myftp.properties"/> ... </camelContext> @@ -213,6 +237,30 @@ myFtpPassword=se+re?t&23 To understand more about property placeholders, read the documentation. +In Camel 3.4 you can use an alternative than RAW to refer to a property placeholder by its +key, as discussed in the following section. + +=== Referring to a property placeholder + +*Since Camel 3.4* + +When using `{{key}}` in configuring endpoint URIs then Camel will replace the `{{key}}` while parsing the endpoint URI. +This has its pros but also a few cons, such as when using sensitive information such as passwords. As we have seen +in the previous section you can use RAW() syntax. Instead of using RAW() you can use `#property:key` notation, +as shown in the example below: + +[source,java] +---- +.to("ftp:j...@myftpserver.com?password=#property:myFtpPassword&binary=true") +---- + +... and in XML: + +[source,xml] +---- +<to uri="ftp:j...@myftpserver.com?password=#property:myFtpPassword&binary=true"/> +---- + [[HowdoIconfigureendpoints-Configuringurisusingendpointwithbeanpropertystyle]] == Configuring URIs using endpoint with bean property style @@ -227,7 +275,7 @@ routes refer to the endpoints using their shorthand ids. [source,xml] ---- -<camelContext ...> +<camelContext> <endpoint id="foo" uri="ftp://foo@myserver"> <property key="password" value="secret"/> @@ -243,8 +291,6 @@ routes refer to the endpoints using their shorthand ids. </camelContext> ---- - - In the example above, the endpoint with id `foo`, is defined using `<endpoint>` which under the covers assembles this as an URI, with all the options, as if you have defined all the options directly in the URI. You @@ -261,8 +307,6 @@ as: </endpoint> ---- - - [[HowdoIconfigureendpoints-Configuringlongurisusingnewlines]] == Configuring long URIs using new lines @@ -286,7 +330,7 @@ shown below: </route> ---- -Notice that it still requires to use escape `&` as `&` in XML. Also you +Notice that it still requires escaping `&` as `&` in XML. Also you can have multiple options in one line, eg this is the same: [source,xml]