davsclaus commented on code in PR #29875:
URL: https://github.com/apache/camel/pull/29875#discussion_r4573199319


##########
components/camel-language/src/main/java/org/apache/camel/component/language/LanguageProducer.java:
##########
@@ -135,6 +117,52 @@ public void process(Exchange exchange) throws Exception {
         }
     }
 
+    /**
+     * Evaluates the script of the {@link LanguageConstants#LANGUAGE_SCRIPT} 
header, if there is one. The script is for
+     * this exchange only: it is compiled once, never cached as the script of 
the endpoint, and the header is removed so
+     * a later language endpoint does not run it again.
+     *
+     * @return true if the header had a script, false to use the script of the 
endpoint
+     */
+    private boolean processHeaderScript(Exchange exchange) throws Exception {
+        Expression exp = 
exchange.getIn().getHeader(LanguageConstants.LANGUAGE_SCRIPT, Expression.class);
+        boolean compiled = false;
+        if (exp == null) {
+            String script = 
exchange.getIn().getHeader(LanguageConstants.LANGUAGE_SCRIPT, String.class);
+            if (script == null) {
+                return false;
+            }
+            // the script may be a file: so resolve it before using
+            script = getEndpoint().resolveScript(script);
+            Class<?> type = resultType != Object.class ? resultType : null;
+            exp = getEndpoint().getLanguage().createExpression(script, new 
Object[] { type });
+            exp.init(getEndpoint().getCamelContext());
+            compiled = true;
+        }
+        exchange.getIn().removeHeader(LanguageConstants.LANGUAGE_SCRIPT);
+
+        // the expression compiled from the script is used once, so it is 
always stopped after use
+        Object result = evaluate(exchange, exp, compiled || 
!getEndpoint().isCacheScript());

Review Comment:
   This is a backport, so the code and the comment are kept the same as on main 
(#29751, `LanguageProducer.java:152`). The comment is about the expression 
compiled from a String script; an `Expression` object from the header keeps 
honouring `cacheScript`, as you say. Any rewording belongs on main, not in the 
backport.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to