camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1441518 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/test/java/org/apache/camel/component/file/ ca...
Date Fri, 01 Feb 2013 16:40:32 GMT
Author: davsclaus
Date: Fri Feb  1 16:40:31 2013
New Revision: 1441518

URL: http://svn.apache.org/viewvc?rev=1441518&view=rev
Log:
CAMEL-6025: Use long for file last modified header. Allows to transfer over JMS etc.

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java
      - copied, changed from r1441428, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteToJmsTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpKeepLastModifiedTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=1441518&r1=1441517&r2=1441518&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Fri Feb  1 16:40:31
2013
@@ -120,6 +120,7 @@ public interface Exchange {
     String FILE_PATH            = "CamelFilePath";
     String FILE_PARENT          = "CamelFileParent";
     String FILE_LAST_MODIFIED   = "CamelFileLastModified";
+    String FILE_LENGTH          = "CamelFileLength";
     String FILTER_MATCHED       = "CamelFilterMatched";
     String FILE_LOCK_FILE_ACQUIRED   = "CamelFileLockFileAcquired"; 
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=1441518&r1=1441517&r2=1441518&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Fri
Feb  1 16:40:31 2013
@@ -1350,9 +1350,14 @@ public final class ExpressionBuilder {
                         throw new IllegalArgumentException("Cannot find java.util.Date object
at command: " + command);
                     }
                 } else if ("file".equals(command)) {
-                    date = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Date.class);
-                    if (date == null) {
-                        throw new IllegalArgumentException("Cannot find " + Exchange.FILE_LAST_MODIFIED
+ " header at command: " + command);
+                    Long num = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Long.class);
+                    if (num != null && num > 0) {
+                        date = new Date(num.longValue());
+                    } else {
+                        date = exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Date.class);
+                        if (date == null) {
+                            throw new IllegalArgumentException("Cannot find " + Exchange.FILE_LAST_MODIFIED
+ " header at command: " + command);
+                        }
                     }
                 } else {
                     throw new IllegalArgumentException("Command not supported for dateExpression:
" + command);
@@ -1587,7 +1592,7 @@ public final class ExpressionBuilder {
     public static Expression fileSizeExpression() {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
-                return exchange.getIn().getHeader("CamelFileLength", Long.class);
+                return exchange.getIn().getHeader(Exchange.FILE_LENGTH, Long.class);
             }
 
             @Override
@@ -1600,7 +1605,7 @@ public final class ExpressionBuilder {
     public static Expression fileLastModifiedExpression() {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
-                return exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Date.class);
+                return exchange.getIn().getHeader(Exchange.FILE_LAST_MODIFIED, Long.class);
             }
 
             @Override

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=1441518&r1=1441517&r2=1441518&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Fri Feb  1 16:40:31 2013
@@ -144,10 +144,10 @@ public class GenericFile<T> implements W
             message.setHeader(Exchange.FILE_PARENT, getParent());
     
             if (getFileLength() >= 0) {
-                message.setHeader("CamelFileLength", getFileLength());
+                message.setHeader(Exchange.FILE_LENGTH, getFileLength());
             }
             if (getLastModified() > 0) {
-                message.setHeader(Exchange.FILE_LAST_MODIFIED, new Date(getLastModified()));
+                message.setHeader(Exchange.FILE_LAST_MODIFIED, getLastModified());
             }
         }
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java?rev=1441518&r1=1441517&r2=1441518&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
Fri Feb  1 16:40:31 2013
@@ -53,7 +53,7 @@ public class FileKeepLastModifiedTest ex
 
         assertMockEndpointsSatisfied();
 
-        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
Date.class).getTime();
+        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
long.class);
         long t2 = new File("target/keep/out/hello.txt").lastModified();
 
         assertEquals("Timestamp should have been kept", t1, t2);
@@ -76,7 +76,7 @@ public class FileKeepLastModifiedTest ex
 
         assertMockEndpointsSatisfied();
 
-        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
Date.class).getTime();
+        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
long.class);
         long t2 = new File("target/keep/out/hello.txt").lastModified();
 
         assertNotSame("Timestamp should NOT have been kept", t1, t2);
@@ -99,7 +99,7 @@ public class FileKeepLastModifiedTest ex
 
         assertMockEndpointsSatisfied();
 
-        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
Date.class).getTime();
+        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
long.class);
         long t2 = new File("target/keep/out/hello.txt").lastModified();
 
         assertNotSame("Timestamp should NOT have been kept", t1, t2);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java?rev=1441518&r1=1441517&r2=1441518&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java Fri
Feb  1 16:40:31 2013
@@ -83,9 +83,9 @@ public class FileLanguageTest extends La
         assertExpression("${file:length}", file.length());
         assertExpression("${file:size}", file.length());
 
-        // modified is a Date object
-        Date modified = SimpleLanguage.simple("${file:modified}").evaluate(exchange, Date.class);
-        assertEquals(new Date(file.lastModified()), modified);
+        // modified is a long object
+        Long modified = SimpleLanguage.simple("${file:modified}").evaluate(exchange, Long.class);
+        assertEquals(file.lastModified(), modified.longValue());
     }
 
     public void testFileUsingAlternativeStartToken() throws Exception {
@@ -102,9 +102,9 @@ public class FileLanguageTest extends La
         assertExpression("$simple{file:length}", file.length());
         assertExpression("$simple{file:size}", file.length());
 
-        // modified is a Date object
-        Date modified = SimpleLanguage.simple("${file:modified}").evaluate(exchange, Date.class);
-        assertEquals(new Date(file.lastModified()), modified);
+        // modified is a long object
+        long modified = SimpleLanguage.simple("${file:modified}").evaluate(exchange, long.class);
+        assertEquals(file.lastModified(), modified);
     }
 
     public void testDate() throws Exception {

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpKeepLastModifiedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpKeepLastModifiedTest.java?rev=1441518&r1=1441517&r2=1441518&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpKeepLastModifiedTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpKeepLastModifiedTest.java
Fri Feb  1 16:40:31 2013
@@ -59,7 +59,7 @@ public class FromFtpKeepLastModifiedTest
 
         assertMockEndpointsSatisfied();
 
-        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
Date.class).getTime();
+        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
long.class);
         long t2 = new File("target/keep/out/hello.txt").lastModified();
 
         assertEquals("Timestamp should have been kept", t1, t2);
@@ -83,7 +83,7 @@ public class FromFtpKeepLastModifiedTest
 
         assertMockEndpointsSatisfied();
 
-        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
Date.class).getTime();
+        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
long.class);
         long t2 = new File("target/keep/out/hello.txt").lastModified();
 
         assertNotSame("Timestamp should NOT have been kept", t1, t2);
@@ -107,7 +107,7 @@ public class FromFtpKeepLastModifiedTest
 
         assertMockEndpointsSatisfied();
 
-        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
Date.class).getTime();
+        long t1 = mock.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_LAST_MODIFIED,
long.class);
         long t2 = new File("target/keep/out/hello.txt").lastModified();
 
         assertNotSame("Timestamp should NOT have been kept", t1, t2);

Copied: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java
(from r1441428, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteToJmsTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteToJmsTest.java&r1=1441428&r2=1441518&rev=1441518&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteToJmsTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java
Fri Feb  1 16:40:31 2013
@@ -16,12 +16,12 @@
  */
 package org.apache.camel.component.jms;
 
+import java.io.File;
 import javax.jms.ConnectionFactory;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -30,21 +30,22 @@ import static org.apache.camel.component
 /**
  * Unit test that we can produce JMS message from files
  */
-public class FileRouteToJmsTest extends CamelTestSupport {
+public class FileRouteJmsKeepLastModifiedTest extends CamelTestSupport {
 
     protected String componentName = "activemq";
 
     @Test
-    public void testRouteToFile() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.message(0).body().isInstanceOf(byte[].class);
-        mock.message(0).body(String.class).isEqualTo("Hello World");
+    public void testKeepLastModified() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
 
-        deleteDirectory("target/routefromfile");
-        template.sendBodyAndHeader("file://target/routefromfile", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+        template.sendBodyAndHeader("file://target/inbox", "Hello World", Exchange.FILE_NAME,
"hello.txt");
 
         assertMockEndpointsSatisfied();
+
+        File inbox = new File("trarget/inbox/hello.txt");
+        File outbox = new File("trarget/outbox/hello.txt");
+
+        assertEquals("Should keep last modified", inbox.lastModified(), outbox.lastModified());
     }
 
     protected CamelContext createCamelContext() throws Exception {
@@ -59,9 +60,13 @@ public class FileRouteToJmsTest extends 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("file://target/routefromfile").to("activemq:queue:hello");
+                from("file://target/inbox?noop=true").to("activemq:queue:hello");
 
-                from("activemq:queue:hello").to("mock:result");
+                from("activemq:queue:hello")
+                    // just a little delay so the write of the file happens later
+                    .delayer(100)
+                    .to("file://target/outbox?keepLastModified=true")
+                    .to("mock:result");
             }
         };
     }



Mime
View raw message