Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How

...

to use a dynamic URI in

...

I want to use a dynamic URI when sending to an endpoint. How do I do that?
For example where the template name is dynamic as shown below:

to()

A dynamic URI is an endpoint URI that varies depending on inflight routing information, such as Exchange properties, message headers, the body, the Camel Context, etc.

For example, if you're using a Freemarker producer and the template location is provided inside the current message, you might expect the following code to work, but it will not.

Warning
titleThis is not valid code

This snippet is not valid code. Read on.

Code Block
.
Code Block

to("freemarker://templateHome/${body.templateName}.ftl")

Use the Recipient List EIP pattern, which allows you to compute the In this case, you must use an EIP (Enterprise Integration Pattern) that is capable of computing a dynamic URI using an Expressionan Expression, such as the Recipient List EIP pattern.

For example using , rewriting the snippet above to use the Simple expression language as shown below::

Tip
titleThis is valid code

This snippet is valid code.

Code Block
.
Code Block

recipientList(simple("freemarker://templateHome/${body.templateName}.ftl"))

Or you could use any other of the other Camel Languages.