gnodet-bot commented on code in PR #29873:
URL: https://github.com/apache/camel/pull/29873#discussion_r4565859761


##########
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

Review Comment:
   ⚠️ **Misleading comment:** The comment says "always stopped after use", but 
`compiled || !getEndpoint().isCacheScript()` evaluates to `false` when the 
header carries a user-supplied `Expression` object (`compiled=false`) and 
`cacheScript=true` — in that case the expression is **not** stopped. The 
comment is accurate only for the String-script case.
   
   Consider narrowing it:
   ```suggestion
           // expressions compiled from the string script are stopped after use 
(they are never cached)
   ```



-- 
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