You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/01/27 14:55:55 UTC
svn commit: r738093 [1/2] - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/builder/
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/ap...
Author: davsclaus
Date: Tue Jan 27 13:55:53 2009
New Revision: 738093
URL: http://svn.apache.org/viewvc?rev=738093&view=rev
Log:
CAMEL-1241: NewFileComponent using the new Camel VFS living side by side with old File component, until the new is rock solid.
Removed:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileExchangeTest.java
Modified:
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/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.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/GenericFileProducer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileComponent.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileEndpoint.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.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/GenericFileProcessStrategySupport.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.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/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileProcessStrategyFactory.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeFileOnlyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileFilterTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpLockFileTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceGeneratedFileNameTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileSorterRefTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerFileNamesTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpRemoteFileEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpRemoteFileOperations.java
camel/trunk/tests/camel-itest/pom.xml
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
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=738093&r1=738092&r2=738093&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 Tue Jan 27 13:55:53 2009
@@ -58,7 +58,7 @@
public Object evaluate(Exchange exchange) {
Object header = exchange.getIn().getHeader(headerName);
if (header == null) {
- // lets try the exchange header
+ // fall back on a property
header = exchange.getProperty(headerName);
}
return header;
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=738093&r1=738092&r2=738093&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 Tue Jan 27 13:55:53 2009
@@ -16,6 +16,9 @@
*/
package org.apache.camel.component.file;
+import java.io.File;
+import java.util.Date;
+
import org.apache.camel.util.ObjectHelper;
/**
@@ -25,6 +28,7 @@
public class GenericFile<T> {
private String absoluteFileName;
+ private String canonicalFileName;
private String relativeFileName;
private String fileName;
private long fileLength;
@@ -51,6 +55,7 @@
throw ObjectHelper.wrapRuntimeCamelException(e);
}
result.setAbsoluteFileName(source.getAbsoluteFileName());
+ result.setCanonicalFileName(source.getCanonicalFileName());
result.setRelativeFileName(source.getRelativeFileName());
result.setFileName(source.getFileName());
result.setFileLength(source.getFileLength());
@@ -163,11 +168,6 @@
this.binding = binding;
}
- @Override
- public String toString() {
- return getAbsoluteFileName();
- }
-
/**
* @param absoluteFileName the absoluteFileName to set
*/
@@ -182,4 +182,16 @@
return absoluteFileName;
}
+ public String getCanonicalFileName() {
+ return canonicalFileName;
+ }
+
+ public void setCanonicalFileName(String canonicalFileName) {
+ this.canonicalFileName = canonicalFileName;
+ }
+
+ @Override
+ public String toString() {
+ return "GenericFile[" + fileName + "]";
+ }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java Tue Jan 27 13:55:53 2009
@@ -21,16 +21,11 @@
public class GenericFileConfiguration {
private String file;
- private boolean directory = true;
public GenericFileConfiguration() {
super();
}
- public String toString() {
- return "/" + file;
- }
-
public void configure(URI uri) {
setFile(uri.getPath());
}
@@ -40,20 +35,11 @@
}
public void setFile(String file) {
- // Avoid accidentally putting everything in root on
- // servers that expose the full filesystem
- if (file.startsWith("/")) {
- file = file.substring(1);
- }
this.file = file;
}
- public boolean isDirectory() {
- return directory;
- }
-
- public void setDirectory(boolean directory) {
- this.directory = directory;
+ public String toString() {
+ return file;
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Tue Jan 27 13:55:53 2009
@@ -56,7 +56,7 @@
List<GenericFile<T>> files = new ArrayList<GenericFile<T>>();
String name = endpoint.getConfiguration().getFile();
- boolean isDirectory = endpoint.getConfiguration().isDirectory();
+ boolean isDirectory = endpoint.isDirectory();
if (isDirectory) {
pollDirectory(name, files);
} else {
@@ -239,7 +239,12 @@
if (log.isDebugEnabled()) {
log.debug("Rolling back remote file strategy: " + processStrategy + " for file: " + file);
}
- processStrategy.rollback(operations, endpoint, exchange, file);
+ try {
+ processStrategy.rollback(operations, endpoint, exchange, file);
+ } catch (Exception e) {
+ log.warn("Error rolling back remote file strategy: " + processStrategy, e);
+ handleException(e);
+ }
}
/**
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java Tue Jan 27 13:55:53 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.file;
import java.io.IOException;
+import java.io.File;
import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.HashMap;
@@ -53,6 +54,8 @@
// TODO: Consider remove setNames
// TODO: Consider filename should always be specified when producing (to get rid of auto generating with id as filename)
// TODO: bufferSize & append can be moved to NewFileEndpoint as FTP does not support it
+ // TODO: configuration.getfile/setfile is a bit cumbersome setting endpoint using spring bean (see FileConsumerExpressionTest)
+
protected boolean directory = true;
protected boolean autoCreate = true;
protected int bufferSize = 128 * 1024;
@@ -80,20 +83,11 @@
protected long readLockTimeout;
protected GenericFileExclusiveReadLockStrategy exclusiveReadLockStrategy;
- public GenericFileEndpoint(String endpointUri, Component component) {
- super(endpointUri, component);
- }
-
- public GenericFileEndpoint(String endpointUri, CamelContext context) {
- super(endpointUri, context);
- }
-
- public GenericFileEndpoint(String endpointUri) {
- super(endpointUri);
+ public GenericFileEndpoint() {
}
- public GenericFileEndpoint() {
- super();
+ public GenericFileEndpoint(String endpointUri, Component component) {
+ super(endpointUri, component);
}
public boolean isSingleton() {
@@ -345,6 +339,9 @@
}
public GenericFileConfiguration getConfiguration() {
+ if (configuration == null) {
+ configuration = new GenericFileConfiguration();
+ }
return configuration;
}
@@ -408,6 +405,22 @@
this.autoCreate = autoCreate;
}
+ public GenericFileOperations getOperations() {
+ return operations;
+ }
+
+ public void setOperations(GenericFileOperations operations) {
+ this.operations = operations;
+ }
+
+ public GenericFileProcessStrategy getProcessStrategy() {
+ return processStrategy;
+ }
+
+ public void setProcessStrategy(GenericFileProcessStrategy processStrategy) {
+ this.processStrategy = processStrategy;
+ }
+
/**
* Should the file be moved after consuming?
*/
@@ -423,7 +436,18 @@
*/
public void configureMessage(GenericFile<T> file, Message message) {
message.setBody(file);
- message.setHeader(FileComponent.HEADER_FILE_NAME, file.getRelativeFileName());
+
+ // compute the name that was written, it should be relative to the endpoint configuraion
+ String name = file.getRelativeFileName();
+ if (name.startsWith(getConfiguration().getFile())) {
+ name = name.substring(getConfiguration().getFile().length());
+ }
+ if (name.startsWith(File.separator) || name.startsWith("/")) {
+ // skip trailing /
+ name = name.substring(1);
+ }
+
+ message.setHeader(FileComponent.HEADER_FILE_NAME, name);
}
protected Map<String, Object> getParamsAsMap() {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java Tue Jan 27 13:55:53 2009
@@ -16,6 +16,9 @@
*/
package org.apache.camel.component.file;
+import java.util.Date;
+import java.io.IOException;
+
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
@@ -58,24 +61,24 @@
super(fromEndpoint, pattern);
}
-
protected void populateHeaders(GenericFile<T> genericFile) {
if (genericFile != null) {
- getIn().setHeader("file.absoluteName", genericFile.getAbsoluteFileName());
- getIn().setHeader("file.relativeName", genericFile.getRelativeFileName());
- getIn().setHeader("file.name", genericFile.getFileName());
-
getIn().setHeader("CamelFileName", genericFile.getFileName());
- getIn().setHeader("CamelFilePath", genericFile.getAbsoluteFileName());
+ getIn().setHeader("CamelFileAbsolutePath", genericFile.getAbsoluteFileName());
// set the parent if there is a parent folder
- int lastSlash = genericFile.getAbsoluteFileName().lastIndexOf("/");
- if (genericFile.getAbsoluteFileName() != null && lastSlash != -1) {
- String parent = genericFile.getAbsoluteFileName().substring(0, lastSlash);
+ if (genericFile.getRelativeFileName().lastIndexOf("/") != -1) {
+ String parent = genericFile.getRelativeFileName().substring(0, genericFile.getRelativeFileName().lastIndexOf("/"));
getIn().setHeader("CamelFileParent", parent);
}
+ getIn().setHeader("CamelFilePath", genericFile.getRelativeFileName());
+ getIn().setHeader("CamelFileCanonicalPath", genericFile.getCanonicalFileName());
+
if (genericFile.getFileLength() > 0) {
getIn().setHeader("CamelFileLength", genericFile.getFileLength());
}
+ if (genericFile.getLastModified() > 0) {
+ getIn().setHeader("CamelFileLastModified", new Date(genericFile.getLastModified()));
+ }
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java Tue Jan 27 13:55:53 2009
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.file;
+import org.apache.camel.Exchange;
+
/**
* Strategy for acquiring exclusive read locks for files to be consumed. After
* granting the read lock it is realeased, we just want to make sure that when
@@ -35,18 +37,22 @@
*
* @param operations generic file operations
* @param file the file
+ * @param exchange the exchange
* @return <tt>true</tt> if read lock was acquired. If <tt>false</tt> Camel
* will skip the file and try it on the next poll
+ * @throws Exception can be thrown in case of errors
*/
- boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file);
+ boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange) throws Exception;
/**
* Releases the exclusive read lock granted by the <tt>acquireExclusiveReadLock</tt> method.
*
* @param operations generic file operations
* @param file the file
+ * @param exchange the exchange
+ * @throws Exception can be thrown in case of errors
*/
- void releaseExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file);
+ void releaseExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange) throws Exception;
/**
* Sets an optional timeout period.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java Tue Jan 27 13:55:53 2009
@@ -20,6 +20,8 @@
public interface GenericFileOperations<T> {
+ // TODO: setEndpoint method so we have access to it
+
/**
* Deletes the file name by name, relative to the current directory
*
@@ -45,13 +47,14 @@
* Builds the directory structure. Will test if the
* folder already exists.
*
- * @param directory the directory path to build
+ * @param directory the directory path to build as a relative string name
+ * @param absolute wether the directory is an absolute or relative path
* @return true if build or already exists, false if not possbile (could be
* lack of permissions)
* @throws GenericFileOperationFailedException
* can be thrown
*/
- boolean buildDirectory(String directory) throws GenericFileOperationFailedException;
+ boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException;
/**
* Retrieves the file
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=738093&r1=738092&r2=738093&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 Tue Jan 27 13:55:53 2009
@@ -19,7 +19,7 @@
/**
* Represents a strategy for marking that a remote file is processed.
*/
-public interface GenericFileProcessStrategy {
+public interface GenericFileProcessStrategy<T> {
/**
* Called when work is about to begin on this file. This method may attempt
@@ -34,8 +34,8 @@
* be obtained)
* @throws Exception can be thrown in case of errors
*/
- boolean begin(GenericFileOperations operations, GenericFileEndpoint endpoint,
- GenericFileExchange exchange, GenericFile file) throws Exception;
+ boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint,
+ GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception;
/**
* Releases any file locks and possibly deletes or moves the file after
@@ -47,8 +47,8 @@
* @param file the remote file
* @throws Exception can be thrown in case of errors
*/
- void commit(GenericFileOperations operations, GenericFileEndpoint endpoint,
- GenericFileExchange exchange, GenericFile file) throws Exception;
+ void commit(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint,
+ GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception;
/**
* Releases any file locks and possibly deletes or moves the file after
@@ -58,8 +58,9 @@
* @param endpoint the endpoint
* @param exchange the exchange
* @param file the remote file
+ * @throws Exception can be thrown in case of errors
*/
- void rollback(GenericFileOperations operations, GenericFileEndpoint endpoint,
- GenericFileExchange exchange, GenericFile file);
+ void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint,
+ GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java Tue Jan 27 13:55:53 2009
@@ -121,8 +121,8 @@
int lastPathIndex = fileName.lastIndexOf('/');
if (lastPathIndex != -1) {
String directory = fileName.substring(0, lastPathIndex);
- if (!getOperations().buildDirectory(directory)) {
- log.debug("Couldn't build directory [" + directory + "] (could be because of denied permissions)");
+ if (!getOperations().buildDirectory(directory, false)) {
+ log.debug("Can not build directory [" + directory + "] (could be because of denied permissions)");
}
}
// upload
@@ -170,7 +170,7 @@
}
String endpointFile = getGenericFileEndpoint().getConfiguration().getFile();
- if (getGenericFileEndpoint().isDirectory() || getGenericFileEndpoint().getConfiguration().isDirectory()) {
+ if (getGenericFileEndpoint().isDirectory()) {
// Its a directory so we should use it as a basepath for the filename
// If the path isn't empty, we need to add a trailing / if it isn't already there
String baseDir = "";
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileComponent.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileComponent.java Tue Jan 27 13:55:53 2009
@@ -31,15 +31,7 @@
result.setFile(file);
GenericFileConfiguration config = new GenericFileConfiguration();
-
- // TODO: This code should be looked at, the parent stuff is might not needed
- File parent = file.getParentFile();
- if (parent != null) {
- file = new File(parent, file.getName());
- }
config.setFile(file.getPath());
- config.setDirectory(file.isDirectory());
-
result.setConfiguration(config);
NewFileOperations operations = new NewFileOperations(result, file);
@@ -50,6 +42,5 @@
protected void afterPropertiesSet(GenericFileEndpoint<File> endpoint) throws Exception {
// noop
- // TODO: Could be a noop in parent and only override if needed
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileConsumer.java Tue Jan 27 13:55:53 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.file;
import java.io.File;
+import java.io.IOException;
import java.util.List;
import org.apache.camel.Processor;
@@ -41,6 +42,11 @@
log.trace("Polling directory: " + fileOrDirectory.getPath());
}
File[] files = fileOrDirectory.listFiles();
+
+ if (files == null || files.length == 0) {
+ // no files in this directory to poll
+ return;
+ }
for (File file : files) {
// createa a generic file
GenericFile<File> gf = asGenericFile(file);
@@ -79,7 +85,13 @@
}
- protected GenericFile<File> asGenericFile(File file) {
+ /**
+ * Creates a new GenericFile<File> based on the given file.
+ *
+ * @param file the source file
+ * @return wrapped as a GenericFile
+ */
+ public static GenericFile<File> asGenericFile(File file) {
GenericFile<File> answer = new GenericFile<File>();
// use file specific binding
answer.setBinding(new NewFileBinding());
@@ -87,6 +99,11 @@
answer.setFileLength(file.length());
answer.setFileName(file.getName());
answer.setAbsoluteFileName(file.getAbsolutePath());
+ try {
+ answer.setCanonicalFileName(file.getCanonicalPath());
+ } catch (IOException e) {
+ // ignore
+ }
answer.setLastModified(file.lastModified());
if (file.getParent() != null) {
answer.setRelativeFileName(file.getParent() + "/" + file.getName());
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileEndpoint.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileEndpoint.java Tue Jan 27 13:55:53 2009
@@ -32,10 +32,14 @@
private File file;
public NewFileEndpoint() {
+ // use marker file as default exclusive read locks
+ this.readLock = "markerFile";
}
public NewFileEndpoint(String endpointUri, Component component) {
super(endpointUri, component);
+ // use marker file as default exclusive read locks
+ this.readLock = "markerFile";
}
public NewFileConsumer createConsumer(Processor processor) throws Exception {
@@ -100,4 +104,10 @@
// TODO change to file when this is ready
return "newfile";
}
+
+ @Override
+ protected String createEndpointUri() {
+ return "file://" + getFile().getAbsolutePath();
+ }
+
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/NewFileOperations.java Tue Jan 27 13:55:53 2009
@@ -60,23 +60,32 @@
return file.renameTo(target);
}
- public boolean buildDirectory(String directory) throws GenericFileOperationFailedException {
- File dir = new File(directory);
- if (dir.exists()) {
- return true;
+ public boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException {
+ // always create endpoint defined directory
+ if (endpoint.isAutoCreate() && endpoint.isDirectory() && !endpoint.getFile().exists()) {
+ endpoint.getFile().mkdirs();
}
- return dir.mkdirs();
- }
- public String getCurrentDirectory(File file) throws GenericFileOperationFailedException {
- return file.getPath();
- }
+ File path;
+ if (absolute) {
+ path = new File(directory);
+ } else {
+ // skip trailing endpoint configued filename as we always start with the endoint file
+ // for creating relative directories
+ if (directory.startsWith(endpoint.getFile().getPath())) {
+ directory = directory.substring(endpoint.getFile().getPath().length());
+ }
+ path = new File(endpoint.getFile(), directory);
+ }
- public File changeCurrentDirectory(File file, String path) throws GenericFileOperationFailedException {
- return new File(path);
+ if (path.isDirectory() && path.exists()) {
+ // the directory already exists
+ return true;
+ } else {
+ return path.mkdirs();
+ }
}
-
public List<File> listFiles() throws GenericFileOperationFailedException {
return Arrays.asList(this.currentFile.listFiles());
}
@@ -85,12 +94,12 @@
return Arrays.asList(new File(this.currentFile, path).listFiles());
}
- public List<File> listFiles(File file) throws GenericFileOperationFailedException {
- return Arrays.asList(file.listFiles());
+ public void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
+ this.currentFile = new File(this.currentFile, path).getAbsoluteFile();
}
- public List<File> listFiles(File file, String path) throws GenericFileOperationFailedException {
- return listFiles(new File(path));
+ public String getCurrentDirectory() throws GenericFileOperationFailedException {
+ return currentFile.getAbsolutePath();
}
public boolean retrieveFile(String name, GenericFileExchange<File> exchange) throws GenericFileOperationFailedException {
@@ -177,12 +186,4 @@
return out;
}
- public void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
- this.currentFile = new File(this.currentFile, path).getAbsoluteFile();
- }
-
- public String getCurrentDirectory() throws GenericFileOperationFailedException {
- return currentFile.getAbsolutePath();
- }
-
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java Tue Jan 27 13:55:53 2009
@@ -38,8 +38,6 @@
*/
public abstract class FileProcessStrategySupport implements FileProcessStrategy {
- // TODO: Should be suppored by NewFile
-
private static final transient Log LOG = LogFactory.getLog(FileProcessStrategySupport.class);
private boolean lockFile;
private FileRenamer lockFileRenamer;
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=738093&r1=738092&r2=738093&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 Tue Jan 27 13:55:53 2009
@@ -26,6 +26,9 @@
@Override
public void commit(GenericFileOperations operations, GenericFileEndpoint endpoint, GenericFileExchange exchange, GenericFile file) throws Exception {
+ // must invoke super
+ super.commit(operations, endpoint, exchange, file);
+
boolean deleted = operations.deleteFile(file.getAbsoluteFileName());
if (!deleted) {
throw new GenericFileOperationFailedException("Cannot delete file: " + file);
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java Tue Jan 27 13:55:53 2009
@@ -23,13 +23,13 @@
import org.apache.camel.component.file.GenericFileOperations;
import org.apache.camel.component.file.GenericFileProcessStrategy;
-public abstract class GenericFileProcessStrategySupport implements GenericFileProcessStrategy {
+public abstract class GenericFileProcessStrategySupport<T> implements GenericFileProcessStrategy<T> {
private GenericFileExclusiveReadLockStrategy exclusiveReadLockStrategy;
- public boolean begin(GenericFileOperations operations, GenericFileEndpoint endpoint, GenericFileExchange exchange, GenericFile file) throws Exception {
+ public boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception {
// is we use excluse read then acquire the exclusive read (waiting until we got it)
if (exclusiveReadLockStrategy != null) {
- boolean lock = exclusiveReadLockStrategy.acquireExclusiveReadLock(operations, file);
+ boolean lock = exclusiveReadLockStrategy.acquireExclusiveReadLock(operations, file, exchange);
if (!lock) {
// do not begin sice we could not get the exclusive read lcok
return false;
@@ -39,15 +39,15 @@
return true;
}
- public void commit(GenericFileOperations operations, GenericFileEndpoint endpoint, GenericFileExchange exchange, GenericFile file) throws Exception {
+ public void commit(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception {
if (exclusiveReadLockStrategy != null) {
- exclusiveReadLockStrategy.releaseExclusiveReadLock(operations, file);
+ exclusiveReadLockStrategy.releaseExclusiveReadLock(operations, file, exchange);
}
}
- public void rollback(GenericFileOperations operations, GenericFileEndpoint endpoint, GenericFileExchange exchange, GenericFile file) {
+ public void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception {
if (exclusiveReadLockStrategy != null) {
- exclusiveReadLockStrategy.releaseExclusiveReadLock(operations, file);
+ exclusiveReadLockStrategy.releaseExclusiveReadLock(operations, file, exchange);
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java Tue Jan 27 13:55:53 2009
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file.strategy;
+import org.apache.camel.Exchange;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
import org.apache.camel.component.file.GenericFileOperations;
@@ -31,7 +32,8 @@
private static final transient Log LOG = LogFactory.getLog(GenericFileRenameExclusiveReadLockStrategy.class);
private long timeout;
- public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file) {
+ public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file,
+ Exchange exchange) throws Exception {
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for exclusive read lock to file: " + file);
}
@@ -73,7 +75,8 @@
return true;
}
- public void releaseExclusiveReadLock(GenericFileOperations genericFileOperations, GenericFile genericFile) {
+ public void releaseExclusiveReadLock(GenericFileOperations opeations, GenericFile file,
+ Exchange exchange) throws Exception {
// noop
}
@@ -94,8 +97,7 @@
* Sets an optional timeout period.
* <p/>
* If the readlock could not be granted within the timeperiod then the wait is stopped and the
- * {@link #acquireExclusiveReadLock(org.apache.camel.component.file.GenericFileOperations, org.apache.camel.component.file.GenericFile)}
- * acquireExclusiveReadLock} returns <tt>false</tt>.
+ * <tt>acquireExclusiveReadLock</tt> returns <tt>false</tt>.
*
* @param timeout period in millis
*/
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=738093&r1=738092&r2=738093&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 Tue Jan 27 13:55:53 2009
@@ -26,7 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class GenericFileRenameProcessStrategy extends GenericFileProcessStrategySupport {
+public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrategySupport<T> {
private static final transient Log LOG = LogFactory.getLog(org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy.class);
private GenericFileRenamer beginRenamer;
private GenericFileRenamer commitRenamer;
@@ -48,7 +48,13 @@
}
@Override
- public boolean begin(GenericFileOperations operations, GenericFileEndpoint endpoint, GenericFileExchange exchange, GenericFile file) throws Exception {
+ public boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception {
+ // must invoke super
+ boolean result = super.begin(operations, endpoint, exchange, file);
+ if (!result) {
+ return false;
+ }
+
if (beginRenamer != null) {
GenericFile newName = beginRenamer.renameFile(exchange, file);
GenericFile to = renameFile(operations, file, newName);
@@ -59,7 +65,10 @@
}
@Override
- public void commit(GenericFileOperations operations, GenericFileEndpoint endpoint, GenericFileExchange exchange, GenericFile file) throws Exception {
+ public void commit(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, GenericFileExchange<T> exchange, GenericFile<T> file) throws Exception {
+ // must invoke super
+ super.commit(operations, endpoint, exchange, file);
+
if (commitRenamer != null) {
GenericFile newName = commitRenamer.renameFile(exchange, file);
renameFile(operations, file, newName);
@@ -75,10 +84,9 @@
}
// make parent folder if missing
- String parent = to.getParent();
- boolean mkdir = operations.buildDirectory(parent);
+ boolean mkdir = operations.buildDirectory(to.getParent(), true);
if (!mkdir) {
- throw new GenericFileOperationFailedException("Cannot create directory: " + parent + " (could be because of denied permissions)");
+ throw new GenericFileOperationFailedException("Can not create directory: " + to.getParent() + " (could be because of denied permissions)");
}
if (LOG.isDebugEnabled()) {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileLockExclusiveReadLockStrategy.java Tue Jan 27 13:55:53 2009
@@ -19,13 +19,15 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.nio.channels.Channel;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
-import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.Exchange;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
import org.apache.camel.component.file.GenericFileOperations;
+import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -39,17 +41,17 @@
private static final transient Log LOG = LogFactory.getLog(NewFileLockExclusiveReadLockStrategy.class);
private long timeout;
- public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file) {
+ public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, Exchange exchange)
+ throws Exception {
File target = new File(file.getAbsoluteFileName());
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for exclusive read lock to file: " + target);
}
- FileChannel channel = null;
try {
// try to acquire rw lock on the file before we can consume it
- channel = new RandomAccessFile(target, "rw").getChannel();
+ FileChannel channel = new RandomAccessFile(target, "rw").getChannel();
long start = System.currentTimeMillis();
boolean exclusive = false;
@@ -70,15 +72,17 @@
try {
lock = timeout > 0 ? channel.tryLock() : channel.lock();
} catch (IllegalStateException ex) {
- // Also catch the OverlappingFileLockException here
- // Do nothing here
+ // Also catch the OverlappingFileLockException here. Do nothing here
}
if (lock != null) {
if (LOG.isTraceEnabled()) {
LOG.trace("Acquired exclusive read lock: " + lock + " to file: " + target);
}
- // just release it now we dont want to hold it during the rest of the processing
- lock.release();
+
+ // store lock so we can release it later
+ exchange.setProperty("org.apache.camel.file.lock", lock);
+ exchange.setProperty("org.apache.camel.file.lock.fileName", target.getName());
+
exclusive = true;
} else {
sleep();
@@ -89,22 +93,29 @@
// such as AntiVirus or MS Office that has special locks for it's supported files
if (timeout == 0) {
// if not using timeout, then we cant retry, so rethrow
- throw new RuntimeCamelException(e);
+ throw e;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Cannot acquire read lock. Will try again.", e);
}
sleep();
- } finally {
- // must close channel
- ObjectHelper.close(channel, "while acquiring exclusive read lock for file: " + target, LOG);
}
return true;
}
- public void releaseExclusiveReadLock(GenericFileOperations<File> fileGenericFileOperations, GenericFile<File> fileGenericFile) {
- // TODO: release read lock from above, as we should hold id during processing
+ public void releaseExclusiveReadLock(GenericFileOperations<File> fileGenericFileOperations,
+ GenericFile<File> fileGenericFile, Exchange exchange) throws Exception {
+ FileLock lock = ExchangeHelper.getMandatoryProperty(exchange, "org.apache.camel.file.lock", FileLock.class);
+ String lockFileName = ExchangeHelper.getMandatoryProperty(exchange, "org.apache.camel.file.lock.filename", String.class);
+ Channel channel = lock.channel();
+ try {
+ lock.release();
+ }
+ finally {
+ // must close channel
+ ObjectHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName, LOG);
+ }
}
private void sleep() {
@@ -132,4 +143,4 @@
this.timeout = timeout;
}
-}
\ No newline at end of file
+}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileProcessStrategyFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileProcessStrategyFactory.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileProcessStrategyFactory.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewFileProcessStrategyFactory.java Tue Jan 27 13:55:53 2009
@@ -75,9 +75,10 @@
}
return strategy;
} else {
- // default strategy will do nothing
- GenericFileNoOpProcessStrategy strategy = new GenericFileNoOpProcessStrategy();
+ // default strategy will move files in a .camel/ subfolder
+ GenericFileRenameProcessStrategy strategy = new GenericFileRenameProcessStrategy();
strategy.setExclusiveReadLockStrategy(getExclusiveReadLockStrategy(params));
+ strategy.setCommitRenamer(new GenericFileDefaultRenamer(".camel/", ""));
return strategy;
}
}
@@ -108,7 +109,6 @@
}
return readLockStrategy;
} else if ("markerFile".equals(readLock)) {
- // TODO: marker file that is the stuff with the .camel file
GenericFileExclusiveReadLockStrategy readLockStrategy = new NewMarkerFileExclusiveReadLockStrategy();
return readLockStrategy;
}
@@ -116,4 +116,4 @@
return null;
}
-}
\ No newline at end of file
+}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NewMarkerFileExclusiveReadLockStrategy.java Tue Jan 27 13:55:53 2009
@@ -17,23 +17,70 @@
package org.apache.camel.component.file.strategy;
import java.io.File;
+import java.io.RandomAccessFile;
+import java.nio.channels.Channel;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import org.apache.camel.Exchange;
import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileExchange;
import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
import org.apache.camel.component.file.GenericFileOperations;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
*
*/
public class NewMarkerFileExclusiveReadLockStrategy implements GenericFileExclusiveReadLockStrategy<File> {
+ private static final transient Log LOG = LogFactory.getLog(NewMarkerFileExclusiveReadLockStrategy.class);
- public boolean acquireExclusiveReadLock(GenericFileOperations<File> fileGenericFileOperations, GenericFile<File> fileGenericFile) {
- // TODO create the .camelFile
- return false;
+ private GenericFileRenamer lockFileRenamer = new GenericFileDefaultRenamer("", ".camellock");
+
+ public boolean acquireExclusiveReadLock(GenericFileOperations<File> fileGenericFileOperations,
+ GenericFile<File> file, Exchange exchange) throws Exception {
+
+ GenericFile newFile = lockFileRenamer.renameFile((GenericFileExchange) exchange, file);
+ String lockFileName = newFile.getAbsoluteFileName();
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Locking the file: " + file + " using the lock file name: " + lockFileName);
+ }
+
+ FileChannel channel = new RandomAccessFile(lockFileName, "rw").getChannel();
+ FileLock lock = channel.lock();
+ if (lock != null) {
+ exchange.setProperty("org.apache.camel.file.marker.lock", lock);
+ exchange.setProperty("org.apache.camel.file.marker.filename", lockFileName);
+ return true;
+ } else {
+ return false;
+ }
}
- public void releaseExclusiveReadLock(GenericFileOperations<File> fileGenericFileOperations, GenericFile<File> fileGenericFile) {
- // delete the .camelFile
+ public void releaseExclusiveReadLock(GenericFileOperations<File> fileGenericFileOperations,
+ GenericFile<File> fileGenericFile, Exchange exchange) throws Exception {
+ FileLock lock = ExchangeHelper.getMandatoryProperty(exchange, "org.apache.camel.file.marker.lock", FileLock.class);
+ String lockFileName = ExchangeHelper.getMandatoryProperty(exchange, "org.apache.camel.file.marker.filename", String.class);
+ Channel channel = lock.channel();
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Unlocking file: " + lockFileName);
+ }
+ try {
+ lock.release();
+ } finally {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Deleting lock file: " + lockFileName);
+ }
+ File lockfile = new File(lockFileName);
+ lockfile.delete();
+
+ // must close channel
+ ObjectHelper.close(channel, "Closing channel", LOG);
+ }
}
public void setTimeout(long timeout) {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Tue Jan 27 13:55:53 2009
@@ -360,7 +360,7 @@
return endpointType.cast(endpoint);
} else {
throw new IllegalArgumentException("The endpoint is not of type: " + endpointType + " but is: "
- + endpoint);
+ + endpoint.getClass().getCanonicalName());
}
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java Tue Jan 27 13:55:53 2009
@@ -32,7 +32,7 @@
*/
public class FileAsyncRouteTest extends ContextTestSupport {
protected Object expectedBody = "Hello there!";
- protected String uri = "file:target/test-async-inbox?delete=true&consumer.delay=10000&recursive=true";
+ protected String uri = "newfile:target/test-async-inbox?delete=true&consumer.delay=10000&recursive=true";
private CountDownLatch receivedLatch = new CountDownLatch(1);
private CountDownLatch processingLatch = new CountDownLatch(1);
@@ -83,7 +83,8 @@
from(uri).thread(1).to("direct:a");
from("direct:a").process(new Processor() {
public void process(Exchange exchange) throws Exception {
- file.set((File)exchange.getIn().getBody());
+ Object body = exchange.getIn().getBody(GenericFile.class).getFile();
+ file.set((File) body);
// Simulate a processing delay..
receivedLatch.countDown();
processingLatch.await();
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java Tue Jan 27 13:55:53 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.file;
import java.io.File;
+import java.io.IOException;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
@@ -37,24 +38,24 @@
}
};
public void testUriConfigurations() throws Exception {
- assertFileEndpoint("file://target/foo/bar", EXPECT_PATH);
- assertFileEndpoint("file://target/foo/bar?delete=true", EXPECT_PATH);
- assertFileEndpoint("file:target/foo/bar?delete=true", EXPECT_PATH);
- assertFileEndpoint("file:target/foo/bar", EXPECT_PATH);
- assertFileEndpoint("file://target/foo/bar/", EXPECT_PATH);
- assertFileEndpoint("file://target/foo/bar/?delete=true", EXPECT_PATH);
- assertFileEndpoint("file:target/foo/bar/?delete=true", EXPECT_PATH);
- assertFileEndpoint("file:target/foo/bar/", EXPECT_PATH);
- assertFileEndpoint("file:/target/foo/bar/", File.separator + EXPECT_PATH);
- assertFileEndpoint("file:/", File.separator);
- assertFileEndpoint("file:///", File.separator);
+ assertFileEndpoint("newfile://target/foo/bar", EXPECT_PATH);
+ assertFileEndpoint("newfile://target/foo/bar?delete=true", EXPECT_PATH);
+ assertFileEndpoint("newfile:target/foo/bar?delete=true", EXPECT_PATH);
+ assertFileEndpoint("newfile:target/foo/bar", EXPECT_PATH);
+ assertFileEndpoint("newfile://target/foo/bar/", EXPECT_PATH);
+ assertFileEndpoint("newfile://target/foo/bar/?delete=true", EXPECT_PATH);
+ assertFileEndpoint("newfile:target/foo/bar/?delete=true", EXPECT_PATH);
+ assertFileEndpoint("newfile:target/foo/bar/", EXPECT_PATH);
+ assertFileEndpoint("newfile:/target/foo/bar/", File.separator + EXPECT_PATH);
+ assertFileEndpoint("newfile:/", File.separator);
+ assertFileEndpoint("newfile:///", File.separator);
}
public void testConsumerConfigurations() throws Exception {
- FileConsumer consumer = createFileConsumer("file://target/foo/bar?recursive=true");
+ NewFileConsumer consumer = createFileConsumer("newfile://target/foo/bar?recursive=true");
assertNotNull(consumer);
try {
- createFileConsumer("file://target/foo/bar?recursiv=true");
+ createFileConsumer("newfile://target/foo/bar?recursiv=true");
fail("Expect a configure exception here");
} catch (Exception ex) {
assertTrue("Get the wrong exception type here", ex instanceof ResolveEndpointFailedException);
@@ -68,20 +69,22 @@
deleteDirectory("/target");
}
- private FileConsumer createFileConsumer(String endpointUri) throws Exception {
- FileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, FileEndpoint.class);
- return (FileConsumer)endpoint.createConsumer(DUMMY_PROCESSOR);
+ private NewFileConsumer createFileConsumer(String endpointUri) throws Exception {
+ NewFileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, NewFileEndpoint.class);
+ return endpoint.createConsumer(DUMMY_PROCESSOR);
}
- private void assertFileEndpoint(String endpointUri, String expectedPath) {
- FileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, FileEndpoint.class);
+ private void assertFileEndpoint(String endpointUri, String expectedPath) throws IOException {
+ NewFileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, NewFileEndpoint.class);
assertNotNull("Could not find endpoint: " + endpointUri, endpoint);
File file = endpoint.getFile();
String path = file.getPath();
assertEquals("For uri: " + endpointUri + " the file is not equal", expectedPath, path);
- File consumedFile = new File(expectedPath + (expectedPath.endsWith(File.separator) ? "" : File.separator) + EXPECT_FILE);
+ file = new File(expectedPath + (expectedPath.endsWith(File.separator) ? "" : File.separator) + EXPECT_FILE);
+ GenericFile consumedFile = NewFileConsumer.asGenericFile(file);
+
Message message = new DefaultMessage();
endpoint.configureMessage(consumedFile, message);
assertEquals(EXPECT_FILE, message.getHeader(FileComponent.HEADER_FILE_NAME));
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeFileOnlyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeFileOnlyTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeFileOnlyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeFileOnlyTest.java Tue Jan 27 13:55:53 2009
@@ -29,9 +29,9 @@
protected void setUp() throws Exception {
super.setUp();
deleteDirectory("target/fileonly");
- template.sendBodyAndHeader("file://target/fileonly", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
- template.sendBodyAndHeader("file://target/fileonly", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
- template.sendBodyAndHeader("file://target/fileonly/2008", "2008 Report", FileComponent.HEADER_FILE_NAME, "report2008.txt");
+ template.sendBodyAndHeader("newfile://target/fileonly", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
+ template.sendBodyAndHeader("newfile://target/fileonly", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
+ template.sendBodyAndHeader("newfile://target/fileonly/2008", "2008 Report", FileComponent.HEADER_FILE_NAME, "report2008.txt");
}
public void testConsumeFileOnly() throws Exception {
@@ -45,7 +45,7 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("file://target/fileonly/report.txt?recursive=false&delete=true").to("mock:result");
+ from("newfile://target/fileonly/report.txt?directory=false&recursive=false&delete=true").to("mock:result");
}
};
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java Tue Jan 27 13:55:53 2009
@@ -27,7 +27,7 @@
*/
public class FileConsumeMultipleDirectoriesTest extends ContextTestSupport {
- private String fileUrl = "file://target/multidir/?recursive=true&delete=true&consumer.delay=5000&sortBy=file:path";
+ private String fileUrl = "newfile://target/multidir/?recursive=true&delete=true&consumer.delay=5000&sortBy=file:path";
@Override
protected void setUp() throws Exception {
@@ -44,18 +44,18 @@
assertMockEndpointsSatisfied();
- FileExchange exchange = (FileExchange) mock.getExchanges().get(0);
- File file = exchange.getFile();
+ GenericFileExchange<File> exchange = (GenericFileExchange<File>) mock.getExchanges().get(0);
+ File file = exchange.getGenericFile().getFile();
assertFilePath("target/multidir/bye.txt", file.getPath());
assertEquals("bye.txt", file.getName());
- exchange = (FileExchange) mock.getExchanges().get(1);
- file = exchange.getFile();
+ exchange = (GenericFileExchange<File>) mock.getExchanges().get(1);
+ file = exchange.getGenericFile().getFile();
assertFilePath("target/multidir/sub/hello.txt", file.getPath());
assertEquals("hello.txt", file.getName());
- exchange = (FileExchange) mock.getExchanges().get(2);
- file = exchange.getFile();
+ exchange = (GenericFileExchange<File>) mock.getExchanges().get(2);
+ file = exchange.getGenericFile().getFile();
assertFilePath("target/multidir/sub/sub2/godday.txt", file.getPath());
assertEquals("godday.txt", file.getName());
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java Tue Jan 27 13:55:53 2009
@@ -39,7 +39,7 @@
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello Paris");
- template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+ template.sendBodyAndHeader("newfile:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
mock.assertIsSatisfied();
@@ -53,7 +53,7 @@
public void testIllegalOptions() throws Exception {
try {
- context.getEndpoint("file://target?expression=../done/${file:name}&delete=true").createConsumer(new Processor() {
+ context.getEndpoint("newfile://target?expression=../done/${file:name}&delete=true").createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -66,12 +66,11 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("file://target/reports?preMoveExpression=../inprogress/${file:name.noext}.bak&expression=../done/${file:name}&consumer.delay=5000")
+ from("newfile://target/reports?preMoveExpression=../inprogress/${file:name.noext}.bak&expression=../done/${file:name}&consumer.delay=5000")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
- FileExchange fe = (FileExchange) exchange;
- assertEquals("The file should have been move to inprogress",
- "inprogress", fe.getFile().getParentFile().getName());
+ GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
+ assertTrue(fe.getGenericFile().getRelativeFileName().indexOf("inprogress") > -1);
}
})
.to("mock:report");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java Tue Jan 27 13:55:53 2009
@@ -39,7 +39,7 @@
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello Paris");
- template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+ template.sendBodyAndHeader("newfile:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
mock.assertIsSatisfied();
@@ -53,7 +53,7 @@
public void testIllegalOptions() throws Exception {
try {
- context.getEndpoint("file://target?moveNamePrefix=../done/&delete=true").createConsumer(new Processor() {
+ context.getEndpoint("newfile://target?moveNamePrefix=../done/&delete=true").createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -63,7 +63,7 @@
}
try {
- context.getEndpoint("file://target?expression=${file:name.noext}.bak&delete=true").createConsumer(new Processor() {
+ context.getEndpoint("newfile://target?expression=${file:name.noext}.bak&delete=true").createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
@@ -76,12 +76,11 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("file://target/reports?preMoveNamePrefix=../inprogress/&moveNamePrefix=../done/&consumer.delay=5000")
+ from("newfile://target/reports?preMoveNamePrefix=../inprogress/&moveNamePrefix=../done/&consumer.delay=5000")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
- FileExchange fe = (FileExchange) exchange;
- assertEquals("The file should have been move to inprogress",
- "inprogress", fe.getFile().getParentFile().getName());
+ GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
+ assertTrue(fe.getGenericFile().getRelativeFileName().indexOf("inprogress") > -1);
}
})
.to("mock:report");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java Tue Jan 27 13:55:53 2009
@@ -38,7 +38,7 @@
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello Paris");
- template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+ template.sendBodyAndHeader("newfile:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
Thread.sleep(100);
@@ -60,7 +60,7 @@
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello London");
- template.sendBodyAndHeader("file:target/reports", "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt");
+ template.sendBodyAndHeader("newfile:target/reports", "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt");
Thread.sleep(100);
@@ -70,12 +70,11 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("file://target/reports?preMoveExpression=../inprogress/${file:name.noext}.bak&consumer.delay=5000")
+ from("newfile://target/reports?preMoveExpression=../inprogress/${file:name.noext}.bak&consumer.delay=5000")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
- FileExchange fe = (FileExchange) exchange;
- assertEquals("The file should have been move to inprogress",
- "inprogress", fe.getFile().getParentFile().getName());
+ GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
+ assertTrue(fe.getGenericFile().getRelativeFileName().indexOf("inprogress") > -1);
}
})
.to("mock:report");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java Tue Jan 27 13:55:53 2009
@@ -38,7 +38,7 @@
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello Paris");
- template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+ template.sendBodyAndHeader("newfile:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
Thread.sleep(100);
@@ -60,7 +60,7 @@
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello London");
- template.sendBodyAndHeader("file:target/reports", "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt");
+ template.sendBodyAndHeader("newfile:target/reports", "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt");
Thread.sleep(100);
@@ -70,12 +70,11 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("file://target/reports?preMoveNamePrefix=../inprogress/&consumer.delay=5000")
+ from("newfile://target/reports?preMoveNamePrefix=../inprogress/&consumer.delay=5000")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
- FileExchange fe = (FileExchange) exchange;
- assertEquals("The file should have been move to inprogress",
- "inprogress", fe.getFile().getParentFile().getName());
+ GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
+ assertTrue(fe.getGenericFile().getRelativeFileName().indexOf("inprogress") > -1);
}
})
.to("mock:report");
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java Tue Jan 27 13:55:53 2009
@@ -46,7 +46,7 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
- template.sendBodyAndHeader("file://target/filelanguage/", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
+ template.sendBodyAndHeader("newfile://target/filelanguage/", "Hello World", FileComponent.HEADER_FILE_NAME, "report.txt");
assertMockEndpointsSatisfied();
// give time for consumer to rename file
@@ -62,7 +62,7 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");
- template.sendBodyAndHeader("file://target/filelanguage/", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
+ template.sendBodyAndHeader("newfile://target/filelanguage/", "Bye World", FileComponent.HEADER_FILE_NAME, "report2.txt");
assertMockEndpointsSatisfied();
// give time for consumer to rename file
@@ -78,7 +78,7 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye Big World");
- template.sendBodyAndHeader("file://target/filelanguage/", "Bye Big World", FileComponent.HEADER_FILE_NAME, "report3.txt");
+ template.sendBodyAndHeader("newfile://target/filelanguage/", "Bye Big World", FileComponent.HEADER_FILE_NAME, "report3.txt");
assertMockEndpointsSatisfied();
// give time for consumer to rename file
@@ -93,7 +93,7 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello Big World");
- template.sendBodyAndHeader("file://target/filelanguage/", "Hello Big World", FileComponent.HEADER_FILE_NAME, "report4.txt");
+ template.sendBodyAndHeader("newfile://target/filelanguage/", "Hello Big World", FileComponent.HEADER_FILE_NAME, "report4.txt");
assertMockEndpointsSatisfied();
// give time for consumer to rename file
@@ -108,7 +108,7 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bean Language Rules The World");
- template.sendBodyAndHeader("file://target/filelanguage/", "Bean Language Rules The World",
+ template.sendBodyAndHeader("newfile://target/filelanguage/", "Bean Language Rules The World",
FileComponent.HEADER_FILE_NAME, "report5.txt");
assertMockEndpointsSatisfied();
@@ -124,24 +124,28 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("file://target/filelanguage/report.txt?autoCreate=false"
+ from("newfile://target/filelanguage/report.txt?directory=false&autoCreate=false"
+ "&expression=${id}.bak").to("mock:result");
- from("file://target/filelanguage/report2.txt?autoCreate=false"
+ from("newfile://target/filelanguage/report2.txt?directory=false&autoCreate=false"
+ "&expression=backup-${id}-${file:name.noext}.bak").to("mock:result");
- from("file://target/filelanguage/report3.txt?autoCreate=false"
+ from("newfile://target/filelanguage/report3.txt?directory=false&autoCreate=false"
+ "&expression=backup/${bean:myguidgenerator.guid}.txt").to("mock:result");
- from("file://target/filelanguage/report4.txt?autoCreate=false"
+ from("newfile://target/filelanguage/report4.txt?directory=false&autoCreate=false"
+ "&expression=../backup/${file:name}.bak").to("mock:result");
// configured by java using java beans setters
- FileEndpoint endpoint = new FileEndpoint();
+ NewFileEndpoint endpoint = new NewFileEndpoint();
endpoint.setCamelContext(context);
+ endpoint.getConfiguration().setFile("target/filelanguage/report5.txt");
endpoint.setFile(new File("target/filelanguage/report5.txt"));
+ endpoint.setOperations(new NewFileOperations(endpoint, endpoint.getFile()));
+ endpoint.setDirectory(false);
endpoint.setAutoCreate(false);
endpoint.setExpression(BeanLanguage.bean("myguidgenerator"));
+
from(endpoint).to("mock:result");
}
};
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileFilterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileFilterTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileFilterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileFilterTest.java Tue Jan 27 13:55:53 2009
@@ -16,9 +16,6 @@
*/
package org.apache.camel.component.file;
-import java.io.File;
-import java.io.FileFilter;
-
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -29,7 +26,7 @@
*/
public class FileConsumerFileFilterTest extends ContextTestSupport {
- private String fileUrl = "file://target/filefilter/?filter=#myFilter";
+ private String fileUrl = "newfile://target/filefilter/?filter=#myFilter";
@Override
protected JndiRegistry createRegistry() throws Exception {
@@ -48,7 +45,7 @@
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
- template.sendBodyAndHeader("file:target/filefilter/", "This is a file to be filtered",
+ template.sendBodyAndHeader("newfile:target/filefilter/", "This is a file to be filtered",
FileComponent.HEADER_FILE_NAME, "skipme.txt");
mock.setResultWaitTime(2000);
@@ -60,10 +57,10 @@
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello World");
- template.sendBodyAndHeader("file:target/filefilter/", "This is a file to be filtered",
+ template.sendBodyAndHeader("newfile:target/filefilter/", "This is a file to be filtered",
FileComponent.HEADER_FILE_NAME, "skipme.txt");
- template.sendBodyAndHeader("file:target/filefilter/", "Hello World",
+ template.sendBodyAndHeader("newfile:target/filefilter/", "Hello World",
FileComponent.HEADER_FILE_NAME, "hello.txt");
mock.assertIsSatisfied();
@@ -78,10 +75,10 @@
}
// START SNIPPET: e1
- public class MyFileFilter implements FileFilter {
- public boolean accept(File pathname) {
+ public class MyFileFilter implements GenericFileFilter {
+ public boolean accept(GenericFile pathname) {
// we dont accept any files starting with skip in the name
- return !pathname.getName().startsWith("skip");
+ return !pathname.getFileName().startsWith("skip");
}
}
// END SNIPPET: e1
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpLockFileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpLockFileTest.java?rev=738093&r1=738092&r2=738093&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpLockFileTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpLockFileTest.java Tue Jan 27 13:55:53 2009
@@ -41,7 +41,7 @@
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello Locked");
- template.sendBodyAndHeader("file:target/reports/locked", "Hello Locked",
+ template.sendBodyAndHeader("newfile:target/reports/locked", "Hello Locked",
FileComponent.HEADER_FILE_NAME, "report.txt");
mock.assertIsSatisfied();
@@ -59,7 +59,7 @@
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello Not Locked");
- template.sendBodyAndHeader("file:target/reports/notlocked", "Hello Not Locked",
+ template.sendBodyAndHeader("newfile:target/reports/notlocked", "Hello Not Locked",
FileComponent.HEADER_FILE_NAME, "report.txt");
mock.assertIsSatisfied();
@@ -84,11 +84,11 @@
return new RouteBuilder() {
public void configure() throws Exception {
// for locks
- from("file://target/reports/locked/?noop=true").process(new MyNoopProcessor()).
+ from("newfile://target/reports/locked/?noop=true").process(new MyNoopProcessor()).
to("mock:report");
// for no locks
- from("file://target/reports/notlocked/?noop=true&lock=false").process(new MyNoopProcessor()).
+ from("newfile://target/reports/notlocked/?noop=true&readLock=false").process(new MyNoopProcessor()).
to("mock:report");
}
};