VYPR
Moderate severityNVD Advisory· Published Oct 4, 2013· Updated Apr 29, 2026

CVE-2013-4330

CVE-2013-4330

Description

Apache Camel before 2.9.7, 2.10.0 before 2.10.7, 2.11.0 before 2.11.2, and 2.12.0 allows remote attackers to execute arbitrary simple language expressions by including "$simple{}" in a CamelFileName message header to a (1) FILE or (2) FTP producer.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
org.apache.camel:camel-coreMaven
< 2.9.72.9.7
org.apache.camel:camel-coreMaven
>= 2.10.0, < 2.10.72.10.7
org.apache.camel:camel-coreMaven
>= 2.11.0, < 2.11.22.11.2
org.apache.camel:camel-coreMaven
>= 2.12.0, < 2.12.12.12.1

Affected products

51
  • Apache/Camel51 versions
    cpe:2.3:a:apache:camel:*:*:*:*:*:*:*:*+ 50 more
    • cpe:2.3:a:apache:camel:*:*:*:*:*:*:*:*range: <=2.9.6
    • cpe:2.3:a:apache:camel:1.0.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.1.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.2.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.3.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.4.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.5.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.6.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.6.1:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.6.2:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.6.3:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:1.6.4:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.0.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.0.0:milestone1:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.0.0:milestone2:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.0.0:milestone3:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.1.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.1:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.2:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.3:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.4:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.5:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.10.6:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.11.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.11.1:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.12.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.2.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.3.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.4.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.5.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.6.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.7.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.7.1:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.7.2:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.7.3:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.7.4:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.7.5:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.1:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.2:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.3:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.4:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.5:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.8.6:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.9.0:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.9.1:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.9.2:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.9.3:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.9.4:*:*:*:*:*:*:*
    • cpe:2.3:a:apache:camel:2.9.5:*:*:*:*:*:*:*

Patches

5
2281b1f365c5

CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for the patch.

https://github.com/apache/camelClaus IbsenSep 15, 2013via ghsa
5 files changed · +36 83
  • camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java+24 13 modified
    @@ -286,30 +286,41 @@ public String createFileName(Exchange exchange) {
             String answer;
     
             // overrule takes precedence
    -        String overrule = exchange.getIn().getHeader(Exchange.OVERRULE_FILE_NAME, String.class);
    -        String consumed = exchange.getIn().getHeader(Exchange.FILE_NAME_CONSUMED, String.class);
    -        String name = overrule == null ? exchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : overrule;
    +        Object value;
    +
    +        Object overrule = exchange.getIn().getHeader(Exchange.OVERRULE_FILE_NAME);
    +        if (overrule != null) {
    +            if (overrule instanceof Expression) {
    +                value = overrule;
    +            } else {
    +                value = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, overrule);
    +            }
    +        } else {
    +            value = exchange.getIn().getHeader(Exchange.FILE_NAME);
    +        }
     
             // if we have an overrule then override the existing header to use the overrule computed name from this point forward
             if (overrule != null) {
    -            exchange.getIn().setHeader(Exchange.FILE_NAME, name);
    +            exchange.getIn().setHeader(Exchange.FILE_NAME, value);
    +        }
    +
    +        if (value != null && value instanceof String && StringHelper.hasStartToken((String) value, "simple")) {
    +            log.warn("Simple expression: {} detected in header: {} of type String. This feature has been removed (see CAMEL-6748).", value, Exchange.FILE_NAME);
             }
     
             // expression support
             Expression expression = endpoint.getFileName();
    -
    -        if (name != null && !name.equals(consumed)) {
    -            // the header name can be an expression too, that should override
    -            // whatever configured on the endpoint
    -            if (StringHelper.hasStartToken(name, "simple")) {
    -                log.trace("{} contains a Simple expression: {}", Exchange.FILE_NAME, name);
    -                Language language = getEndpoint().getCamelContext().resolveLanguage("file");
    -                expression = language.createExpression(name);
    -            }
    +        if (value != null && value instanceof Expression) {
    +            expression = (Expression) value;
             }
    +
    +        // evaluate the name as a String from the value
    +        String name;
             if (expression != null) {
                 log.trace("Filename evaluated as expression: {}", expression);
                 name = expression.evaluate(exchange, String.class);
    +        } else {
    +            name = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value);
             }
     
             // flatten name
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java+3 1 modified
    @@ -22,6 +22,8 @@
     import org.apache.camel.component.mock.MockEndpoint;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file consumer.
      */
    @@ -70,7 +72,7 @@ public void configure() throws Exception {
         public void testConsumeFileBasedOnDatePattern() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage/date", "Bye World", Exchange.FILE_NAME, "myfile-20081128.txt");
             template.sendBodyAndHeader("file://target/filelanguage/date", "Hello World", Exchange.FILE_NAME, "myfile-20081129.txt");
    -        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             context.addRoutes(new RouteBuilder() {
                 @Override
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java+0 62 removed
    @@ -1,62 +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.
    - */
    -package org.apache.camel.component.file;
    -
    -import java.text.SimpleDateFormat;
    -import java.util.Date;
    -import java.util.Map;
    -import java.util.TreeMap;
    -
    -import org.apache.camel.ContextTestSupport;
    -import org.apache.camel.Exchange;
    -
    -/**
    - * @version
    - */
    -public class FileProducerConsumedFileNameEvaluationTest extends ContextTestSupport {
    -
    -    @Override
    -    protected void setUp() throws Exception {
    -        deleteDirectory("target/producerconsumedfilename");
    -        super.setUp();
    -    }
    -
    -    public void testFileNameNotEvaluatedWhenMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-${date:now:yyyyMMdd}");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        assertFileExists("target/producerconsumedfilename/file-${date:now:yyyyMMdd}");
    -    }
    -
    -    public void testFileNameEvaluatedWhenNotMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-consumed");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -
    -    public void testFileNameEvaluatedWhenConsumedNull() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -}
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java+6 6 modified
    @@ -24,6 +24,8 @@
     import org.apache.camel.Exchange;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file producer.
      */
    @@ -42,11 +44,9 @@ protected JndiRegistry createRegistry() throws Exception {
             return jndi;
         }
     
    -    public void testProduceBeanByHeader() throws Exception {
    -        template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "${bean:myguidgenerator}.bak");
    -
    -        assertFileExists("target/filelanguage/123.bak");
    +    public void testProducerFileNameHeaderNotEvaluated() {
    +        template.sendBodyAndHeader("file://target/filelanguage", "Hello World", Exchange.FILE_NAME, "$simple{myfile-${date:now:yyyyMMdd}}.txt");
    +        assertFileExists("target/filelanguage/$simple{myfile-${date:now:yyyyMMdd}}.txt");
         }
     
         public void testProduceBeanByExpression() throws Exception {
    @@ -57,7 +57,7 @@ public void testProduceBeanByExpression() throws Exception {
     
         public void testProducerDateByHeader() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +            Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
             assertFileExists("target/filelanguage/myfile-" + date + ".txt");
    
  • components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java+3 1 modified
    @@ -32,6 +32,8 @@
     import org.junit.After;
     import org.junit.Before;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Base class for unit testing using a FTPServer
      */
    @@ -125,7 +127,7 @@ protected FtpServerFactory createFtpServerFactory() throws Exception {
         }
         
         public void sendFile(String url, Object body, String fileName) {
    -        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, fileName);
    +        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, simple(fileName));
         }
         
     }
    
27a9752a565f

CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for the patch.

https://github.com/apache/camelClaus IbsenSep 15, 2013via ghsa
5 files changed · +24 80
  • camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java+12 10 modified
    @@ -257,23 +257,25 @@ public void writeFile(Exchange exchange, String fileName) throws GenericFileOper
         public String createFileName(Exchange exchange) {
             String answer;
     
    -        String name = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
    -        String consumed = exchange.getIn().getHeader(Exchange.FILE_NAME_CONSUMED, String.class);
    +        Object value = exchange.getIn().getHeader(Exchange.FILE_NAME);
    +
    +        if (value != null && value instanceof String && StringHelper.hasStartToken((String) value, "simple")) {
    +            log.warn("Simple expression: {} detected in header: {} of type String. This feature has been removed (see CAMEL-6748).", value, Exchange.FILE_NAME);
    +        }
     
             // expression support
             Expression expression = endpoint.getFileName();
    -        if (name != null && !name.equals(consumed)) {
    -            // the header name can be an expression too, that should override
    -            // whatever configured on the endpoint
    -            if (StringHelper.hasStartToken(name, "simple")) {
    -                log.trace("{} contains a Simple expression: {}", Exchange.FILE_NAME, name);
    -                Language language = getEndpoint().getCamelContext().resolveLanguage("file");
    -                expression = language.createExpression(name);
    -            }
    +        if (value != null && value instanceof Expression) {
    +            expression = (Expression) value;
             }
    +
    +        // evaluate the name as a String from the value
    +        String name;
             if (expression != null) {
                 log.trace("Filename evaluated as expression: {}", expression);
                 name = expression.evaluate(exchange, String.class);
    +        } else {
    +            name = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value);
             }
     
             // flatten name
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java+3 1 modified
    @@ -22,6 +22,8 @@
     import org.apache.camel.component.mock.MockEndpoint;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file consumer.
      */
    @@ -70,7 +72,7 @@ public void configure() throws Exception {
         public void testConsumeFileBasedOnDatePattern() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage/date", "Bye World", Exchange.FILE_NAME, "myfile-20081128.txt");
             template.sendBodyAndHeader("file://target/filelanguage/date", "Hello World", Exchange.FILE_NAME, "myfile-20081129.txt");
    -        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             context.addRoutes(new RouteBuilder() {
                 @Override
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java+0 62 removed
    @@ -1,62 +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.
    - */
    -package org.apache.camel.component.file;
    -
    -import java.text.SimpleDateFormat;
    -import java.util.Date;
    -import java.util.Map;
    -import java.util.TreeMap;
    -
    -import org.apache.camel.ContextTestSupport;
    -import org.apache.camel.Exchange;
    -
    -/**
    - * @version
    - */
    -public class FileProducerConsumedFileNameEvaluationTest extends ContextTestSupport {
    -
    -    @Override
    -    protected void setUp() throws Exception {
    -        deleteDirectory("target/producerconsumedfilename");
    -        super.setUp();
    -    }
    -
    -    public void testFileNameNotEvaluatedWhenMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-${date:now:yyyyMMdd}");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        assertFileExists("target/producerconsumedfilename/file-${date:now:yyyyMMdd}");
    -    }
    -
    -    public void testFileNameEvaluatedWhenNotMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-consumed");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -
    -    public void testFileNameEvaluatedWhenConsumedNull() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -}
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java+6 6 modified
    @@ -25,6 +25,8 @@
     import org.apache.camel.Exchange;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file producer.
      */
    @@ -43,11 +45,9 @@ protected JndiRegistry createRegistry() throws Exception {
             return jndi;
         }
     
    -    public void testProduceBeanByHeader() throws Exception {
    -        template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "${bean:myguidgenerator}.bak");
    -
    -        assertFileExists("target/filelanguage/123.bak");
    +    public void testProducerFileNameHeaderNotEvaluated() {
    +        template.sendBodyAndHeader("file://target/filelanguage", "Hello World", Exchange.FILE_NAME, "$simple{myfile-${date:now:yyyyMMdd}}.txt");
    +        assertFileExists("target/filelanguage/$simple{myfile-${date:now:yyyyMMdd}}.txt");
         }
     
         public void testProduceBeanByExpression() throws Exception {
    @@ -58,7 +58,7 @@ public void testProduceBeanByExpression() throws Exception {
     
         public void testProducerDateByHeader() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +            Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
             assertFileExists("target/filelanguage/myfile-" + date + ".txt");
    
  • components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java+3 1 modified
    @@ -32,6 +32,8 @@
     import org.junit.After;
     import org.junit.Before;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Base class for unit testing using a FTPServer
      */
    @@ -127,7 +129,7 @@ protected FtpServerFactory createFtpServerFactory() throws Exception {
         }
         
         public void sendFile(String url, Object body, String fileName) {
    -        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, fileName);
    +        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, simple(fileName));
         }
         
     }
    
5ba8f63f78f8

CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for the patch.

https://github.com/apache/camelClaus IbsenSep 15, 2013via ghsa
5 files changed · +36 83
  • camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java+24 13 modified
    @@ -286,30 +286,41 @@ public String createFileName(Exchange exchange) {
             String answer;
     
             // overrule takes precedence
    -        String overrule = exchange.getIn().getHeader(Exchange.OVERRULE_FILE_NAME, String.class);
    -        String consumed = exchange.getIn().getHeader(Exchange.FILE_NAME_CONSUMED, String.class);
    -        String name = overrule == null ? exchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : overrule;
    +        Object value;
    +
    +        Object overrule = exchange.getIn().getHeader(Exchange.OVERRULE_FILE_NAME);
    +        if (overrule != null) {
    +            if (overrule instanceof Expression) {
    +                value = overrule;
    +            } else {
    +                value = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, overrule);
    +            }
    +        } else {
    +            value = exchange.getIn().getHeader(Exchange.FILE_NAME);
    +        }
     
             // if we have an overrule then override the existing header to use the overrule computed name from this point forward
             if (overrule != null) {
    -            exchange.getIn().setHeader(Exchange.FILE_NAME, name);
    +            exchange.getIn().setHeader(Exchange.FILE_NAME, value);
    +        }
    +
    +        if (value != null && value instanceof String && StringHelper.hasStartToken((String) value, "simple")) {
    +            log.warn("Simple expression: {} detected in header: {} of type String. This feature has been removed (see CAMEL-6748).", value, Exchange.FILE_NAME);
             }
     
             // expression support
             Expression expression = endpoint.getFileName();
    -
    -        if (name != null && !name.equals(consumed)) {
    -            // the header name can be an expression too, that should override
    -            // whatever configured on the endpoint
    -            if (StringHelper.hasStartToken(name, "simple")) {
    -                log.trace("{} contains a Simple expression: {}", Exchange.FILE_NAME, name);
    -                Language language = getEndpoint().getCamelContext().resolveLanguage("file");
    -                expression = language.createExpression(name);
    -            }
    +        if (value != null && value instanceof Expression) {
    +            expression = (Expression) value;
             }
    +
    +        // evaluate the name as a String from the value
    +        String name;
             if (expression != null) {
                 log.trace("Filename evaluated as expression: {}", expression);
                 name = expression.evaluate(exchange, String.class);
    +        } else {
    +            name = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value);
             }
     
             // flatten name
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java+3 1 modified
    @@ -22,6 +22,8 @@
     import org.apache.camel.component.mock.MockEndpoint;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file consumer.
      */
    @@ -70,7 +72,7 @@ public void configure() throws Exception {
         public void testConsumeFileBasedOnDatePattern() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage/date", "Bye World", Exchange.FILE_NAME, "myfile-20081128.txt");
             template.sendBodyAndHeader("file://target/filelanguage/date", "Hello World", Exchange.FILE_NAME, "myfile-20081129.txt");
    -        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             context.addRoutes(new RouteBuilder() {
                 @Override
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java+0 62 removed
    @@ -1,62 +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.
    - */
    -package org.apache.camel.component.file;
    -
    -import java.text.SimpleDateFormat;
    -import java.util.Date;
    -import java.util.Map;
    -import java.util.TreeMap;
    -
    -import org.apache.camel.ContextTestSupport;
    -import org.apache.camel.Exchange;
    -
    -/**
    - * @version
    - */
    -public class FileProducerConsumedFileNameEvaluationTest extends ContextTestSupport {
    -
    -    @Override
    -    protected void setUp() throws Exception {
    -        deleteDirectory("target/producerconsumedfilename");
    -        super.setUp();
    -    }
    -
    -    public void testFileNameNotEvaluatedWhenMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-${date:now:yyyyMMdd}");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        assertFileExists("target/producerconsumedfilename/file-${date:now:yyyyMMdd}");
    -    }
    -
    -    public void testFileNameEvaluatedWhenNotMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-consumed");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -
    -    public void testFileNameEvaluatedWhenConsumedNull() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -}
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java+6 6 modified
    @@ -24,6 +24,8 @@
     import org.apache.camel.Exchange;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file producer.
      */
    @@ -42,11 +44,9 @@ protected JndiRegistry createRegistry() throws Exception {
             return jndi;
         }
     
    -    public void testProduceBeanByHeader() throws Exception {
    -        template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "${bean:myguidgenerator}.bak");
    -
    -        assertFileExists("target/filelanguage/123.bak");
    +    public void testProducerFileNameHeaderNotEvaluated() {
    +        template.sendBodyAndHeader("file://target/filelanguage", "Hello World", Exchange.FILE_NAME, "$simple{myfile-${date:now:yyyyMMdd}}.txt");
    +        assertFileExists("target/filelanguage/$simple{myfile-${date:now:yyyyMMdd}}.txt");
         }
     
         public void testProduceBeanByExpression() throws Exception {
    @@ -57,7 +57,7 @@ public void testProduceBeanByExpression() throws Exception {
     
         public void testProducerDateByHeader() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +            Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
             assertFileExists("target/filelanguage/myfile-" + date + ".txt");
    
  • components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java+3 1 modified
    @@ -32,6 +32,8 @@
     import org.junit.After;
     import org.junit.Before;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Base class for unit testing using a FTPServer
      */
    @@ -125,7 +127,7 @@ protected FtpServerFactory createFtpServerFactory() throws Exception {
         }
         
         public void sendFile(String url, Object body, String fileName) {
    -        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, fileName);
    +        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, simple(fileName));
         }
         
     }
    
ce19353f1297

CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for the patch.

https://github.com/apache/camelClaus IbsenSep 15, 2013via ghsa
5 files changed · +36 83
  • camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java+24 13 modified
    @@ -286,30 +286,41 @@ public String createFileName(Exchange exchange) {
             String answer;
     
             // overrule takes precedence
    -        String overrule = exchange.getIn().getHeader(Exchange.OVERRULE_FILE_NAME, String.class);
    -        String consumed = exchange.getIn().getHeader(Exchange.FILE_NAME_CONSUMED, String.class);
    -        String name = overrule == null ? exchange.getIn().getHeader(Exchange.FILE_NAME, String.class) : overrule;
    +        Object value;
    +
    +        Object overrule = exchange.getIn().getHeader(Exchange.OVERRULE_FILE_NAME);
    +        if (overrule != null) {
    +            if (overrule instanceof Expression) {
    +                value = overrule;
    +            } else {
    +                value = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, overrule);
    +            }
    +        } else {
    +            value = exchange.getIn().getHeader(Exchange.FILE_NAME);
    +        }
     
             // if we have an overrule then override the existing header to use the overrule computed name from this point forward
             if (overrule != null) {
    -            exchange.getIn().setHeader(Exchange.FILE_NAME, name);
    +            exchange.getIn().setHeader(Exchange.FILE_NAME, value);
    +        }
    +
    +        if (value != null && value instanceof String && StringHelper.hasStartToken((String) value, "simple")) {
    +            log.warn("Simple expression: {} detected in header: {} of type String. This feature has been removed (see CAMEL-6748).", value, Exchange.FILE_NAME);
             }
     
             // expression support
             Expression expression = endpoint.getFileName();
    -
    -        if (name != null && !name.equals(consumed)) {
    -            // the header name can be an expression too, that should override
    -            // whatever configured on the endpoint
    -            if (StringHelper.hasStartToken(name, "simple")) {
    -                log.trace("{} contains a Simple expression: {}", Exchange.FILE_NAME, name);
    -                Language language = getEndpoint().getCamelContext().resolveLanguage("file");
    -                expression = language.createExpression(name);
    -            }
    +        if (value != null && value instanceof Expression) {
    +            expression = (Expression) value;
             }
    +
    +        // evaluate the name as a String from the value
    +        String name;
             if (expression != null) {
                 log.trace("Filename evaluated as expression: {}", expression);
                 name = expression.evaluate(exchange, String.class);
    +        } else {
    +            name = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value);
             }
     
             // flatten name
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java+3 1 modified
    @@ -22,6 +22,8 @@
     import org.apache.camel.component.mock.MockEndpoint;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file consumer.
      */
    @@ -70,7 +72,7 @@ public void configure() throws Exception {
         public void testConsumeFileBasedOnDatePattern() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage/date", "Bye World", Exchange.FILE_NAME, "myfile-20081128.txt");
             template.sendBodyAndHeader("file://target/filelanguage/date", "Hello World", Exchange.FILE_NAME, "myfile-20081129.txt");
    -        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             context.addRoutes(new RouteBuilder() {
                 @Override
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java+0 62 removed
    @@ -1,62 +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.
    - */
    -package org.apache.camel.component.file;
    -
    -import java.text.SimpleDateFormat;
    -import java.util.Date;
    -import java.util.Map;
    -import java.util.TreeMap;
    -
    -import org.apache.camel.ContextTestSupport;
    -import org.apache.camel.Exchange;
    -
    -/**
    - * @version
    - */
    -public class FileProducerConsumedFileNameEvaluationTest extends ContextTestSupport {
    -
    -    @Override
    -    protected void setUp() throws Exception {
    -        deleteDirectory("target/producerconsumedfilename");
    -        super.setUp();
    -    }
    -
    -    public void testFileNameNotEvaluatedWhenMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-${date:now:yyyyMMdd}");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        assertFileExists("target/producerconsumedfilename/file-${date:now:yyyyMMdd}");
    -    }
    -
    -    public void testFileNameEvaluatedWhenNotMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-consumed");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -
    -    public void testFileNameEvaluatedWhenConsumedNull() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -}
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java+6 6 modified
    @@ -25,6 +25,8 @@
     import org.apache.camel.Exchange;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file producer.
      */
    @@ -43,11 +45,9 @@ protected JndiRegistry createRegistry() throws Exception {
             return jndi;
         }
     
    -    public void testProduceBeanByHeader() throws Exception {
    -        template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "${bean:myguidgenerator}.bak");
    -
    -        assertFileExists("target/filelanguage/123.bak");
    +    public void testProducerFileNameHeaderNotEvaluated() {
    +        template.sendBodyAndHeader("file://target/filelanguage", "Hello World", Exchange.FILE_NAME, "$simple{myfile-${date:now:yyyyMMdd}}.txt");
    +        assertFileExists("target/filelanguage/$simple{myfile-${date:now:yyyyMMdd}}.txt");
         }
     
         public void testProduceBeanByExpression() throws Exception {
    @@ -58,7 +58,7 @@ public void testProduceBeanByExpression() throws Exception {
     
         public void testProducerDateByHeader() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +            Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
             assertFileExists("target/filelanguage/myfile-" + date + ".txt");
    
  • components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java+3 1 modified
    @@ -32,6 +32,8 @@
     import org.junit.After;
     import org.junit.Before;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Base class for unit testing using a FTPServer
      */
    @@ -125,7 +127,7 @@ protected FtpServerFactory createFtpServerFactory() throws Exception {
         }
         
         public void sendFile(String url, Object body, String fileName) {
    -        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, fileName);
    +        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, simple(fileName));
         }
         
     }
    
3215fe50dd42

CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for the patch.

https://github.com/apache/camelClaus IbsenSep 15, 2013via ghsa
5 files changed · +24 80
  • camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java+12 10 modified
    @@ -256,23 +256,25 @@ public void writeFile(Exchange exchange, String fileName) throws GenericFileOper
         public String createFileName(Exchange exchange) {
             String answer;
     
    -        String name = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
    -        String consumed = exchange.getIn().getHeader(Exchange.FILE_NAME_CONSUMED, String.class);
    +        Object value = exchange.getIn().getHeader(Exchange.FILE_NAME);
    +
    +        if (value != null && value instanceof String && StringHelper.hasStartToken((String) value, "simple")) {
    +            log.warn("Simple expression: {} detected in header: {} of type String. This feature has been removed (see CAMEL-6748).", value, Exchange.FILE_NAME);
    +        }
     
             // expression support
             Expression expression = endpoint.getFileName();
    -        if (name != null && !name.equals(consumed)) {
    -            // the header name can be an expression too, that should override
    -            // whatever configured on the endpoint
    -            if (StringHelper.hasStartToken(name, "simple")) {
    -                log.trace("{} contains a Simple expression: {}", Exchange.FILE_NAME, name);
    -                Language language = getEndpoint().getCamelContext().resolveLanguage("file");
    -                expression = language.createExpression(name);
    -            }
    +        if (value != null && value instanceof Expression) {
    +            expression = (Expression) value;
             }
    +
    +        // evaluate the name as a String from the value
    +        String name;
             if (expression != null) {
                 log.trace("Filename evaluated as expression: {}", expression);
                 name = expression.evaluate(exchange, String.class);
    +        } else {
    +            name = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, value);
             }
     
             // flatten name
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java+3 1 modified
    @@ -22,6 +22,8 @@
     import org.apache.camel.component.mock.MockEndpoint;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file consumer.
      */
    @@ -70,7 +72,7 @@ public void configure() throws Exception {
         public void testConsumeFileBasedOnDatePattern() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage/date", "Bye World", Exchange.FILE_NAME, "myfile-20081128.txt");
             template.sendBodyAndHeader("file://target/filelanguage/date", "Hello World", Exchange.FILE_NAME, "myfile-20081129.txt");
    -        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +        template.sendBodyAndHeader("file://target/filelanguage/date", "Goodday World", Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             context.addRoutes(new RouteBuilder() {
                 @Override
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java+0 62 removed
    @@ -1,62 +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.
    - */
    -package org.apache.camel.component.file;
    -
    -import java.text.SimpleDateFormat;
    -import java.util.Date;
    -import java.util.Map;
    -import java.util.TreeMap;
    -
    -import org.apache.camel.ContextTestSupport;
    -import org.apache.camel.Exchange;
    -
    -/**
    - * @version
    - */
    -public class FileProducerConsumedFileNameEvaluationTest extends ContextTestSupport {
    -
    -    @Override
    -    protected void setUp() throws Exception {
    -        deleteDirectory("target/producerconsumedfilename");
    -        super.setUp();
    -    }
    -
    -    public void testFileNameNotEvaluatedWhenMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-${date:now:yyyyMMdd}");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        assertFileExists("target/producerconsumedfilename/file-${date:now:yyyyMMdd}");
    -    }
    -
    -    public void testFileNameEvaluatedWhenNotMatchingConsumed() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        headers.put(Exchange.FILE_NAME_CONSUMED, "file-consumed");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -
    -    public void testFileNameEvaluatedWhenConsumedNull() throws Exception {
    -        Map<String, Object> headers = new TreeMap<String, Object>();
    -        headers.put(Exchange.FILE_NAME, "file-${date:now:yyyyMMdd}.txt");
    -        template.sendBodyAndHeaders("file://target/producerconsumedfilename", "Hello World", headers);
    -        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    -        assertFileExists("target/producerconsumedfilename/file-" + date + ".txt");
    -    }
    -}
    
  • camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java+6 6 modified
    @@ -25,6 +25,8 @@
     import org.apache.camel.Exchange;
     import org.apache.camel.impl.JndiRegistry;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Unit test for expression option for file producer.
      */
    @@ -43,11 +45,9 @@ protected JndiRegistry createRegistry() throws Exception {
             return jndi;
         }
     
    -    public void testProduceBeanByHeader() throws Exception {
    -        template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "${bean:myguidgenerator}.bak");
    -
    -        assertFileExists("target/filelanguage/123.bak");
    +    public void testProducerFileNameHeaderNotEvaluated() {
    +        template.sendBodyAndHeader("file://target/filelanguage", "Hello World", Exchange.FILE_NAME, "$simple{myfile-${date:now:yyyyMMdd}}.txt");
    +        assertFileExists("target/filelanguage/$simple{myfile-${date:now:yyyyMMdd}}.txt");
         }
     
         public void testProduceBeanByExpression() throws Exception {
    @@ -58,7 +58,7 @@ public void testProduceBeanByExpression() throws Exception {
     
         public void testProducerDateByHeader() throws Exception {
             template.sendBodyAndHeader("file://target/filelanguage", "Hello World",
    -            Exchange.FILE_NAME, "myfile-${date:now:yyyyMMdd}.txt");
    +            Exchange.FILE_NAME, simple("myfile-${date:now:yyyyMMdd}.txt"));
     
             String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
             assertFileExists("target/filelanguage/myfile-" + date + ".txt");
    
  • components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java+3 1 modified
    @@ -32,6 +32,8 @@
     import org.junit.After;
     import org.junit.Before;
     
    +import static org.apache.camel.language.simple.SimpleLanguage.simple;
    +
     /**
      * Base class for unit testing using a FTPServer
      */
    @@ -127,7 +129,7 @@ protected FtpServerFactory createFtpServerFactory() throws Exception {
         }
         
         public void sendFile(String url, Object body, String fileName) {
    -        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, fileName);
    +        template.sendBodyAndHeader(url, body, Exchange.FILE_NAME, simple(fileName));
         }
         
     }
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

24

News mentions

0

No linked articles in our index yet.