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 6f7d1686f01 CAMEL-21600: camel-ognl - Workaround for ognl 3.4.5 issue
6f7d1686f01 is described below

commit 6f7d1686f01c505a96d1a9a479e826245db7cd22
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Jan 8 07:58:50 2025 +0100

    CAMEL-21600: camel-ognl - Workaround for ognl 3.4.5 issue
---
 .../apache/camel/language/ognl/OgnlExpression.java |  2 +-
 .../org/apache/camel/language/ognl/OgnlHelper.java | 37 ++++++++++++++++++++++
 .../apache/camel/language/ognl/OgnlLanguage.java   |  2 +-
 parent/pom.xml                                     |  2 +-
 4 files changed, 40 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java
 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java
index a359b87e961..635477f4137 100644
--- 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java
+++ 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlExpression.java
@@ -54,7 +54,7 @@ public class OgnlExpression extends ExpressionSupport {
         RootObject root = new RootObject(exchange);
         OgnlContext oglContext = Ognl.createDefaultContext(root, cr);
         try {
-            Object value = Ognl.getValue(expression, oglContext, root);
+            Object value = OgnlHelper.getValue(expression, oglContext, root);
             return exchange.getContext().getTypeConverter().convertTo(tClass, 
value);
         } catch (OgnlException e) {
             throw new ExpressionEvaluationException(this, exchange, e);
diff --git 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlHelper.java
 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlHelper.java
new file mode 100644
index 00000000000..2e991ce31fa
--- /dev/null
+++ 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlHelper.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.camel.language.ognl;
+
+import ognl.Node;
+import ognl.OgnlContext;
+import ognl.OgnlException;
+
+public final class OgnlHelper {
+
+    private OgnlHelper() {
+    }
+
+    public static Object getValue(Object expression, OgnlContext ognlContext, 
Object root) throws OgnlException {
+        // workaround bug in ognl 3.4.5
+        Node node = (Node) expression;
+        if (node.getAccessor() != null) {
+            return node.getAccessor().get(ognlContext, root);
+        } else {
+            return node.getValue(ognlContext, root);
+        }
+    }
+}
diff --git 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java
 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java
index 0ceb31c9ca0..10bcc3ebe52 100644
--- 
a/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java
+++ 
b/components/camel-ognl/src/main/java/org/apache/camel/language/ognl/OgnlLanguage.java
@@ -52,7 +52,7 @@ public class OgnlLanguage extends TypedLanguageSupport 
implements ScriptingLangu
             Object compiled = Ognl.parseExpression(script);
             ClassResolver cr = new 
CamelClassResolver(getCamelContext().getClassResolver());
             OgnlContext oglContext = Ognl.createDefaultContext(null, cr);
-            Object value = Ognl.getValue(compiled, oglContext, bindings);
+            Object value = OgnlHelper.getValue(compiled, oglContext, bindings);
             return getCamelContext().getTypeConverter().convertTo(resultType, 
value);
         } catch (Exception e) {
             throw new ExpressionIllegalSyntaxException(script, e);
diff --git a/parent/pom.xml b/parent/pom.xml
index aa9c09fdde6..f21ccfbfdb0 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -386,7 +386,7 @@
         <nitrite-version>3.4.4</nitrite-version>
         <olingo2-version>2.0.13</olingo2-version>
         <olingo4-version>5.0.0</olingo4-version>
-        <ognl-version>3.4.4</ognl-version>
+        <ognl-version>3.4.5</ognl-version>
         <openapi-generator-version>7.10.0</openapi-generator-version>
         <openjpa-version>4.0.1</openjpa-version>
         <opensearch-rest-client-version>2.18.0</opensearch-rest-client-version>

Reply via email to