camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/5] git commit: CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for the patch.
Date Sun, 15 Sep 2013 14:05:52 GMT
CAMEL-6748: Optimize File Producers by Skipping Header Evaluation. Thansk to James Carman for
the patch.

Conflicts:
	camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3215fe50
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3215fe50
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3215fe50

Branch: refs/heads/camel-2.10.x
Commit: 3215fe50dd42c83a7a454dd36486843fe36eae48
Parents: 9093b7a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Sep 15 15:12:29 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Sep 15 15:15:09 2013 +0200

----------------------------------------------------------------------
 .../component/file/GenericFileProducer.java     | 22 +++----
 .../file/FileConsumerFileExpressionTest.java    |  4 +-
 ...eProducerConsumedFileNameEvaluationTest.java | 62 --------------------
 .../file/FileProducerExpressionTest.java        | 12 ++--
 .../file/remote/FtpServerTestSupport.java       |  4 +-
 5 files changed, 24 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3215fe50/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
index 27f68c8..f366e0f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
@@ -256,23 +256,25 @@ public class GenericFileProducer<T> extends DefaultProducer {
     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

http://git-wip-us.apache.org/repos/asf/camel/blob/3215fe50/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java
index c6a83d2..0ddc412 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileExpressionTest.java
@@ -22,6 +22,8 @@ import org.apache.camel.builder.RouteBuilder;
 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 class FileConsumerFileExpressionTest extends ContextTestSupport {
     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

http://git-wip-us.apache.org/repos/asf/camel/blob/3215fe50/camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java
deleted file mode 100644
index 64da59d..0000000
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerConsumedFileNameEvaluationTest.java
+++ /dev/null
@@ -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");
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/3215fe50/camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java
index 6848189..208e01f 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerExpressionTest.java
@@ -25,6 +25,8 @@ import org.apache.camel.ContextTestSupport;
 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 @@ public class FileProducerExpressionTest extends ContextTestSupport {
         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 class FileProducerExpressionTest extends ContextTestSupport {
 
     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");

http://git-wip-us.apache.org/repos/asf/camel/blob/3215fe50/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
index 96b47fa..0d63c94 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
@@ -32,6 +32,8 @@ import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
 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 @@ public abstract class FtpServerTestSupport extends BaseServerTestSupport
{
     }
     
     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));
     }
     
 }


Mime
View raw message