camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r988146 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/component/file/strategy/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache...
Date Mon, 23 Aug 2010 15:15:01 GMT
Author: davsclaus
Date: Mon Aug 23 15:15:00 2010
New Revision: 988146

URL: http://svn.apache.org/viewvc?rev=988146&view=rev
Log:
CAMEL-1895: Fixed limitation of pollEnrich not being able to poll from file endpoint if route
started from file endpoint as well.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMoveRelativeNameTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
Mon Aug 23 15:15:00 2010
@@ -127,7 +127,6 @@ public class FileConsumer extends Generi
 
         answer.setEndpointPath(endpointPath);
         answer.setFile(file);
-        answer.setFileName(file.getName());
         answer.setFileNameOnly(file.getName());
         answer.setFileLength(file.length());
         // must use FileUtil.isAbsolute to have consistent check for whether the file is
@@ -158,6 +157,9 @@ public class FileConsumer extends Generi
             }
         }
 
+        // the file name should be the relative path
+        answer.setFileName(answer.getRelativeFilePath());
+
         // use file as body as we have converters if needed as stream
         answer.setBody(file);
         return answer;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProcessStrategy.java
Mon Aug 23 15:15:00 2010
@@ -46,7 +46,7 @@ public interface GenericFileProcessStrat
      * @throws Exception can be thrown in case of errors
      */
     boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T>
endpoint,
-            Exchange exchange, GenericFile<T> file) throws Exception;
+                  Exchange exchange, GenericFile<T> file) throws Exception;
 
     /**
      * Releases any file locks and possibly deletes or moves the file after
@@ -59,7 +59,7 @@ public interface GenericFileProcessStrat
      * @throws Exception can be thrown in case of errors
      */
     void commit(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint,
-            Exchange exchange, GenericFile<T> file) throws Exception;
+                Exchange exchange, GenericFile<T> file) throws Exception;
 
     /**
      * Releases any file locks and possibly deletes or moves the file after
@@ -72,6 +72,6 @@ public interface GenericFileProcessStrat
      * @throws Exception can be thrown in case of errors
      */
     void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T>
endpoint,
-            Exchange exchange, GenericFile<T> file) throws Exception;
+                  Exchange exchange, GenericFile<T> file) throws Exception;
 
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
Mon Aug 23 15:15:00 2010
@@ -89,7 +89,14 @@ public class GenericFileDeleteProcessStr
 
         // moved the failed file if specifying the moveFailed option
         if (failureRenamer != null) {
-            GenericFile<T> newName = failureRenamer.renameFile(exchange, file);
+            // create a copy and bind the file to the exchange to be used by the renamer
to evaluate the file name
+            Exchange copy = exchange.copy();
+            file.bindToExchange(copy);
+            // must preserve message id
+            copy.getIn().setMessageId(exchange.getIn().getMessageId());
+            copy.setExchangeId(exchange.getExchangeId());
+
+            GenericFile<T> newName = failureRenamer.renameFile(copy, file);
             renameFile(operations, file, newName);
         }
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
Mon Aug 23 15:15:00 2010
@@ -16,12 +16,9 @@
  */
 package org.apache.camel.component.file.strategy;
 
-import java.io.IOException;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileEndpoint;
-import org.apache.camel.component.file.GenericFileOperationFailedException;
 import org.apache.camel.component.file.GenericFileOperations;
 
 public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrategySupport<T>
{
@@ -57,7 +54,14 @@ public class GenericFileRenameProcessStr
         super.rollback(operations, endpoint, exchange, file);
 
         if (failureRenamer != null) {
-            GenericFile<T> newName = failureRenamer.renameFile(exchange, file);
+            // create a copy and bind the file to the exchange to be used by the renamer
to evaluate the file name
+            Exchange copy = exchange.copy();
+            file.bindToExchange(copy);
+            // must preserve message id
+            copy.getIn().setMessageId(exchange.getIn().getMessageId());
+            copy.setExchangeId(exchange.getExchangeId());
+
+            GenericFile<T> newName = failureRenamer.renameFile(copy, file);
             renameFile(operations, file, newName);
         }
     }
@@ -68,7 +72,14 @@ public class GenericFileRenameProcessStr
         super.commit(operations, endpoint, exchange, file);
 
         if (commitRenamer != null) {
-            GenericFile<T> newName = commitRenamer.renameFile(exchange, file);
+            // create a copy and bind the file to the exchange to be used by the renamer
to evaluate the file name
+            Exchange copy = exchange.copy();
+            file.bindToExchange(copy);
+            // must preserve message id
+            copy.getIn().setMessageId(exchange.getIn().getMessageId());
+            copy.setExchangeId(exchange.getExchangeId());
+
+            GenericFile<T> newName = commitRenamer.renameFile(copy, file);
             renameFile(operations, file, newName);
         }
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/PollEnricher.java Mon
Aug 23 15:15:00 2010
@@ -19,13 +19,13 @@ package org.apache.camel.processor;
 import org.apache.camel.Exchange;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
-import org.apache.camel.impl.EventDrivenPollingConsumer;
 import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import static org.apache.camel.util.ExchangeHelper.copyResultsPreservePattern;
 
 /**
@@ -169,18 +169,7 @@ public class PollEnricher extends Servic
      * @param exchange the current exchange
      */
     protected void preCheckPoll(Exchange exchange) throws Exception {
-        // cannot poll a file endpoint if already consuming from a file endpoint (CAMEL-1895)
-        if (consumer instanceof EventDrivenPollingConsumer) {
-            EventDrivenPollingConsumer edpc = (EventDrivenPollingConsumer) consumer;
-            boolean fileBasedConsumer = edpc.getEndpoint().getEndpointKey().startsWith("file")
|| edpc.getEndpoint().getEndpointKey().startsWith("ftp");
-            boolean fileBasedExchange = exchange.getFromEndpoint() != null
-                    && (exchange.getFromEndpoint().getEndpointUri().startsWith("file")
|| exchange.getFromEndpoint().getEndpointUri().startsWith("ftp"));
-            if (fileBasedConsumer && fileBasedExchange) {
-                throw new IllegalArgumentException("Camel currently does not support pollEnrich
from a file/ftp endpoint"
-                        + " when the route also started from a file/ftp endpoint."
-                        + " Started from: " + exchange.getFromEndpoint().getEndpointUri()
+ " pollEnrich: " + edpc.getEndpoint().getEndpointUri());
-            }
-        }
+        // noop
     }
 
     private static void prepareResult(Exchange exchange) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMoveRelativeNameTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMoveRelativeNameTest.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMoveRelativeNameTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMoveRelativeNameTest.java
Mon Aug 23 15:15:00 2010
@@ -35,19 +35,18 @@ public class FileConsumeMoveRelativeName
         super.setUp();
         template.sendBodyAndHeader(fileUrl, "Bye World", Exchange.FILE_NAME, "bye.txt");
         template.sendBodyAndHeader(fileUrl, "Hello World", Exchange.FILE_NAME, "sub/hello.txt");
-        template.sendBodyAndHeader(fileUrl, "Godday World", Exchange.FILE_NAME, "sub/sub2/godday.txt");
+        template.sendBodyAndHeader(fileUrl, "Goodday World", Exchange.FILE_NAME, "sub/sub2/goodday.txt");
     }
 
     public void testMultiDir() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceivedInAnyOrder("Bye World", "Hello World", "Godday World");
+        mock.expectedBodiesReceivedInAnyOrder("Bye World", "Hello World", "Goodday World");
 
         mock.expectedFileExists("target/multidir/.done/bye.txt.old");
         mock.expectedFileExists("target/multidir/.done/sub/hello.txt.old");
-        mock.expectedFileExists("target/multidir/.done/sub/sub2/godday.txt.old");
+        mock.expectedFileExists("target/multidir/.done/sub/sub2/goodday.txt.old");
 
         assertMockEndpointsSatisfied();
-
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
Mon Aug 23 15:15:00 2010
@@ -33,16 +33,14 @@ public class FileConsumePollEnrichFileTe
         super.setUp();
     }
 
-
-    // TODO: CAMEL-1895
-    public void xxxTestPollEnrich() throws Exception {
+    public void testPollEnrich() throws Exception {
         getMockEndpoint("mock:start").expectedBodiesReceived("Start");
 
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Big file");
 
-        mock.expectedFileExists("target/enrich/.done/AAA.fin");
-        mock.expectedFileExists("target/enrichdata/.done/AAA.dat");
+        mock.expectedFileExists("target/enrich/.done/AAA.fin", "Start");
+        mock.expectedFileExists("target/enrichdata/.done/AAA.dat", "Big file");
 
         template.sendBodyAndHeader("file://target/enrichdata", "Big file", Exchange.FILE_NAME,
"AAA.dat");
         template.sendBodyAndHeader("file://target/enrich", "Start", Exchange.FILE_NAME, "AAA.fin");
@@ -50,10 +48,6 @@ public class FileConsumePollEnrichFileTe
         assertMockEndpointsSatisfied();
     }
 
-    public void testNothing() {
-        //
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
Mon Aug 23 15:15:00 2010
@@ -51,7 +51,7 @@ public class FileConsumerAbsolutePathWit
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("file://" + base + "?move=" + base + "/done/${file:name}").convertBodyTo(String.class).to("mock:report");
+                from("file://" + base + "?move=" + base + "/done/${file:onlyname}").convertBodyTo(String.class).to("mock:report");
             }
         };
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
Mon Aug 23 15:15:00 2010
@@ -51,7 +51,7 @@ public class FileConsumerAbsolutePathWit
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("file://" + base + "?move=../done/${file:name}").convertBodyTo(String.class).to("mock:report");
+                from("file://" + base + "?move=../done/${file:onlyname}").convertBodyTo(String.class).to("mock:report");
             }
         };
     }

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
Mon Aug 23 15:15:00 2010
@@ -124,7 +124,6 @@ public class FtpConsumer extends RemoteF
 
         answer.setEndpointPath(endpointPath);
         answer.setFile(file);
-        answer.setFileName(file.getName());
         answer.setFileNameOnly(file.getName());
         answer.setFileLength(file.getSize());
         if (file.getTimestamp() != null) {
@@ -146,6 +145,9 @@ public class FtpConsumer extends RemoteF
         relativePath = FileUtil.stripLeadingSeparator(relativePath);
         answer.setRelativeFilePath(relativePath);
 
+        // the file name should be the relative path
+        answer.setFileName(answer.getRelativeFilePath());
+
         return answer;
     }
 

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
Mon Aug 23 15:15:00 2010
@@ -107,7 +107,6 @@ public class SftpConsumer extends Remote
 
         answer.setEndpointPath(endpointPath);
         answer.setFile(file);
-        answer.setFileName(file.getFilename());
         answer.setFileNameOnly(file.getFilename());
         answer.setFileLength(file.getAttrs().getSize());
         answer.setLastModified(file.getAttrs().getMTime() * 1000L);
@@ -126,6 +125,9 @@ public class SftpConsumer extends Remote
         relativePath = FileUtil.stripLeadingSeparator(relativePath);
         answer.setRelativeFilePath(relativePath);
 
+        // the file name should be the relative path
+        answer.setFileName(answer.getRelativeFilePath());
+
         return answer;
     }
 

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java?rev=988146&r1=988145&r2=988146&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
Mon Aug 23 15:15:00 2010
@@ -58,14 +58,16 @@ public class FtpConsumerMultipleDirector
         assertNotNull(file);
         assertDirectoryEquals("multidir/sub/hello.txt", file.getAbsoluteFilePath());
         assertDirectoryEquals("sub/hello.txt", file.getRelativeFilePath());
-        assertEquals("hello.txt", file.getFileName());
+        assertEquals("sub/hello.txt", file.getFileName());
+        assertEquals("hello.txt", file.getFileNameOnly());
 
         exchange = mock.getExchanges().get(2);
         file = (RemoteFile) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
         assertNotNull(file);
         assertDirectoryEquals("multidir/sub/sub2/godday.txt", file.getAbsoluteFilePath());
         assertDirectoryEquals("sub/sub2/godday.txt", file.getRelativeFilePath());
-        assertEquals("godday.txt", file.getFileName());
+        assertEquals("sub/sub2/godday.txt", file.getFileName());
+        assertEquals("godday.txt", file.getFileNameOnly());
     }
     
     private void prepareFtpServer() throws Exception {



Mime
View raw message