このコンテンツは選択した言語では利用できません。

Chapter 60. Language


Language

Available as of Camel 2.5
The language component allows you to send Exchange to an endpoint which executes a script by any of the supported Languages in Camel. By having a component to execute language scripts, it allows more dynamic routing capabilities. For example by using the Routing SlipRouting Slip or Dynamic RouterDynamic Router EIPs you can send messages to language endpoints where the script is dynamic defined as well.
This component is provided out of the box in camel-core and hence no additional JARs is needed. You only have to include additional Camel components if the language of choice mandates it, such as using Groovy or JavaScript languages.

URI format

language://languageName[:script][?options]

Copy to Clipboard Toggle word wrap

URI Options

The component supports the following options.
Expand
Name Default Value Type Description
languageName null String The name of the Language to use, such as simple, groovy, javascript etc. This option is mandatory.
script null String The script to execute.
transform true boolean Whether or not the result of the script should be used as the new message body. By setting to false the script is executed but the result of the script is discarded.
contentCache true boolean *Camel 2.9:* Whether to cache the script if loaded from a resource.

Message Headers

The following message headers can be used to affect the behavior of the component
Expand
Header Description
CamelLanguageScript The script to execute provided in the header. Takes precedence over script configured on the endpoint.

Examples

For example you can use the Simple language to Message TranslatorMessage Translator a message:
String script = URLEncoder.encode("Hello ${body}", "UTF-8");
from("direct:start").to("language:simple:" + script).to("mock:result");
Copy to Clipboard Toggle word wrap
In case you want to convert the message body type you can do this as well:
String script = URLEncoder.encode("${mandatoryBodyAs(String)}", "UTF-8");
from("direct:start").to("language:simple:" + script).to("mock:result");
Copy to Clipboard Toggle word wrap
You can also use the Groovy language, such as this example where the input message will by multiplied with 2:
from("direct:start").to("language:groovy:request.body * 2").to("mock:result");
Copy to Clipboard Toggle word wrap
You can also provide the script as a header as shown below. Here we use XPath language to extract the text from the <foo> tag.
Object out = producer.requestBodyAndHeader("language:xpath", "<foo>Hello World</foo>", Exchange.LANGUAGE_SCRIPT, "/foo/text()");
assertEquals("Hello World", out);
Copy to Clipboard Toggle word wrap

Loading scripts from resources

Available as of Camel 2.9
You can specify a resource uri for a script to load in either the endpoint uri, or in the Exchange.LANGUAGE_SCRIPT header. The uri must start with one of the following schemes: file:, classpath:, or http:
For example to load a script from the classpath:
from("direct:start")
    // load the script from the classpath
    .to("language:simple:classpath:org/apache/camel/component/language/mysimplescript.txt")
    .to("mock:result");
Copy to Clipboard Toggle word wrap
By default the script is loaded once and cached. However you can disable the contentCache option and have the script loaded on each evaluation. For example if the file myscript.txt is changed on disk, then the updated script is used:
from("direct:start")
    // the script will be loaded on each message, as we disabled cache
    .to("language:simple:file:target/script/myscript.txt?contentCache=false")
    .to("mock:result");
Copy to Clipboard Toggle word wrap
  • Routing SlipRouting Slip
  • Dynamic RouterDynamic Router
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat