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 1508cd2  CAMEL-16861: Polished ognl language
1508cd2 is described below

commit 1508cd221118a20b34221ed85c9459627834aaa3
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Sep 14 09:52:09 2021 +0200

    CAMEL-16861: Polished ognl language
---
 .../camel-mvel/src/main/docs/mvel-language.adoc    |  4 +-
 .../camel-ognl/src/main/docs/ognl-language.adoc    | 99 ++++++++++------------
 .../org/apache/camel/language/ognl/RootObject.java | 14 +++
 .../camel-ognl/src/test/resources/jndi.properties  | 18 ----
 4 files changed, 62 insertions(+), 73 deletions(-)

diff --git a/components/camel-mvel/src/main/docs/mvel-language.adoc 
b/components/camel-mvel/src/main/docs/mvel-language.adoc
index d9742bf..e315ff0 100644
--- a/components/camel-mvel/src/main/docs/mvel-language.adoc
+++ b/components/camel-mvel/src/main/docs/mvel-language.adoc
@@ -24,14 +24,14 @@ you can construct the syntax as follows:
 
 [source,text]
 ----
-message.body.familyName
+request.body.familyName
 ----
 
 Or use similar syntax as in Java:
 
 [source,java]
 ----
-getMessage().getBody().getFamilyName()
+getRequest().getBody().getFamilyName()
 ----
 
 == MVEL Options
diff --git a/components/camel-ognl/src/main/docs/ognl-language.adoc 
b/components/camel-ognl/src/main/docs/ognl-language.adoc
index 278b371..76c622c 100644
--- a/components/camel-ognl/src/main/docs/ognl-language.adoc
+++ b/components/camel-ognl/src/main/docs/ognl-language.adoc
@@ -9,26 +9,28 @@ 
include::{cq-version}@camel-quarkus:ROOT:partial$reference/languages/ognl.adoc[o
 
 *Since Camel {since}*
 
-Camel allows http://commons.apache.org/proper/commons-ognl/[OGNL] to be
-used as an Expression or
-Predicate the DSL or
-Xml Configuration.
+Camel allows http://commons.apache.org/proper/commons-ognl/[OGNL] (Apache 
Commons OGNL) to be
+used as an xref:manual::expression.adoc[Expression] or 
xref:manual::predicate.adoc[Predicate]
+in Camel routes.
 
-You could use OGNL to create an Predicate in a
-Message Filter or as an
-Expression for a
-Recipient List
+For example, you can use MVEL in a xref:manual::predicate.adoc[Predicate]
+with the xref:{eip-vc}:eips:choice-eip.adoc[Content Based Router] EIP.
 
 You can use OGNL dot notation to invoke operations. If you for instance
 have a body that contains a POJO that has a `getFamilyName` method then
 you can construct the syntax as follows:
 
+[source,text]
+----
+request.body.familyName
+----
+
+Or use similar syntax as in Java:
+
 [source,java]
-----------------------------------------
-"request.body.familyName"
-   // or 
-"getRequest().getBody().getFamilyName()"
-----------------------------------------
+----
+getRequest().getBody().getFamilyName()
+----
 
 == OGNL Options
 
@@ -53,35 +55,37 @@ The OGNL language supports 1 options, which are listed 
below.
 [width="100%",cols="10%,10%,80%",options="header",]
 |=======================================================================
 |Variable |Type |Description
-
 |*this* |Exchange |the Exchange is the root object
-
-|exchange |Exchange |the Exchange object
-
-|exception |Throwable |the Exchange exception (if any)
-
+|context |CamelContext |the CamelContext
+|exchange |Exchange |the Exchange
 |exchangeId |String |the exchange id
-
-|fault |Message |the Fault message (if any)
-
-|request |Message |the exchange.in message
-
-|response |Message |the exchange.out message (if any)
-
+|exception |Throwable |the Exchange exception (if any)
+|request |Message |the message
+|message |Message |the message
+|headers |Map |the message headers
+|header(name) |Object |the message header by the given name
+|header(name, type) |Type |the message header by the given name as the given 
type
 |properties |Map |the exchange properties
-
-|property(name) |Object |the property by the given name
-
-|property(name, type) |Type |the property by the given name as the given type
+|property(name) |Object |the exchange property by the given name
+|property(name, type) |Type |the exchange property by the given name as the 
given type
 |=======================================================================
 
-== Samples
+== Example
 
-For example you could use OGNL inside a 
xref:{eip-vc}:eips:filter-eip.adoc[Message
-Filter] in XML
+For example, you could use OGNL inside a 
xref:{eip-vc}:eips:filter-eip.adoc[Message
+Filter]
 
 [source,java]
----------------------------------------------
+----
+from("seda:foo")
+  .filter().ognl("request.headers.foo == 'bar'")
+    .to("seda:bar");
+----
+
+And in XML:
+
+[source,xml]
+----
 <route>
   <from uri="seda:foo"/>
   <filter>
@@ -89,39 +93,31 @@ Filter] in XML
     <to uri="seda:bar"/>
   </filter>
 </route>
----------------------------------------------
+----
 
-And the sample using Java DSL:
-
-[source,java]
----------------------------------------------------------------------------------
-from("seda:foo").filter().ognl("request.headers.foo == 'bar'").to("seda:bar");
----------------------------------------------------------------------------------
 
 == Loading script from external resource
 
-*Since Camel 2.11*
-
 You can externalize the script and have Camel load it from a resource
-such as `"classpath:"`, `"file:"`, or `"http:"`. +
- This is done using the following syntax: `"resource:scheme:location"`,
-eg to refer to a file on the classpath you can do:
+such as `"classpath:"`, `"file:"`, or `"http:"`.
+This is done using the following syntax: `"resource:scheme:location"`,
+e.g. to refer to a file on the classpath you can do:
 
 [source,java]
-------------------------------------------------------------
+----
 .setHeader("myHeader").ognl("resource:classpath:myognl.txt")
-------------------------------------------------------------
+----
 
 == Dependencies
 
-To use OGNL in your camel routes you need to add the a dependency on
+To use OGNL in your camel routes you need to add the dependency on
 *camel-ognl* which implements the OGNL language.
 
 If you use maven you could just add the following to your pom.xml,
 substituting the version number for the latest & greatest release (see
 the download page for the latest versions).
 
-[source,java]
+[source,xml]
 -------------------------------------
 <dependency>
   <groupId>org.apache.camel</groupId>
@@ -130,7 +126,4 @@ the download page for the latest versions).
 </dependency>
 -------------------------------------
 
-Otherwise, you'll also need
-https://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.ognl/2.7.3_4/org.apache.servicemix.bundles.ognl-2.7.3_4.jar[OGNL]
-
 include::{page-component-version}@camel-spring-boot::page$ognl-starter.adoc[]
diff --git 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java
 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java
index 24ad5fe..f1ba172 100644
--- 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java
+++ 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/RootObject.java
@@ -49,6 +49,7 @@ public class RootObject {
         return exchange.getIn();
     }
 
+    @Deprecated
     public Message getResponse() {
         return exchange.getOut();
     }
@@ -64,4 +65,17 @@ public class RootObject {
     public <T> T getProperty(String name, Class<T> type) {
         return exchange.getProperty(name, type);
     }
+
+    public Map<String, Object> getHeaders() {
+        return exchange.getMessage().getHeaders();
+    }
+
+    public Object getHeader(String name) {
+        return exchange.getMessage().getHeader(name);
+    }
+
+    public <T> T getHeader(String name, Class<T> type) {
+        return exchange.getMessage().getHeader(name, type);
+    }
+
 }
diff --git a/components/camel-ognl/src/test/resources/jndi.properties 
b/components/camel-ognl/src/test/resources/jndi.properties
deleted file mode 100644
index 7675797..0000000
--- a/components/camel-ognl/src/test/resources/jndi.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-
-java.naming.factory.initial = 
org.apache.camel.support.jndi.CamelInitialContextFactory

Reply via email to