This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6e338d4 CAMEL-17647: camel-core - Properties component should support
pluggable functions
6e338d4 is described below
commit 6e338d4c3d7cb1c28e90b74279cd47dffbcab130
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Feb 15 11:51:55 2022 +0100
CAMEL-17647: camel-core - Properties component should support pluggable
functions
---
.../ROOT/pages/using-propertyplaceholder.adoc | 63 ++++------------------
1 file changed, 10 insertions(+), 53 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
b/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
index 2ffee01..d7410ac 100644
--- a/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
+++ b/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
@@ -502,35 +502,22 @@ The
xref:components::properties-component.adoc[Properties] component allow to pl
These functions are then able to do custom logic to resolve the placeholders,
such as looking up in databases, do custom computations, or whatnot.
The name of the function becomes the prefix used in the placeholder.
-This is best illustrated in the example code below with Spring XML files:
+This is best illustrated in the example route below, where we use `beer` as
the prefix:
[source,xml]
----
-<beans>
- <bean id="beerFunction" class="MyBeerFunction"/>
-
- <camelContext>
- <propertyPlaceholder id="properties">
- <propertiesFunction ref="beerFunction"/>
- </propertyPlaceholder>
-
- <route>
- <from uri="direct:start"/>
- <to uri="{{beer:FOO}}"/>
- <to uri="{{beer:BAR}}"/>
- </route>
- </camelContext>
-</beans>
+<route>
+ <from uri="direct:start"/>
+ <to uri="{{beer:FOO}}"/>
+ <to uri="{{beer:BAR}}"/>
+</route>
----
-Here we have a Camel Spring XML route where we have defined the
-`<propertyPlaceholder>` to use a custom function, which we refer to be the
bean id (`beerFunction`).
-As the beer function uses `"beer"` as its name, then the placeholder syntax
can trigger the beer function by starting with `beer:value`.
-
The implementation of the function is only two methods as shown below:
[source,java]
----
[email protected]("beer")
public class MyBeerFunction implements PropertiesFunction {
@Override
@@ -550,39 +537,9 @@ The method `getName` is the name of the function (beer).
And the `apply` method is where we implement the custom logic to do.
As the sample code is from a unit test, it just returns a value to refer to a
mock endpoint.
-To register a custom function from Java code is as shown below:
-
-[source,java]
-----
-PropertiesComponent pc = context.getPropertiesComponent();
-pc.addFunction(new MyBeerFunction());
-----
-
-==== Pluggable custom properties functions
-
-If you want custom properties functions to be easier to use then we recommend
making them pluggable.
-For example the beer function from above, can be made pluggable simply by
adding the `PropertiesFunction` annotations as shown:
-
-[source,java]
-----
[email protected]("beer")
-public class MyBeerFunction implements PropertiesFunction {
-
- @Override
- public String getName() {
- return "beer";
- }
-
- @Override
- public String apply(String remainder) {
- return "mock:" + remainder.toLowerCase();
- }
-}
-----
-
-Then by having the `camel-component-maven-plugin` as part of building the
component will
-then ensure that this custom properties has necessary source code generated
that makes Camel
-able to automatically discover the custom function.
+You also need to have `camel-component-maven-plugin` as part of building the
component will
+then ensure that this custom properties function has necessary source code
generated that makes Camel
+able to automatically discover the function.
TIP: For an example see the `camel-base64` component.