camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r552516 - in /activemq/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/impl/ camel-core/src/main/java/org/ap...
Date Mon, 02 Jul 2007 15:49:57 GMT
Author: jstrachan
Date: Mon Jul  2 08:49:56 2007
New Revision: 552516

URL: http://svn.apache.org/viewvc?view=rev&rev=552516
Log:
added FileStrategy plugins so that you can easily lock/unlock and delete/move files when they
are processed to fix CAMEL-61; I've made moving files to ".camel/" the default behaviour.
Also fixed CAMEL-62 and tidied up some more URI handling code (zapping some cruft in camel-cxf)

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DeleteFileStrategy.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStategySupport.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStrategy.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NoOpFileStrategy.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileStrategy.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileDeleteRouteTest.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpRouteTest.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRenameRouteTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ResequencerTest.java
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
Mon Jul  2 08:49:56 2007
@@ -40,9 +40,7 @@
     }
 
     protected Endpoint<FileExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
-        URI u = new URI(uri);
-        String schemeSpecificPart = u.getSchemeSpecificPart();
-        File file = new File(schemeSpecificPart);
+        File file = new File(remaining);
         FileEndpoint result = new FileEndpoint(file, uri, this);
         IntrospectionSupport.setProperties(result, parameters);
         return result;

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
Mon Jul  2 08:49:56 2007
@@ -18,14 +18,12 @@
 package org.apache.camel.component.file;
 
 import org.apache.camel.Processor;
+import org.apache.camel.component.file.strategy.FileStrategy;
 import org.apache.camel.impl.ScheduledPollConsumer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
 
 /**
  * @version $Revision: 523016 $
@@ -34,7 +32,6 @@
     private static final transient Log log = LogFactory.getLog(FileConsumer.class);
     private final FileEndpoint endpoint;
     private boolean recursive = true;
-    private boolean attemptFileLock = false;
     private String regexPattern = "";
     private long lastPollTime = 0l;
 
@@ -53,10 +50,12 @@
             pollFile(fileOrDirectory); // process the file
         }
         else if (processDir) {
-            log.debug("Polling directory " + fileOrDirectory);
-            File[] files = fileOrDirectory.listFiles();
-            for (int i = 0; i < files.length; i++) {
-                pollFileOrDirectory(files[i], isRecursive()); // self-recursion
+            if (isValidFile(fileOrDirectory)) {
+                log.debug("Polling directory " + fileOrDirectory);
+                File[] files = fileOrDirectory.listFiles();
+                for (int i = 0; i < files.length; i++) {
+                    pollFileOrDirectory(files[i], isRecursive()); // self-recursion
+                }
             }
         }
         else {
@@ -67,62 +66,51 @@
     protected void pollFile(final File file) {
         if (file.exists() && file.lastModified() > lastPollTime) {
             if (isValidFile(file)) {
-                processFile(file);
-                deleteOrMoveFile(file);
+                FileStrategy strategy = endpoint.getFileStrategy();
+                FileExchange exchange = endpoint.createExchange(file);
+
+                try {
+                    if (strategy.begin(endpoint, exchange, file)) {
+                        getProcessor().process(exchange);
+                        strategy.commit(endpoint, exchange, file);
+                    }
+                    else {
+                        if (log.isDebugEnabled()) {
+                            log.debug(endpoint + " cannot process file: " + file);
+                        }
+                    }
+                }
+                catch (Throwable e) {
+                    handleException(e);
+                }
             }
         }
     }
 
-    protected void deleteOrMoveFile(File file) {
-        file.delete();
-    }
-
-    protected void processFile(File file) {
-        try {
-			getProcessor().process(endpoint.createExchange(file));
-		} catch (Throwable e) {
-			handleException(e);
-		}
-    }
-
     protected boolean isValidFile(File file) {
         boolean result = false;
         if (file != null && file.exists()) {
             if (isMatched(file)) {
-                if (isAttemptFileLock()) {
-                    FileChannel fc = null;
-                    try {
-                        fc = new RandomAccessFile(file, "rw").getChannel();
-                        fc.lock();
-                        result = true;
-                    }
-                    catch (Throwable e) {
-                        log.debug("Failed to get the lock on file: " + file, e);
-                    }
-                    finally {
-                        if (fc != null) {
-                            try {
-                                fc.close();
-                            }
-                            catch (IOException e) {
-                            }
-                        }
-                    }
-                }
-                else {
-                    result = true;
-                }
+                result = true;
             }
         }
         return result;
     }
 
     protected boolean isMatched(File file) {
-        boolean result = true;
+        String name = file.getName();
         if (regexPattern != null && regexPattern.length() > 0) {
-            result = file.getName().matches(getRegexPattern());
+            if (!name.matches(getRegexPattern())) {
+                return false;
+            }
         }
-        return result;
+        String[] prefixes = endpoint.getExcludedNamePrefixes();
+        for (String prefix : prefixes) {
+            if (name.startsWith(prefix)) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /**
@@ -137,20 +125,6 @@
      */
     public void setRecursive(boolean recursive) {
         this.recursive = recursive;
-    }
-
-    /**
-     * @return the attemptFileLock
-     */
-    public boolean isAttemptFileLock() {
-        return this.attemptFileLock;
-    }
-
-    /**
-     * @param attemptFileLock the attemptFileLock to set
-     */
-    public void setAttemptFileLock(boolean attemptFileLock) {
-        this.attemptFileLock = attemptFileLock;
     }
 
     /**

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Mon Jul  2 08:49:56 2007
@@ -20,6 +20,10 @@
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.component.file.strategy.DeleteFileStrategy;
+import org.apache.camel.component.file.strategy.FileStrategy;
+import org.apache.camel.component.file.strategy.RenameFileStrategy;
+import org.apache.camel.component.file.strategy.NoOpFileStrategy;
 import org.apache.camel.impl.ScheduledPollEndpoint;
 
 import java.io.File;
@@ -31,7 +35,14 @@
  */
 public class FileEndpoint extends ScheduledPollEndpoint<FileExchange> {
     private File file;
-    private boolean autoCreate=true;
+    private FileStrategy fileStrategy;
+    private boolean autoCreate = true;
+    private boolean lock = true;
+    private boolean delete = false;
+    private boolean noop = false;
+    private String moveNamePrefix = null;
+    private String moveNamePostfix = null;
+    private String[] excludedNamePrefixes = { "." };
 
     protected FileEndpoint(File file, String endpointUri, FileComponent component) {
         super(endpointUri, component);
@@ -88,19 +99,129 @@
         return true;
     }
 
-    
     /**
      * @return the autoCreate
      */
-    public boolean isAutoCreate(){
+    public boolean isAutoCreate() {
         return this.autoCreate;
     }
 
-    
     /**
      * @param autoCreate the autoCreate to set
      */
-    public void setAutoCreate(boolean autoCreate){
-        this.autoCreate=autoCreate;
+    public void setAutoCreate(boolean autoCreate) {
+        this.autoCreate = autoCreate;
     }
+
+    public FileStrategy getFileStrategy() {
+        if (fileStrategy == null) {
+            fileStrategy = createFileStrategy();
+        }
+        return fileStrategy;
+    }
+
+    /**
+     * Sets the strategy to be used when the file has been processed
+     * such as deleting or renaming it etc.
+     *
+     * @param fileStrategy the new stategy to use
+     */
+    public void setFileStrategy(FileStrategy fileStrategy) {
+        this.fileStrategy = fileStrategy;
+    }
+
+    public boolean isDelete() {
+        return delete;
+    }
+
+    public void setDelete(boolean delete) {
+        this.delete = delete;
+    }
+
+    public boolean isLock() {
+        return lock;
+    }
+
+    public void setLock(boolean lock) {
+        this.lock = lock;
+    }
+
+    public String getMoveNamePostfix() {
+        return moveNamePostfix;
+    }
+
+    /**
+     * Sets the name postfix appended to moved files. For example
+     * to rename all the files from * to *.done set this value to ".done"
+     *
+     * @see RenameFileStrategy#setNamePostfix(String)
+
+     * @param moveNamePostfix
+     */
+    public void setMoveNamePostfix(String moveNamePostfix) {
+        this.moveNamePostfix = moveNamePostfix;
+    }
+
+    public String getMoveNamePrefix() {
+        return moveNamePrefix;
+    }
+
+    /**
+     * Sets the name prefix appended to moved files. For example
+     * to move processed files into a hidden directory called ".camel"
+     * set this value to ".camel/"
+     *
+     * @see RenameFileStrategy#setNamePrefix(String)
+     */
+    public void setMoveNamePrefix(String moveNamePrefix) {
+        this.moveNamePrefix = moveNamePrefix;
+    }
+
+    public String[] getExcludedNamePrefixes() {
+        return excludedNamePrefixes;
+    }
+
+    /**
+     * Sets the excluded file name prefixes, such as "." for hidden files
+     * which are excluded by default
+     */
+    public void setExcludedNamePrefixes(String[] excludedNamePrefixes) {
+        this.excludedNamePrefixes = excludedNamePrefixes;
+    }
+
+    public boolean isNoop() {
+        return noop;
+    }
+
+    /**
+     * If set to true then the default {@link FileStrategy} will be to use
+     * the {@link NoOpFileStrategy} to not move or copy processed files
+     *
+     * @param noop
+     */
+    public void setNoop(boolean noop) {
+        this.noop = noop;
+    }
+
+    /**
+     * A strategy method to lazily create the file strategy
+     */
+    protected FileStrategy createFileStrategy() {
+        if (moveNamePostfix != null || moveNamePrefix != null) {
+            if (isDelete()) {
+                throw new IllegalArgumentException("You cannot set the deleteFiles property
and a moveFilenamePostfix or moveFilenamePrefix");
+            }
+            return new RenameFileStrategy(isLock(), moveNamePrefix, moveNamePostfix);
+        }
+        else if (isDelete()) {
+            return new DeleteFileStrategy(isLock());
+        }
+        else if (isNoop()) {
+            return new NoOpFileStrategy(isLock());
+        }
+        else {
+            return new RenameFileStrategy(isLock());
+        }
+    }
+
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DeleteFileStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DeleteFileStrategy.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DeleteFileStrategy.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DeleteFileStrategy.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,49 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.strategy;
+
+import org.apache.camel.component.file.FileEndpoint;
+import org.apache.camel.component.file.FileExchange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+
+/**
+ * A strategy which will delete the file when its processed
+ *
+ * @version $Revision: 1.1 $
+ */
+public class DeleteFileStrategy extends FileStategySupport {
+    private static final transient Log log = LogFactory.getLog(DeleteFileStrategy.class);
+
+    public DeleteFileStrategy() {
+    }
+
+    public DeleteFileStrategy(boolean lockFile) {
+        super(lockFile);
+    }
+
+    public void commit(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception
{
+        if (log.isDebugEnabled()) {
+            log.debug("Deleting file: " + file);
+        }
+        file.delete();
+        super.commit(endpoint, exchange, file);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DeleteFileStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStategySupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStategySupport.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStategySupport.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStategySupport.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,88 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.strategy;
+
+import org.apache.camel.component.file.FileEndpoint;
+import org.apache.camel.component.file.FileExchange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.Channel;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public abstract class FileStategySupport implements FileStrategy {
+    private static final transient Log log = LogFactory.getLog(FileStategySupport.class);
+
+    private boolean lockFile;
+
+    protected FileStategySupport() {
+        this(true);
+    }
+
+    protected FileStategySupport(boolean lockFile) {
+        this.lockFile = lockFile;
+    }
+
+    public boolean begin(FileEndpoint endpoint, FileExchange exchange, File file) throws
Exception {
+        if (isLockFile() ) {
+            if (log.isDebugEnabled()) {
+                log.debug("Locking file: " + file);
+            }
+
+            FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
+            FileLock lock = channel.lock();
+            if (lock != null) {
+                exchange.setProperty("org.apache.camel.fileChannel", channel);
+                exchange.setProperty("org.apache.camel.file.lock", lock);
+                return true;
+            }
+            return false;
+        }
+        return true;
+    }
+
+    public void commit(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception
{
+        if (isLockFile()) {
+            Channel channel = exchange.getProperty("org.apache.camel.fileChannel", Channel.class);
+            if (channel != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Unlocking file: " + file);
+                }
+
+                channel.close();
+            }
+            else {
+                throw new Exception("No Channel available to close on exchange: " + exchange);
+            }
+        }
+    }
+
+    public boolean isLockFile() {
+        return lockFile;
+    }
+
+    public void setLockFile(boolean lockFile) {
+        this.lockFile = lockFile;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStategySupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStrategy.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStrategy.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStrategy.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,43 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.strategy;
+
+import org.apache.camel.component.file.FileEndpoint;
+import org.apache.camel.component.file.FileExchange;
+
+import java.io.File;
+
+/**
+ * Represents a strategy for marking that a file is processed.
+ *
+ * @version $Revision: 1.1 $
+ */
+public interface FileStrategy {
+    /**
+     * Called when work is about to begin on this file. This method may attempt to acquire
some file lock before
+     * returning true; returning false if the file lock could not be obtained so that the
file should be ignored.
+     *
+     * @return true if the file can be processed (such as if a file lock could be obtained)
+     */
+    boolean begin(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception;
+
+    /**
+     * Releases any file locks and possibly deletes or moves the file
+     */
+    public void commit(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception;
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NoOpFileStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NoOpFileStrategy.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NoOpFileStrategy.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NoOpFileStrategy.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.strategy;
+
+/**
+ * A simple strategy which just locks the file but does not modify it
+ *
+ * @version $Revision: 1.1 $
+ */
+public class NoOpFileStrategy extends FileStategySupport {
+    public NoOpFileStrategy() {
+    }
+
+    public NoOpFileStrategy(boolean lockFile) {
+        super(lockFile);
+    }
+}
+

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/NoOpFileStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileStrategy.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileStrategy.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileStrategy.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,93 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.strategy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.camel.component.file.FileEndpoint;
+import org.apache.camel.component.file.FileExchange;
+
+import java.io.File;
+
+/**
+ * A strategy to rename a file
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class RenameFileStrategy extends FileStategySupport {
+    private static final transient Log log = LogFactory.getLog(RenameFileStrategy.class);
+
+    private String namePrefix;
+    private String namePostfix;
+
+    public RenameFileStrategy() {
+        this(true);
+    }
+
+    public RenameFileStrategy(boolean lock) {
+        this(lock, ".camel/", "");
+    }
+
+    public RenameFileStrategy(boolean lock, String namePrefix, String namePostfix) {
+        super(lock);
+        if (namePrefix != null) {
+            this.namePrefix = namePrefix;
+        }
+        if (namePostfix != null) {
+            this.namePostfix = namePostfix;
+        }
+    }
+
+    public void commit(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception
{
+        File parent = file.getParentFile();
+        String name = getNamePrefix() + file.getName() + getNamePostfix();
+        File newName = new File(parent, name);
+        newName.getParentFile().mkdirs();
+
+        if (log.isDebugEnabled()) {
+            log.debug("Renaming file: " + file + " to: " + newName);
+        }
+        file.renameTo(newName);
+        super.commit(endpoint, exchange, file);
+    }
+
+    public String getNamePostfix() {
+        return namePostfix;
+    }
+
+    /**
+     * Sets the name postfix appended to moved files. For example
+     * to rename all the files from * to *.done set this value to ".done"
+     */
+    public void setNamePostfix(String namePostfix) {
+        this.namePostfix = namePostfix;
+    }
+
+    public String getNamePrefix() {
+        return namePrefix;
+    }
+
+    /**
+     * Sets the name prefix appended to moved files. For example
+     * to move processed files into a hidden directory called ".camel"
+     * set this value to ".camel/"
+     */
+    public void setNamePrefix(String namePrefix) {
+        this.namePrefix = namePrefix;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
Mon Jul  2 08:49:56 2007
@@ -51,9 +51,15 @@
     public Endpoint<E> createEndpoint(String uri) throws Exception {
         ObjectHelper.notNull(getCamelContext(), "camelContext");        
         URI u = new URI(uri);
-        String path = u.getHost();
-        if (path == null) {
-            path = u.getSchemeSpecificPart();
+        String path = u.getSchemeSpecificPart();
+        
+        // lets trim off any query arguments
+        if (path.startsWith("//")) {
+            path = path.substring(2);
+        }
+        int idx = path.indexOf('?');
+        if (idx > 0) {
+            path = path.substring(0, idx);
         }
         Map parameters = URISupport.parseParamters(u);
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
Mon Jul  2 08:49:56 2007
@@ -23,11 +23,14 @@
 import org.apache.camel.Producer;
 import org.apache.camel.Service;
 import org.apache.camel.impl.ServiceSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * @version $Revision$
  */
 public class SendProcessor extends ServiceSupport implements Processor, Service {
+    private static final transient Log log = LogFactory.getLog(SendProcessor.class);
     private Endpoint destination;
     private Producer producer;
 
@@ -52,9 +55,16 @@
 
     public void process(Exchange exchange) throws Exception {
         if (producer == null) {
-            throw new IllegalStateException("No producer, this processor has not been started!");
+            if (isStopped()) {
+                log.warn("Ignoring exchange sent after processor is stopped: " + exchange);
+            }
+            else {
+                throw new IllegalStateException("No producer, this processor has not been
started!");
+            }
+        }
+        else {
+            producer.process(exchange);
         }
-        producer.process(exchange);
     }
 
     public Endpoint getDestination() {

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,44 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import org.apache.camel.ContextTestSupport;
+
+import java.io.File;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class FileConfigureTest extends ContextTestSupport {
+
+    public void testUriConfigurations() throws Exception {
+        assertFileEndpoint("file://target/foo/bar", "target/foo/bar");
+        assertFileEndpoint("file://target/foo/bar?delete=true", "target/foo/bar");
+        assertFileEndpoint("file:target/foo/bar?delete=true", "target/foo/bar");
+        assertFileEndpoint("file:target/foo/bar", "target/foo/bar");
+    }
+
+    private void assertFileEndpoint(String endpointUri, String expectedPath) {
+        FileEndpoint endpoint = resolveMandatoryEndpoint(endpointUri, FileEndpoint.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);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileDeleteRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileDeleteRouteTest.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileDeleteRouteTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileDeleteRouteTest.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,29 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class FileDeleteRouteTest extends FileRouteTest {
+    @Override
+    protected void setUp() throws Exception {
+        uri = "file:target/test-rename-inbox?delete=true";
+        super.setUp();
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileDeleteRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpRouteTest.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpRouteTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpRouteTest.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,42 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import java.io.File;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class FileNoOpRouteTest extends FileRouteTest {
+    @Override
+    protected void setUp() throws Exception {
+        uri = "file:target/test-noop-inbox?noop=true";
+
+        // lets delete all the files
+        File oldDir = new File("target/test-noop-inbox");
+        if (oldDir.exists()) {
+            File parentDir = oldDir.getParentFile();
+            File[] files = parentDir.listFiles();
+            File newName = new File(parentDir, oldDir.getName() + "-" + (files.length + 1));
+            log.debug("renaming old output: " + oldDir + " to: " + newName);
+            oldDir.renameTo(newName);
+        }
+
+        super.setUp();
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileNoOpRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRenameRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRenameRouteTest.java?view=auto&rev=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRenameRouteTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRenameRouteTest.java
Mon Jul  2 08:49:56 2007
@@ -0,0 +1,29 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class FileRenameRouteTest extends FileRouteTest {
+    @Override
+    protected void setUp() throws Exception {
+        uri = "file:target/test-rename-inbox?moveNamePrefix=.foo/";
+        super.setUp();
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRenameRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java
Mon Jul  2 08:49:56 2007
@@ -26,7 +26,7 @@
  */
 public class FileRouteTest extends ContextTestSupport {
     protected Object expectedBody = "Hello there!";
-    protected String uri = "file:target/test-inbox";
+    protected String uri = "file:target/test-default-inbox";
 
     public void testFileRoute() throws Exception {
         MockEndpoint result = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ResequencerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ResequencerTest.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ResequencerTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ResequencerTest.java
Mon Jul  2 08:49:56 2007
@@ -40,7 +40,7 @@
         resultEndpoint.assertIsSatisfied();
         List<Exchange> list = resultEndpoint.getReceivedExchanges();
         for (Exchange exchange : list) {
-            log.info("Received: " + exchange);
+            log.debug("Received: " + exchange);
         }
     }
 

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeComponent.java
Mon Jul  2 08:49:56 2007
@@ -44,39 +44,13 @@
 
     @Override
     protected Endpoint<CxfExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
-        return new CxfInvokeEndpoint(getAddress(remaining), this, getQueryAsProperties(new
URI(remaining)));
+        return new CxfInvokeEndpoint(remaining, this, createProperties(parameters));
     }
 
-    /**
-     * Read query parameters from uri
-     *
-     * @param u
-     * @return parameter value pairs as properties
-     */
-    protected Properties getQueryAsProperties(URI u) {
-        Properties retval = new Properties();
-        if (u.getQuery() != null) {
-            String[] parameters = u.getQuery().split("&");
-            for (int i = 0; i < parameters.length; i++) {
-                String[] s = parameters[i].split("=");
-                retval.put(s[0], s[1]);
-            }
-        }
-        return retval;
-    }
-
-    /**
-     * Remove query from uri
-     *
-     * @param uri
-     * @return substring before  the "?" character
-     */
-    protected String getAddress(String uri) {
-        int index = uri.indexOf("?");
-        if (-1 != index) {
-            return uri.substring(0, index);
-        }
-        return uri;
+    protected Properties createProperties(Map parameters) {
+        Properties answer = new Properties();
+        answer.putAll(parameters);
+        return answer;
     }
 
     public Bus getBus() {

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java?view=diff&rev=552516&r1=552515&r2=552516
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfInvokeProducer.java
Mon Jul  2 08:49:56 2007
@@ -19,6 +19,7 @@
 
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.Exchange;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientFactoryBean;
@@ -69,7 +70,9 @@
             ClientFactoryBean cfBean = new ClientFactoryBean();
             cfBean.setAddress(getEndpoint().getEndpointUri());
             cfBean.setBus(endpoint.getBus());
-            cfBean.setServiceClass(Class.forName(endpoint.getProperty(CxfConstants.SEI)));
+            String className = endpoint.getProperty(CxfConstants.SEI);
+            Class type = ObjectHelper.loadClass(className);
+            cfBean.setServiceClass(type);
             client = cfBean.create();
         }
     }



Mime
View raw message