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/26 12:52:07 UTC
svn commit: r737677 [1/2] - in /camel/trunk/components/camel-ftp/src:
main/java/org/apache/camel/component/file/remote/
main/java/org/apache/camel/component/file/remote/strategy/
main/resources/META-INF/services/org/apache/camel/component/ test/java/or...
Author: davsclaus
Date: Mon Jan 26 11:52:06 2009
New Revision: 737677
URL: http://svn.apache.org/viewvc?rev=737677&view=rev
Log:
CAMEL-1241: Refactored FTP to use camel VFS.
Added:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java (with props)
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java (with props)
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java (with props)
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpRemoteFileComponent.java (with props)
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpRemoteFileConfiguration.java (with props)
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpRemoteFileEndpoint.java (with props)
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpDefaultRootRenameStrategyTest.java (with props)
Removed:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/AntPathMatcherRemoteFileFilter.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileFilter.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProcessStrategy.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.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/RemoteFileConverter.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/RemoteFileExchange.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExclusiveReadLockStrategy.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpRemoteFileOperations.java
camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/component/ftp
camel/trunk/components/camel-ftp/src/main/resources/META-INF/services/org/apache/camel/component/sftp
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpDeleteFileTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpExclusiveReadNoneStrategyTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpExclusiveReadRenameStrategyTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpFilterTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpMoveFilePostfixTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpMoveFilePrefixTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpMoveFileTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNoFilesTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNoopTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpPassiveModeTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpPreMoveFileExpressionTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpPreMoveFilePostfixTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpPreMoveFilePrefixTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileFilterTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinarySampleTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromQueueThenConsumeFtpToMockTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerIdempotentRefTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerWithNoFileOptionTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpLoginTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerBuildDirectoryTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerBuildPartOfDirectoryTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerExpressionTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerTempPrefixTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java Mon Jan 26 11:52:06 2009
@@ -19,19 +19,20 @@
import java.util.List;
import org.apache.camel.Processor;
+import org.apache.camel.component.file.GenericFile;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.net.ftp.FTPFile;
/**
* FTP consumer
*/
-public class FtpConsumer extends RemoteFileConsumer {
+public class FtpConsumer extends RemoteFileConsumer<FTPFile> {
- public FtpConsumer(RemoteFileEndpoint endpoint, Processor processor, RemoteFileOperations ftp) {
- super(endpoint, processor, ftp);
+ public FtpConsumer(RemoteFileEndpoint endpoint, Processor processor, RemoteFileOperations fileOperations) {
+ super(endpoint, processor, fileOperations);
}
- protected void pollDirectory(String fileName, List<RemoteFile> fileList) {
+ protected void pollDirectory(String fileName, List<GenericFile<FTPFile>> fileList) {
if (fileName == null) {
return;
}
@@ -64,7 +65,7 @@
}
}
- protected void pollFile(String fileName, List<RemoteFile> fileList) {
+ protected void pollFile(String fileName, List<GenericFile<FTPFile>> fileList) {
String directory = ".";
int index = fileName.lastIndexOf("/");
if (index > -1) {
@@ -72,12 +73,18 @@
}
// list the files in the fold and poll the first file
List<FTPFile> list = operations.listFiles(fileName);
- FTPFile file = list.get(0);
- if (file != null) {
- RemoteFile remoteFile = asRemoteFile(directory, file);
- if (isValidFile(remoteFile, false)) {
- // matched file so add
- fileList.add(remoteFile);
+ if (list.size() > 0) {
+ FTPFile file = list.get(0);
+ if (file != null) {
+ RemoteFile<FTPFile> remoteFile = asRemoteFile(directory, file);
+ if (isValidFile(remoteFile, false)) {
+ // matched file so add
+ fileList.add(remoteFile);
+ }
+ }
+ } else {
+ if (log.isTraceEnabled()) {
+ log.trace("Polled [" + fileName + "]. No files found");
}
}
}
@@ -90,9 +97,9 @@
if (file.getTimestamp() != null) {
remote.setLastModified(file.getTimestamp().getTimeInMillis());
}
- remote.setHostname(endpoint.getConfiguration().getHost());
+ remote.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost());
String absoluteFileName = (ObjectHelper.isNotEmpty(directory) ? directory + "/" : "") + file.getName();
- remote.setAbsolutelFileName(absoluteFileName);
+ remote.setAbsoluteFileName(absoluteFileName);
// the relative filename
String ftpBasePath = endpoint.getConfiguration().getFile();
Added: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java?rev=737677&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java (added)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java Mon Jan 26 11:52:06 2009
@@ -0,0 +1,56 @@
+/**
+ * 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.remote;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.file.GenericFileEndpoint;
+import org.apache.commons.net.ftp.FTPFile;
+
+/**
+ * Standard FTP Remote File Component
+ */
+public class FtpRemoteFileComponent extends RemoteFileComponent<FTPFile> {
+
+ public FtpRemoteFileComponent() {
+ super();
+ }
+
+ public FtpRemoteFileComponent(CamelContext context) {
+ super(context);
+ }
+
+ @Override
+ protected GenericFileEndpoint<FTPFile> buildFileEndpoint(String uri, String remaining, Map parameters) throws Exception {
+ // get the uri part before the options as they can be non URI valid such
+ // as the expression using $ chars
+ if (uri.indexOf("?") != -1) {
+ uri = uri.substring(0, uri.indexOf("?"));
+ }
+
+ // lets make sure we create a new configuration as each endpoint can
+ // customize its own version
+ FtpRemoteFileConfiguration config = new FtpRemoteFileConfiguration(new URI(uri));
+
+ FtpRemoteFileOperations operations = new FtpRemoteFileOperations();
+ return new FtpRemoteFileEndpoint(uri, this, operations, config);
+ }
+
+}
+
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java?rev=737677&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java (added)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java Mon Jan 26 11:52:06 2009
@@ -0,0 +1,37 @@
+/**
+ * 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.remote;
+
+import java.net.URI;
+
+public class FtpRemoteFileConfiguration extends RemoteFileConfiguration {
+
+ public static final int DEFAULT_FTP_PORT = 21;
+
+ public FtpRemoteFileConfiguration() {
+ }
+
+ public FtpRemoteFileConfiguration(URI uri) {
+ super(uri);
+ }
+
+ @Override
+ protected void setDefaultPort() {
+ setPort(DEFAULT_FTP_PORT);
+ }
+
+}
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java?rev=737677&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java (added)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java Mon Jan 26 11:52:06 2009
@@ -0,0 +1,48 @@
+/**
+ * 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.remote;
+
+import org.apache.camel.Processor;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.net.ftp.FTPFile;
+
+public class FtpRemoteFileEndpoint extends RemoteFileEndpoint<FTPFile> {
+
+ public FtpRemoteFileEndpoint(String uri, FtpRemoteFileComponent component, FtpRemoteFileOperations operations,
+ RemoteFileConfiguration configuration) {
+ super(uri, component, operations, configuration);
+
+ }
+
+ @Override
+ protected RemoteFileConsumer buildConsumer(Processor processor, RemoteFileOperations<FTPFile> operations) {
+ return new FtpConsumer(this, processor, operations);
+ }
+
+ @Override
+ public RemoteFileConsumer createConsumer(Processor processor) throws Exception {
+ RemoteFileConsumer rfc = super.createConsumer(processor);
+ ObjectHelper.notEmpty(((FtpRemoteFileConfiguration) configuration).getHost(), "host");
+ return rfc;
+ }
+
+ @Override
+ public String getScheme() {
+ return "ftp";
+ }
+
+}
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileOperations.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpRemoteFileOperations.java Mon Jan 26 11:52:06 2009
@@ -16,12 +16,16 @@
*/
package org.apache.camel.component.file.remote;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileExchange;
+import org.apache.camel.component.file.GenericFileOperationFailedException;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -31,9 +35,11 @@
/**
* FTP remote file operations
*/
-public class FtpRemoteFileOperations implements RemoteFileOperations<FTPClient> {
- private static final Log LOG = LogFactory.getLog(FtpRemoteFileOperations.class);
- private FTPClient client;
+public class FtpRemoteFileOperations implements RemoteFileOperations<FTPFile> {
+
+ private static final transient Log LOG = LogFactory.getLog(FtpRemoteFileOperations.class);
+
+ private final FTPClient client;
public FtpRemoteFileOperations() {
this.client = new FTPClient();
@@ -43,13 +49,13 @@
this.client = client;
}
- public boolean connect(RemoteFileConfiguration config) throws RemoteFileOperationFailedException {
+ public boolean connect(RemoteFileConfiguration config) throws GenericFileOperationFailedException {
String host = config.getHost();
int port = config.getPort();
String username = config.getUsername();
if (config.getFtpClientConfig() != null) {
- LOG.trace("Configuring FTPClient with config: " + config.getFtpClientConfig());
+ LOG.trace("Configuring FTPFile with config: " + config.getFtpClientConfig());
client.configure(config.getFtpClientConfig());
}
@@ -72,7 +78,7 @@
LOG.trace("Attempting to login user: " + username);
login = client.login(username, config.getPassword());
} else {
- LOG.trace("Attempting to login anonymous");
+ LOG.trace("Attempting to login anonymousl");
login = client.login("anonymous", null);
}
if (LOG.isTraceEnabled()) {
@@ -89,11 +95,11 @@
return true;
}
- public boolean isConnected() throws RemoteFileOperationFailedException {
+ public boolean isConnected() throws GenericFileOperationFailedException {
return client.isConnected();
}
- public void disconnect() throws RemoteFileOperationFailedException {
+ public void disconnect() throws GenericFileOperationFailedException {
try {
client.disconnect();
} catch (IOException e) {
@@ -101,7 +107,7 @@
}
}
- public boolean deleteFile(String name) throws RemoteFileOperationFailedException {
+ public boolean deleteFile(FTPClient client, String name) throws GenericFileOperationFailedException {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleteing file: " + name);
}
@@ -112,7 +118,7 @@
}
}
- public boolean renameFile(String from, String to) throws RemoteFileOperationFailedException {
+ public boolean renameFile(String from, String to) throws GenericFileOperationFailedException {
if (LOG.isDebugEnabled()) {
LOG.debug("Renaming file: " + from + " to: " + to);
}
@@ -123,7 +129,7 @@
}
}
- public boolean buildDirectory(String directory) throws RemoteFileOperationFailedException {
+ public boolean buildDirectory(String directory) throws GenericFileOperationFailedException {
try {
String originalDirectory = client.printWorkingDirectory();
@@ -137,7 +143,8 @@
}
success = client.makeDirectory(directory);
if (!success) {
- // we are here if the server side doesn't create intermediate folders
+ // we are here if the server side doesn't create
+ // intermediate folders
// so create the folder one by one
buildDirectoryChunks(directory);
}
@@ -153,23 +160,26 @@
}
}
- public boolean retrieveFile(String name, OutputStream out) throws RemoteFileOperationFailedException {
+ public boolean retrieveFile(String name, GenericFileExchange<FTPFile> exchange) throws GenericFileOperationFailedException {
try {
- return client.retrieveFile(name, out);
+ GenericFile<FTPFile> target = exchange.getGenericFile();
+ OutputStream os = new ByteArrayOutputStream();
+ target.setBody(os);
+ return client.retrieveFile(name, os);
} catch (IOException e) {
throw new RemoteFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}
}
- public boolean storeFile(String name, InputStream body) throws RemoteFileOperationFailedException {
+ public boolean storeFile(String name, GenericFileExchange<FTPFile> exchange) throws GenericFileOperationFailedException {
try {
- return client.storeFile(name, body);
+ return client.storeFile(name, exchange.getIn().getBody(InputStream.class));
} catch (IOException e) {
throw new RemoteFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}
}
- public String getCurrentDirectory() throws RemoteFileOperationFailedException {
+ public String getCurrentDirectory() throws GenericFileOperationFailedException {
try {
return client.printWorkingDirectory();
} catch (IOException e) {
@@ -177,7 +187,7 @@
}
}
- public void changeCurrentDirectory(String newDirectory) throws RemoteFileOperationFailedException {
+ public void changeCurrentDirectory(String newDirectory) throws GenericFileOperationFailedException {
try {
client.changeWorkingDirectory(newDirectory);
} catch (IOException e) {
@@ -185,11 +195,11 @@
}
}
- public List listFiles() throws RemoteFileOperationFailedException {
+ public List listFiles() throws GenericFileOperationFailedException {
return listFiles(".");
}
- public List listFiles(String path) throws RemoteFileOperationFailedException {
+ public List listFiles(String path) throws GenericFileOperationFailedException {
// use current directory if path not given
if (ObjectHelper.isEmpty(path)) {
path = ".";
@@ -225,4 +235,21 @@
return success;
}
+ public FTPClient changeCurrentDirectory(FTPClient client, String path) throws GenericFileOperationFailedException {
+ try {
+ client.changeWorkingDirectory(path);
+ return client;
+ } catch (IOException e) {
+ throw new RemoteFileOperationFailedException("Failed to delete [" + path + "]", e);
+ }
+ }
+
+ public boolean deleteFile(String name) throws GenericFileOperationFailedException {
+ try {
+ return this.client.deleteFile(name);
+ } catch (IOException e) {
+ throw new RemoteFileOperationFailedException("Failed to delete [" + name + "]", e);
+ }
+ }
+
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java Mon Jan 26 11:52:06 2009
@@ -16,84 +16,14 @@
*/
package org.apache.camel.component.file.remote;
-import java.io.OutputStream;
+import org.apache.camel.component.file.GenericFile;
/**
* Represents a remote file of some sort of backing object
*/
-public class RemoteFile<T> implements Cloneable {
+public class RemoteFile<F> extends GenericFile<F> implements Cloneable {
- private String absolutelFileName;
- private String relativeFileName;
- private String fileName;
private String hostname;
- private long fileLength;
- private long lastModified;
- private T file;
- private OutputStream body;
-
- @Override
- public RemoteFile<T> clone() {
- return copyFrom(this);
- }
-
- /**
- * Creates a clone based on the source
- *
- * @param source the source
- * @return a clone of the source
- */
- public RemoteFile<T> copyFrom(RemoteFile<T> source) {
- RemoteFile<T> result = new RemoteFile<T>();
- result.setAbsolutelFileName(source.getAbsolutelFileName());
- result.setRelativeFileName(source.getRelativeFileName());
- result.setFileName(source.getFileName());
- result.setHostname(source.getHostname());
- result.setFileLength(source.getFileLength());
- result.setLastModified(source.getLastModified());
- result.setFile(source.getFile());
- result.setBody(source.getBody());
- return result;
- }
-
- /**
- * Changes the name of this remote file. This method alters the absolute and relative names as well.
- *
- * @param newName the new name
- */
- public void changeFileName(String newName) {
- setAbsolutelFileName(getParent() + "/" + newName);
- if (relativeFileName.indexOf("/") != -1) {
- setRelativeFileName(relativeFileName.substring(0, relativeFileName.lastIndexOf("/")) + newName);
- } else {
- setRelativeFileName(newName);
- }
- setFileName(newName);
- }
-
- public String getAbsolutelFileName() {
- return absolutelFileName;
- }
-
- public void setAbsolutelFileName(String absolutelFileName) {
- this.absolutelFileName = absolutelFileName;
- }
-
- public String getRelativeFileName() {
- return relativeFileName;
- }
-
- public void setRelativeFileName(String relativeFileName) {
- this.relativeFileName = relativeFileName;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
public String getHostname() {
return hostname;
@@ -103,44 +33,17 @@
this.hostname = hostname;
}
- public long getFileLength() {
- return fileLength;
- }
-
- public void setFileLength(long fileLength) {
- this.fileLength = fileLength;
- }
-
- public long getLastModified() {
- return lastModified;
- }
-
- public void setLastModified(long lastModified) {
- this.lastModified = lastModified;
- }
-
- public T getFile() {
- return file;
- }
-
- public void setFile(T file) {
- this.file = file;
- }
-
- public OutputStream getBody() {
- return body;
- }
-
- public void setBody(OutputStream os) {
- this.body = os;
- }
-
- public String getParent() {
- return absolutelFileName.substring(0, absolutelFileName.lastIndexOf("/"));
- }
-
- @Override
- public String toString() {
- return absolutelFileName;
+ public RemoteFile<F> copyFrom(RemoteFile<F> source) {
+ RemoteFile<F> result = (RemoteFile<F>) source.clone();
+ result.setAbsoluteFileName(source.getAbsoluteFileName());
+ result.setRelativeFileName(source.getRelativeFileName());
+ result.setFileName(source.getFileName());
+ result.setFileLength(source.getFileLength());
+ result.setLastModified(source.getLastModified());
+ result.setFile(source.getFile());
+ result.setBody(source.getBody());
+ result.setBinding(source.getBinding());
+ result.setHostname(source.getHostname());
+ return result;
}
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileComponent.java Mon Jan 26 11:52:06 2009
@@ -16,81 +16,29 @@
*/
package org.apache.camel.component.file.remote;
-import java.net.URI;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.Map;
-
import org.apache.camel.CamelContext;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.util.ObjectHelper;
-import static org.apache.camel.util.ObjectHelper.isNotEmpty;
+import org.apache.camel.component.file.GenericFileComponent;
+import org.apache.camel.component.file.GenericFileEndpoint;
/**
- * Remote file component.
+ * Base class for remote file components. Polling and consuming files from
+ * (logically) remote locations
+ *
+ * @param <T> the type of file that these remote endpoints provide
*/
-public class RemoteFileComponent extends DefaultComponent {
+public abstract class RemoteFileComponent<T> extends GenericFileComponent<T> {
public RemoteFileComponent() {
+ super();
}
public RemoteFileComponent(CamelContext context) {
super(context);
}
- protected RemoteFileEndpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
- // get the uri part before the options as they can be non URI valid such as the expression using $ chars
- if (uri.indexOf("?") != -1) {
- uri = uri.substring(0, uri.indexOf("?"));
- }
-
- // lets make sure we create a new configuration as each endpoint can customize its own version
- RemoteFileConfiguration config = new RemoteFileConfiguration(new URI(uri));
-
- // create the correct endpoint based on the protocol
- final RemoteFileEndpoint endpoint;
- if ("ftp".equals(config.getProtocol())) {
- RemoteFileOperations operations = new FtpRemoteFileOperations();
- endpoint = new RemoteFileEndpoint(uri, this, operations, config);
- } else if ("sftp".equals(config.getProtocol())) {
- RemoteFileOperations operations = new SftpRemoteFileOperations();
- endpoint = new RemoteFileEndpoint(uri, this, operations, config);
- } else {
- throw new IllegalArgumentException("Unsupported protocol: " + config.getProtocol());
- }
-
- // sort by using file language
- String sortBy = getAndRemoveParameter(parameters, "sortBy", String.class);
- if (isNotEmpty(sortBy) && !isReferenceParameter(sortBy)) {
- // we support nested sort groups so they should be chained
- String[] groups = sortBy.split(";");
- Iterator<String> it = ObjectHelper.createIterator(groups);
- Comparator<RemoteFileExchange> comparator = createSortByComparator(it);
- endpoint.setSortBy(comparator);
- }
-
- setProperties(endpoint.getConfiguration(), parameters);
- setProperties(endpoint, parameters);
- return endpoint;
- }
-
- private Comparator<RemoteFileExchange> createSortByComparator(Iterator<String> it) {
- if (!it.hasNext()) {
- return null;
- }
-
- String group = it.next();
-
- boolean reverse = group.startsWith("reverse:");
- String reminder = reverse ? ifStartsWithReturnRemainder("reverse:", group) : group;
-
- boolean ignoreCase = reminder.startsWith("ignoreCase:");
- reminder = ignoreCase ? ifStartsWithReturnRemainder("ignoreCase:", reminder) : reminder;
-
- ObjectHelper.notEmpty(reminder, "sortBy expression", this);
-
- // recursive add nested sorters
- return DefaultRemoteFileSorter.sortByFileLanguage(reminder, reverse, ignoreCase, createSortByComparator(it));
+ @Override
+ protected void afterPropertiesSet(GenericFileEndpoint<T> endpoint) throws Exception {
+ // noop
}
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Mon Jan 26 11:52:06 2009
@@ -18,19 +18,18 @@
import java.net.URI;
+import org.apache.camel.component.file.GenericFileConfiguration;
import org.apache.commons.net.ftp.FTPClientConfig;
/**
* Configuration of the FTP server
*/
-public class RemoteFileConfiguration {
+public abstract class RemoteFileConfiguration extends GenericFileConfiguration {
private String protocol;
private String username;
private String host;
private int port;
private String password;
- private String file;
- private boolean directory = true;
private boolean binary;
private boolean passiveMode;
private String knownHostsFile;
@@ -45,46 +44,24 @@
configure(uri);
}
- public String toString() {
- return remoteServerInformation() + "/" + file;
- }
-
- /**
- * Returns human readable server information for logging purpose
- */
- public String remoteServerInformation() {
- return protocol + "://" + (username != null ? username : "anonymous") + "@" + host + ":" + getPort();
- }
-
+ @Override
public void configure(URI uri) {
+ super.configure(uri);
setProtocol(uri.getScheme());
setDefaultPort();
setUsername(uri.getUserInfo());
setHost(uri.getHost());
setPort(uri.getPort());
- setFile(uri.getPath());
- }
-
- protected void setDefaultPort() {
- if ("ftp".equalsIgnoreCase(protocol)) {
- setPort(21);
- } else if ("sftp".equalsIgnoreCase(protocol)) {
- setPort(22);
- }
}
- public String getFile() {
- return file;
+ /**
+ * Returns human readable server information for logging purpose
+ */
+ public String remoteServerInformation() {
+ return protocol + "://" + (username != null ? username : "anonymous") + "@" + host + ":" + getPort();
}
- 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;
- }
+ protected abstract void setDefaultPort();
public String getHost() {
return host;
@@ -136,14 +113,6 @@
this.binary = binary;
}
- public boolean isDirectory() {
- return directory;
- }
-
- public void setDirectory(boolean directory) {
- this.directory = directory;
- }
-
public boolean isPassiveMode() {
return passiveMode;
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java Mon Jan 26 11:52:06 2009
@@ -16,329 +16,59 @@
*/
package org.apache.camel.component.file.remote;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.apache.camel.AsyncCallback;
import org.apache.camel.Processor;
-import org.apache.camel.component.file.FileComponent;
-import org.apache.camel.component.file.FileEndpoint;
-import org.apache.camel.impl.ScheduledPollConsumer;
-import org.apache.camel.processor.DeadLetterChannel;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.component.file.GenericFileConsumer;
+import org.apache.camel.component.file.GenericFileOperationFailedException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Base class for remote file consumers.
*/
-public abstract class RemoteFileConsumer extends ScheduledPollConsumer {
+public abstract class RemoteFileConsumer<T> extends GenericFileConsumer<T> {
+
protected final transient Log log = LogFactory.getLog(getClass());
- protected RemoteFileEndpoint endpoint;
- protected RemoteFileOperations operations;
protected boolean loggedIn;
- public RemoteFileConsumer(RemoteFileEndpoint endpoint, Processor processor, RemoteFileOperations operations) {
- super(endpoint, processor);
- this.endpoint = endpoint;
- this.operations = operations;
+ public RemoteFileConsumer(RemoteFileEndpoint<T> endpoint, Processor processor, RemoteFileOperations<T> operations) {
+ super(endpoint, processor, operations);
}
- protected void poll() throws Exception {
+ protected boolean prePollCheck() throws Exception {
connectIfNecessary();
if (!loggedIn) {
- String message = "Could not connect/login to: " + endpoint.remoteServerInformation() + ". Will skip this poll.";
+ String message = "Could not connect/login to: " + remoteServer() + ". Will skip this poll.";
log.warn(message);
- return;
- }
-
- // gather list of files to process
- List<RemoteFile> files = new ArrayList<RemoteFile>();
-
- String name = endpoint.getConfiguration().getFile();
- boolean isDirectory = endpoint.getConfiguration().isDirectory();
- if (isDirectory) {
- pollDirectory(name, files);
- } else {
- pollFile(name, files);
- }
-
- // sort files using file comparator if provided
- if (endpoint.getSorter() != null) {
- Collections.sort(files, endpoint.getSorter());
- }
-
- // sort using build in sorters that is expression based
- // first we need to convert to RemoteFileExchange objects so we can sort using expressions
- List<RemoteFileExchange> exchanges = new ArrayList<RemoteFileExchange>(files.size());
- for (RemoteFile file : files) {
- RemoteFileExchange exchange = endpoint.createExchange(file);
- endpoint.configureMessage(file, exchange.getIn());
- exchanges.add(exchange);
- }
- // sort files using exchange comparator if provided
- if (endpoint.getSortBy() != null) {
- Collections.sort(exchanges, endpoint.getSortBy());
- }
-
- // consume files one by one
- int total = exchanges.size();
- if (total > 0 && log.isDebugEnabled()) {
- log.debug("Total " + total + " files to consume");
- }
- for (int index = 0; index < total; index++) {
- RemoteFileExchange exchange = exchanges.get(index);
- // add current index and total as headers
- exchange.getIn().setHeader(FileComponent.HEADER_FILE_BATCH_INDEX, index);
- exchange.getIn().setHeader(FileComponent.HEADER_FILE_BATCH_TOTAL, total);
- processExchange(exchange);
- }
- }
-
- /**
- * Polls the given directory for files to process
- *
- * @param fileName current directory or file
- * @param fileList current list of files gathered
- */
- protected abstract void pollDirectory(String fileName, List<RemoteFile> fileList);
-
- /**
- * Polls the given file
- *
- * @param fileName the file name
- * @param fileList current list of files gathered
- */
- protected abstract void pollFile(String fileName, List<RemoteFile> fileList);
-
- /**
- * Processes the exchange
- *
- * @param exchange the exchange
- */
- protected void processExchange(final RemoteFileExchange exchange) {
- if (log.isTraceEnabled()) {
- log.trace("Processing remote file: " + exchange.getRemoteFile());
- }
-
- try {
- final RemoteFileProcessStrategy processStrategy = endpoint.getRemoteFileProcessStrategy();
-
- if (processStrategy.begin(operations, endpoint, exchange, exchange.getRemoteFile())) {
-
- // must use file from exchange as it can be updated due the preMoveNamePrefix/preMoveNamePostfix options
- final RemoteFile target = exchange.getRemoteFile();
- // must use full name when downloading so we have the correct path
- final String name = target.getAbsolutelFileName();
-
- // retrieve the file using the stream
- if (log.isTraceEnabled()) {
- log.trace("Retriving remote file: " + name + " from: " + remoteServer());
- }
- OutputStream os = new ByteArrayOutputStream();
- target.setBody(os);
- operations.retrieveFile(name, os);
-
- if (log.isTraceEnabled()) {
- log.trace("Retrieved remote file: " + name + " from: " + remoteServer());
- }
-
- if (log.isDebugEnabled()) {
- log.debug("About to process remote file: " + target + " using exchange: " + exchange);
- }
- // Use the async processor interface so that processing of
- // the exchange can happen asynchronously
- getAsyncProcessor().process(exchange, new AsyncCallback() {
- public void done(boolean sync) {
- final RemoteFile file = exchange.getRemoteFile();
- boolean failed = exchange.isFailed();
- boolean handled = DeadLetterChannel.isFailureHandled(exchange);
-
- if (log.isDebugEnabled()) {
- log.debug("Done processing remote file: " + file.getAbsolutelFileName()
- + ". Status is: " + (failed ? "failed: " + failed + ", handled by failure processor: " + handled : "processed OK"));
- }
-
- boolean committed = false;
- try {
- if (!failed || handled) {
- // commit the file strategy if there was no failure or already handled by the DeadLetterChannel
- processStrategyCommit(processStrategy, exchange, file, handled);
- committed = true;
- } else {
- // there was an exception but it was not handled by the DeadLetterChannel
- handleException(exchange.getException());
- }
- } finally {
- if (!committed) {
- processStrategyRollback(processStrategy, exchange, file);
- }
- }
- }
- });
- } else {
- log.warn(endpoint + " cannot process remote file: " + exchange.getRemoteFile());
- }
- } catch (Exception e) {
- handleException(e);
- }
-
- }
-
- /**
- * Strategy when the file was processed and a commit should be executed.
- *
- * @param processStrategy the strategy to perform the commit
- * @param exchange the exchange
- * @param file the file processed
- * @param failureHandled is <tt>false</tt> if the exchange was processed succesfully, <tt>true</tt> if
- * an exception occured during processing but it was handled by the failure processor (usually the
- * DeadLetterChannel).
- */
- protected void processStrategyCommit(RemoteFileProcessStrategy processStrategy, RemoteFileExchange exchange,
- RemoteFile file, boolean failureHandled) {
- if (endpoint.isIdempotent()) {
- // only add to idempotent repository if we could process the file
- // use file.getAbsoluteFileName as key for the idempotent repository to support files with same name but in different folders
- endpoint.getIdempotentRepository().add(file.getAbsolutelFileName());
- }
-
- try {
- if (log.isDebugEnabled()) {
- log.debug("Committing remote file strategy: " + processStrategy + " for file: "
- + file + (failureHandled ? " that was handled by the failure processor." : ""));
- }
- processStrategy.commit(operations, endpoint, exchange, file);
- } catch (Exception e) {
- log.warn("Error committing remote file strategy: " + processStrategy, e);
- handleException(e);
- }
- }
-
- /**
- * Strategy when the file was not processed and a rollback should be executed.
- *
- * @param processStrategy the strategy to perform the commit
- * @param exchange the exchange
- * @param file the file processed
- */
- protected void processStrategyRollback(RemoteFileProcessStrategy processStrategy, RemoteFileExchange exchange,
- RemoteFile file) {
- if (log.isDebugEnabled()) {
- log.debug("Rolling back remote file strategy: " + processStrategy + " for file: " + file);
- }
- processStrategy.rollback(operations, endpoint, exchange, file);
- }
-
- /**
- * Strategy for validating if the given remote file should be included or not
- *
- * @param file the remote file
- * @param isDirectory wether the file is a directory or a file
- * @return <tt>true</tt> to include the file, <tt>false</tt> to skip it
- */
- protected boolean isValidFile(RemoteFile file, boolean isDirectory) {
- if (!isMatched(file, isDirectory)) {
- if (log.isTraceEnabled()) {
- log.trace("Remote file did not match. Will skip this remote file: " + file);
- }
- return false;
- } else if (endpoint.isIdempotent() && endpoint.getIdempotentRepository().contains(file.getAbsolutelFileName())) {
- // use file.getAbsoluteFileName as key for the idempotent repository to support files with same name but in different folders
- if (log.isTraceEnabled()) {
- log.trace("RemoteFileConsumer is idempotent and the file has been consumed before. Will skip this remote file: " + file);
- }
- return false;
- }
-
- // file matched
- return true;
- }
-
- /**
- * Strategy to perform file matching based on endpoint configuration.
- * <p/>
- * Will always return <tt>false</tt> for certain files/folders:
- * <ul>
- * <li>Starting with a dot</li>
- * <li>lock files</li>
- * </ul>
- * And then <tt>true</tt> for directories.
- *
- * @param file the remote file
- * @param isDirectory wether the file is a directory or a file
- * @return <tt>true</tt> if the remote file is matched, <tt>false</tt> if not
- */
- protected boolean isMatched(RemoteFile file, boolean isDirectory) {
- String name = file.getFileName();
-
- // folders/names starting with dot is always skipped (eg. ".", ".camel", ".camelLock")
- if (name.startsWith(".")) {
return false;
}
-
- // lock files should be skipped
- if (name.endsWith(FileEndpoint.DEFAULT_LOCK_FILE_POSTFIX)) {
- return false;
- }
-
- // directories so far is always regarded as matched (matching on the name is only for files)
- if (isDirectory) {
- return true;
- }
-
- if (endpoint.getFilter() != null) {
- if (!endpoint.getFilter().accept(file)) {
- return false;
- }
- }
-
- if (ObjectHelper.isNotEmpty(endpoint.getRegexPattern())) {
- if (!name.matches(endpoint.getRegexPattern())) {
- return false;
- }
- }
-
- if (ObjectHelper.isNotEmpty(endpoint.getExcludedNamePrefix())) {
- if (name.startsWith(endpoint.getExcludedNamePrefix())) {
- return false;
- }
- }
- if (ObjectHelper.isNotEmpty(endpoint.getExcludedNamePostfix())) {
- if (name.endsWith(endpoint.getExcludedNamePostfix())) {
- return false;
- }
- }
-
return true;
}
+ @Override
protected void doStop() throws Exception {
super.doStop();
// disconnect when stopping
try {
- if (operations.isConnected()) {
+ if (((RemoteFileOperations) operations).isConnected()) {
loggedIn = false;
log.debug("Disconnecting from " + remoteServer());
- operations.disconnect();
+ ((RemoteFileOperations) operations).disconnect();
}
- } catch (RemoteFileOperationFailedException e) {
+ } catch (GenericFileOperationFailedException e) {
// ignore just log a warning
log.warn(e.getMessage());
}
}
protected void connectIfNecessary() throws IOException {
- if (!operations.isConnected() || !loggedIn) {
+ if (!((RemoteFileOperations) operations).isConnected() || !loggedIn) {
if (log.isDebugEnabled()) {
log.debug("Not connected/logged in, connecting to " + remoteServer());
}
- loggedIn = operations.connect(endpoint.getConfiguration());
+ loggedIn = ((RemoteFileOperations) operations).connect((RemoteFileConfiguration) endpoint.getConfiguration());
if (loggedIn) {
log.info("Connected and logged in to " + remoteServer());
}
@@ -349,6 +79,6 @@
* Returns human readable server information for logging purpose
*/
protected String remoteServer() {
- return endpoint.remoteServerInformation();
+ return ((RemoteFileEndpoint) endpoint).remoteServerInformation();
}
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConverter.java Mon Jan 26 11:52:06 2009
@@ -32,7 +32,7 @@
*/
@Converter
public final class RemoteFileConverter {
-
+
private RemoteFileConverter() {
// Helper Class
}
@@ -64,7 +64,7 @@
@Converter
public static String toString(RemoteFile file, Exchange exchange) throws IOException {
- OutputStream os = file.getBody();
+ OutputStream os = (OutputStream) file.getBody();
return os != null ? os.toString() : null;
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java Mon Jan 26 11:52:06 2009
@@ -16,118 +16,64 @@
*/
package org.apache.camel.component.file.remote;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.Expression;
-import org.apache.camel.Message;
import org.apache.camel.Processor;
-import org.apache.camel.component.file.FileComponent;
-import org.apache.camel.impl.ScheduledPollEndpoint;
-import org.apache.camel.language.simple.FileLanguage;
+import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileEndpoint;
+import org.apache.camel.component.file.GenericFileExchange;
+import org.apache.camel.component.file.GenericFileProducer;
import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
-import org.apache.camel.spi.IdempotentRepository;
-import org.apache.camel.util.FactoryFinder;
import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.UuidGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Remote file endpoint.
*/
-public class RemoteFileEndpoint extends ScheduledPollEndpoint {
- private static final transient Log LOG = LogFactory.getLog(RemoteFileEndpoint.class);
- private static final transient String DEFAULT_STRATEGYFACTORY_CLASS =
- "org.apache.camel.component.file.remote.strategy.RemoteFileProcessStrategyFactory";
- private static final transient int DEFAULT_IDEMPOTENT_CACHE_SIZE = 1000;
-
- private RemoteFileProcessStrategy processStrategy;
- private RemoteFileOperations operations;
- private RemoteFileConfiguration configuration;
- private boolean noop;
- private String tempPrefix;
- private String moveNamePrefix;
- private String moveNamePostfix;
- private String preMoveNamePrefix;
- private String preMoveNamePostfix;
- private String excludedNamePrefix;
- private String excludedNamePostfix;
- private boolean recursive;
- private String regexPattern;
- private boolean setNames = true;
- private boolean delete;
- private Expression expression;
- private Expression preMoveExpression;
- private boolean idempotent;
- private IdempotentRepository idempotentRepository;
- private RemoteFileFilter filter;
- private Comparator<RemoteFile> sorter;
- private Comparator<RemoteFileExchange> sortBy;
- private RemoteFileExclusiveReadLockStrategy exclusiveReadLockStrategy;
- private String readLock = "none";
- private long readLockTimeout;
+public abstract class RemoteFileEndpoint<T> extends GenericFileEndpoint<T> {
- public RemoteFileEndpoint() {
- }
+ protected final transient Log log = LogFactory.getLog(getClass());
- public RemoteFileEndpoint(String uri, RemoteFileComponent component, RemoteFileOperations operations, RemoteFileConfiguration configuration) {
+ public RemoteFileEndpoint(String uri, RemoteFileComponent<T> component, RemoteFileOperations<T> operations,
+ RemoteFileConfiguration configuration) {
super(uri, component);
this.operations = operations;
this.configuration = configuration;
}
- public RemoteFileExchange createExchange() {
- return new RemoteFileExchange(this, getExchangePattern(), null);
+ @Override
+ public GenericFileExchange createExchange() {
+ return new RemoteFileExchange(this, getExchangePattern());
}
- public RemoteFileExchange createExchange(RemoteFile remote) {
- return new RemoteFileExchange(this, getExchangePattern(), remote);
+ @Override
+ public GenericFileExchange createExchange(GenericFile<T> file) {
+ return new RemoteFileExchange(this, getExchangePattern(), (RemoteFile<T>) file);
}
- public RemoteFileProducer createProducer() throws Exception {
- return new RemoteFileProducer(this, operations);
+ @Override
+ public GenericFileProducer<T> createProducer() throws Exception {
+ return new RemoteFileProducer<T>(this, (RemoteFileOperations<T>) this.operations);
}
+ @Override
public RemoteFileConsumer createConsumer(Processor processor) throws Exception {
- ObjectHelper.notNull(configuration, "remoteFileConfiguration");
- String protocol = getConfiguration().getProtocol();
+ String protocol = ((RemoteFileConfiguration) getConfiguration()).getProtocol();
ObjectHelper.notEmpty(protocol, "protocol");
- ObjectHelper.notEmpty(configuration.getHost(), "host");
- RemoteFileConsumer consumer;
- if ("ftp".equals(protocol)) {
- // create operations for this protocol if not already set
- // for instance if using spring bean configured endpoints instead of URI parameters
- if (operations == null) {
- operations = new FtpRemoteFileOperations();
- }
- consumer = new FtpConsumer(this, processor, operations);
- } else if ("sftp".equals(protocol)) {
- if (operations == null) {
- operations = new SftpRemoteFileOperations();
- }
- consumer = new SftpConsumer(this, processor, operations);
- } else {
- throw new IllegalArgumentException("Unsupported protocol: " + protocol);
- }
+ RemoteFileConsumer consumer = buildConsumer(processor, (RemoteFileOperations<T>) operations);
if (isDelete() && (getMoveNamePrefix() != null || getMoveNamePostfix() != null || getExpression() != null)) {
throw new IllegalArgumentException("You cannot set delete=true and a moveNamePrefix, moveNamePostfix or expression option");
}
-
// if noop=true then idempotent should also be configured
if (isNoop() && !isIdempotent()) {
- LOG.info("Endpoint is configured with noop=true so forcing endpoint to be idempotent as well");
+ log.info("Endpoint is configured with noop=true so forcing endpoint to be idempotent as well");
setIdempotent(true);
}
// if idempotent and no repository set then create a default one
if (isIdempotent() && idempotentRepository == null) {
- LOG.info("Using default memory based idempotent repository with cache max size: " + DEFAULT_IDEMPOTENT_CACHE_SIZE);
+ log.info("Using default memory based idempotent repository with cache max size: " + DEFAULT_IDEMPOTENT_CACHE_SIZE);
idempotentRepository = MemoryIdempotentRepository.memoryIdempotentRepository(DEFAULT_IDEMPOTENT_CACHE_SIZE);
}
@@ -135,340 +81,20 @@
return consumer;
}
- public boolean isSingleton() {
- return true;
- }
-
- /**
- * Return the file name that will be auto-generated for the given message if none is provided
- */
- public String getGeneratedFileName(Message message) {
- return getFileFriendlyMessageId(message.getMessageId());
- }
-
- protected String getFileFriendlyMessageId(String id) {
- return UuidGenerator.generateSanitizedId(id);
- }
-
- public RemoteFileProcessStrategy getRemoteFileProcessStrategy() {
- if (processStrategy == null) {
- processStrategy = createRemoteFileStrategy();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Using remote file process strategy: " + processStrategy);
- }
- }
- return processStrategy;
- }
-
- public void setRemoteFileProcessStrategy(RemoteFileProcessStrategy remoteFileProcessStrategy) {
- this.processStrategy = remoteFileProcessStrategy;
- }
-
- public void setRemoteFileOperations(RemoteFileOperations operations) {
- this.operations = operations;
- }
-
- public boolean isNoop() {
- return noop;
- }
-
- public void setNoop(boolean noop) {
- this.noop = noop;
- }
-
- public String getMoveNamePrefix() {
- return moveNamePrefix;
- }
-
- public void setMoveNamePrefix(String moveNamePrefix) {
- this.moveNamePrefix = moveNamePrefix;
- }
-
- public String getMoveNamePostfix() {
- return moveNamePostfix;
- }
-
- public void setMoveNamePostfix(String moveNamePostfix) {
- this.moveNamePostfix = moveNamePostfix;
- }
-
- public String getPreMoveNamePrefix() {
- return preMoveNamePrefix;
- }
-
- public void setPreMoveNamePrefix(String preMoveNamePrefix) {
- this.preMoveNamePrefix = preMoveNamePrefix;
- }
-
- public String getPreMoveNamePostfix() {
- return preMoveNamePostfix;
- }
-
- public void setPreMoveNamePostfix(String preMoveNamePostfix) {
- this.preMoveNamePostfix = preMoveNamePostfix;
- }
-
- public String getExcludedNamePrefix() {
- return excludedNamePrefix;
- }
-
- public void setExcludedNamePrefix(String excludedNamePrefix) {
- this.excludedNamePrefix = excludedNamePrefix;
- }
-
- public String getExcludedNamePostfix() {
- return excludedNamePostfix;
- }
-
- public void setExcludedNamePostfix(String excludedNamePostfix) {
- this.excludedNamePostfix = excludedNamePostfix;
- }
-
- public boolean isRecursive() {
- return recursive;
- }
-
- public void setRecursive(boolean recursive) {
- this.recursive = recursive;
- }
-
- public String getRegexPattern() {
- return regexPattern;
- }
-
- public void setRegexPattern(String regexPattern) {
- this.regexPattern = regexPattern;
- }
-
- public boolean isSetNames() {
- return setNames;
- }
-
- public void setSetNames(boolean setNames) {
- this.setNames = setNames;
- }
-
- public boolean isDelete() {
- return delete;
- }
-
- public void setDelete(boolean delete) {
- this.delete = delete;
- }
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
/**
- * Sets the expression based on {@link org.apache.camel.language.simple.FileLanguage}
+ * Remote File Endpoints, impl this method to create a custom consumer specific to their "protocol" etc.
+ *
+ * @param processor the processor
+ * @param operations the operations
+ * @return the created consumer
*/
- public void setExpression(String fileLanguageExpression) {
- this.expression = FileLanguage.file(fileLanguageExpression);
- }
-
- public Expression getPreMoveExpression() {
- return preMoveExpression;
- }
-
- public void setPreMoveExpression(Expression preMoveExpression) {
- this.preMoveExpression = preMoveExpression;
- }
-
- /**
- * Sets the pre move expression based on {@link org.apache.camel.language.simple.FileLanguage}
- */
- public void setPreMoveExpression(String fileLanguageExpression) {
- this.preMoveExpression = FileLanguage.file(fileLanguageExpression);
- }
-
- public boolean isIdempotent() {
- return idempotent;
- }
-
- public void setIdempotent(boolean idempotent) {
- this.idempotent = idempotent;
- }
-
- public IdempotentRepository getIdempotentRepository() {
- return idempotentRepository;
- }
-
- public void setIdempotentRepository(IdempotentRepository idempotentRepository) {
- this.idempotentRepository = idempotentRepository;
- }
-
- public RemoteFileFilter getFilter() {
- return filter;
- }
-
- public void setFilter(RemoteFileFilter filter) {
- this.filter = filter;
- }
-
- public Comparator<RemoteFile> getSorter() {
- return sorter;
- }
-
- public void setSorter(Comparator<RemoteFile> sorter) {
- this.sorter = sorter;
- }
-
- public Comparator<RemoteFileExchange> getSortBy() {
- return sortBy;
- }
-
- public void setSortBy(Comparator<RemoteFileExchange> sortBy) {
- this.sortBy = sortBy;
- }
-
- public void setSortBy(String expression) {
- setSortBy(expression, false);
- }
-
- public void setSortBy(String expression, boolean reverse) {
- setSortBy(DefaultRemoteFileSorter.sortByFileLanguage(expression, reverse));
- }
-
- public String getTempPrefix() {
- return tempPrefix;
- }
-
- /**
- * Enables and uses temporary prefix when writing files, after write it will be renamed to the correct name.
- */
- public void setTempPrefix(String tempPrefix) {
- this.tempPrefix = tempPrefix;
- }
-
- public RemoteFileConfiguration getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(RemoteFileConfiguration configuration) {
- this.configuration = configuration;
- }
-
- public RemoteFileExclusiveReadLockStrategy getExclusiveReadLockStrategy() {
- return exclusiveReadLockStrategy;
- }
-
- public void setExclusiveReadLockStrategy(RemoteFileExclusiveReadLockStrategy exclusiveReadLockStrategy) {
- this.exclusiveReadLockStrategy = exclusiveReadLockStrategy;
- }
-
- public String getReadLock() {
- return readLock;
- }
-
- public void setReadLock(String readLock) {
- this.readLock = readLock;
- }
-
- public long getReadLockTimeout() {
- return readLockTimeout;
- }
-
- public void setReadLockTimeout(long readLockTimeout) {
- this.readLockTimeout = readLockTimeout;
- }
-
- /**
- * Should the file be moved after consuming?
- */
- public boolean isMoveFile() {
- return moveNamePostfix != null || moveNamePrefix != null || preMoveNamePostfix != null || preMoveNamePrefix != null || expression != null;
- }
+ protected abstract RemoteFileConsumer buildConsumer(Processor processor, RemoteFileOperations<T> operations);
/**
* Returns human readable server information for logging purpose
*/
public String remoteServerInformation() {
- return configuration.remoteServerInformation();
- }
-
- /**
- * Configures the given message with the file which sets the body to the file object
- * and sets the {@link FileComponent#HEADER_FILE_NAME} header.
- */
- public void configureMessage(RemoteFile file, Message message) {
- message.setBody(file);
- message.setHeader(FileComponent.HEADER_FILE_NAME, file.getRelativeFileName());
- }
-
- /**
- * A strategy method to lazily create the file strategy
- */
- protected RemoteFileProcessStrategy createRemoteFileStrategy() {
- ObjectHelper.notNull(getCamelContext(), "camelContext");
- Class<?> factory = null;
- try {
- FactoryFinder finder = getCamelContext().createFactoryFinder("META-INF/services/org/apache/camel/component/");
- factory = finder.findClass("ftp", "strategy.factory.");
- } catch (ClassNotFoundException e) {
- LOG.debug("'strategy.factory.class' not found", e);
- } catch (IOException e) {
- LOG.debug("No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e);
- }
-
- if (factory == null) {
- // use default
- factory = ObjectHelper.loadClass(DEFAULT_STRATEGYFACTORY_CLASS);
- if (factory == null) {
- throw new TypeNotPresentException("RemoteFileProcessStrategyFactory class not found", null);
- }
- }
-
- try {
- Method factoryMethod = factory.getMethod("createRemoteFileProcessStrategy", Map.class);
- return (RemoteFileProcessStrategy) ObjectHelper.invokeMethod(factoryMethod, null, getParamsAsMap());
- } catch (NoSuchMethodException e) {
- throw new TypeNotPresentException(factory.getSimpleName()
- + ".createRemoteFileProcessStrategy(RemoteFileEndpoint endpoint) method not found", e);
- }
- }
-
- protected Map<String, Object> getParamsAsMap() {
- Map<String, Object> params = new HashMap<String, Object>();
-
- if (isNoop()) {
- params.put("noop", Boolean.toString(true));
- }
- if (isDelete()) {
- params.put("delete", Boolean.toString(true));
- }
- if (moveNamePrefix != null) {
- params.put("moveNamePrefix", moveNamePrefix);
- }
- if (moveNamePostfix != null) {
- params.put("moveNamePostfix", moveNamePostfix);
- }
- if (preMoveNamePrefix != null) {
- params.put("preMoveNamePrefix", preMoveNamePrefix);
- }
- if (preMoveNamePostfix != null) {
- params.put("preMoveNamePostfix", preMoveNamePostfix);
- }
- if (expression != null) {
- params.put("expression", expression);
- }
- if (preMoveExpression != null) {
- params.put("preMoveExpression", preMoveExpression);
- }
- if (exclusiveReadLockStrategy != null) {
- params.put("exclusiveReadLockStrategy", exclusiveReadLockStrategy);
- }
- if (readLock != null) {
- params.put("readLock", readLock);
- }
- if (readLockTimeout > 0) {
- params.put("readLockTimeout", Long.valueOf(readLockTimeout));
- }
- return params;
+ return ((RemoteFileConfiguration) configuration).remoteServerInformation();
}
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java Mon Jan 26 11:52:06 2009
@@ -17,54 +17,48 @@
package org.apache.camel.component.file.remote;
import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileExchange;
import org.apache.camel.impl.DefaultExchange;
-public class RemoteFileExchange extends DefaultExchange {
- private RemoteFile remoteFile;
+public class RemoteFileExchange<T> extends GenericFileExchange<T> {
- public RemoteFileExchange(RemoteFileEndpoint endpoint, ExchangePattern pattern, RemoteFile remoteFile) {
- super(endpoint, pattern);
- setRemoteFile(remoteFile);
+ public RemoteFileExchange(CamelContext context, ExchangePattern pattern) {
+ super(context, pattern);
}
- public RemoteFileExchange(DefaultExchange parent, RemoteFile remoteFile) {
- super(parent);
- setRemoteFile(remoteFile);
+ public RemoteFileExchange(CamelContext context) {
+ super(context);
+ }
+
+ public RemoteFileExchange(DefaultExchange parent, RemoteFile<T> remoteFile) {
+ super(parent, remoteFile);
}
- public RemoteFile getRemoteFile() {
- return remoteFile;
+ public RemoteFileExchange(Endpoint fromEndpoint, ExchangePattern pattern) {
+ super(fromEndpoint, pattern);
}
- public void setRemoteFile(RemoteFile remoteFile) {
- setIn(new RemoteFileMessage(remoteFile));
- this.remoteFile = remoteFile;
- populateHeaders(remoteFile);
+ public RemoteFileExchange(Endpoint fromEndpoint) {
+ super(fromEndpoint);
+ }
+
+ public RemoteFileExchange(Exchange parent) {
+ super(parent);
}
- public Exchange newInstance() {
- return new RemoteFileExchange(this, remoteFile);
+ public RemoteFileExchange(RemoteFileEndpoint<T> endpoint, ExchangePattern pattern, RemoteFile<T> genericFile) {
+ super(endpoint, pattern, genericFile);
}
- protected void populateHeaders(RemoteFile remoteFile) {
+ @Override
+ protected void populateHeaders(GenericFile<T> remoteFile) {
+ super.populateHeaders(remoteFile);
if (remoteFile != null) {
- getIn().setHeader("file.remote.host", remoteFile.getHostname());
- getIn().setHeader("file.remote.absoluteName", remoteFile.getAbsolutelFileName());
- getIn().setHeader("file.remote.relativeName", remoteFile.getRelativeFileName());
- getIn().setHeader("file.remote.name", remoteFile.getFileName());
-
- getIn().setHeader("CamelFileName", remoteFile.getFileName());
- getIn().setHeader("CamelFilePath", remoteFile.getAbsolutelFileName());
- // set the parent if there is a parent folder
- if (remoteFile.getAbsolutelFileName() != null && remoteFile.getAbsolutelFileName().indexOf("/") != -1) {
- String parent = remoteFile.getAbsolutelFileName().substring(0, remoteFile.getAbsolutelFileName().lastIndexOf("/"));
- getIn().setHeader("CamelFileParent", parent);
- }
- if (remoteFile.getFileLength() > 0) {
- getIn().setHeader("CamelFileLength", new Long(remoteFile.getFileLength()));
- }
+ getIn().setHeader("file.remote.host", ((RemoteFile<T>) remoteFile).getHostname());
}
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExclusiveReadLockStrategy.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExclusiveReadLockStrategy.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExclusiveReadLockStrategy.java Mon Jan 26 11:52:06 2009
@@ -23,7 +23,7 @@
* <p/>
* Camel supports out of the box the following strategies:
* <ul>
- * <li>RemoteFileRenameExclusiveReadLockStrategy waiting until its possible to rename the file.</li>
+ * <li>RemoteFileRenameExclusiveReadLockStrategy waiting until its possible to rename the file.</li>
* </ul>
*/
public interface RemoteFileExclusiveReadLockStrategy {
@@ -32,7 +32,7 @@
* Acquires exclusive read lock to the file.
*
* @param operations remote file operations
- * @param file the remote file
+ * @param file the remote file
* @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
*/
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java?rev=737677&r1=737676&r2=737677&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileOperations.java Mon Jan 26 11:52:06 2009
@@ -16,117 +16,40 @@
*/
package org.apache.camel.component.file.remote;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
+import org.apache.camel.component.file.GenericFileOperationFailedException;
+import org.apache.camel.component.file.GenericFileOperations;
+
/**
* Remote file operations based on some backing framework
*/
-public interface RemoteFileOperations<T> {
+public interface RemoteFileOperations<T> extends GenericFileOperations<T> {
/**
* Connects to the remote server
*
* @param configuration configuraiton
* @return true if connected
- * @throws RemoteFileOperationFailedException can be thrown
+ * @throws GenericFileOperationFailedException
+ * can be thrown
*/
- boolean connect(RemoteFileConfiguration configuration) throws RemoteFileOperationFailedException;
+ boolean connect(RemoteFileConfiguration configuration) throws GenericFileOperationFailedException;
/**
* Returns whether we are connected to the remote server or not
*
* @return true if connected, false if not
- * @throws RemoteFileOperationFailedException can be thrown
+ * @throws GenericFileOperationFailedException
+ * can be thrown
*/
- boolean isConnected() throws RemoteFileOperationFailedException;
+ boolean isConnected() throws GenericFileOperationFailedException;
/**
* Discconects from the remote server
*
- * @throws RemoteFileOperationFailedException can be thrown
- */
- void disconnect() throws RemoteFileOperationFailedException;
-
- /**
- * Deletes the file from the remote server
- *
- * @param name name of the file
- * @return true if deleted, false if not
- * @throws RemoteFileOperationFailedException can be thrown
- */
- boolean deleteFile(String name) throws RemoteFileOperationFailedException;
-
- /**
- * Renames the file on the remote server
- *
- * @param from original name
- * @param to the new name
- * @return true if renamed, false if not
- * @throws RemoteFileOperationFailedException can be thrown
- */
- boolean renameFile(String from, String to) throws RemoteFileOperationFailedException;
-
- /**
- * Builds the directory structure on the remote server. Will test if the folder already exists.
- *
- * @param directory the directory path to build
- * @return true if build or already exists, false if not possbile (could be lack of permissions)
- * @throws RemoteFileOperationFailedException can be thrown
- */
- boolean buildDirectory(String directory) throws RemoteFileOperationFailedException;
-
- /**
- * Retrieves the remote file (download)
- *
- * @param name name of the file
- * @param out stream to write the content of the file into
- * @return true if file has been retrieved, false if not
- * @throws RemoteFileOperationFailedException can be thrown
- */
- boolean retrieveFile(String name, OutputStream out) throws RemoteFileOperationFailedException;
-
- /**
- * Stores the content as a new remote file (upload)
- *
- * @param name name of new file
- * @param body content of the file
- * @return true if the file was stored, false if not
- * @throws RemoteFileOperationFailedException can be thrown
- */
- boolean storeFile(String name, InputStream body) throws RemoteFileOperationFailedException;
-
- /**
- * Gets the current remote directory
- * @return the current directory path
- * @throws RemoteFileOperationFailedException can be thrown
- */
- String getCurrentDirectory() throws RemoteFileOperationFailedException;
-
- /**
- * Change the current remote directory
- *
- * @param path the path to change to
- * @throws RemoteFileOperationFailedException can be thrown
- */
- void changeCurrentDirectory(String path) throws RemoteFileOperationFailedException;
-
- /**
- * List the files in the current remote directory
- *
- * @return a list of backing objects representing the files
- * @throws RemoteFileOperationFailedException can be thrown
- */
- List listFiles() throws RemoteFileOperationFailedException;
-
- /**
- * List the files in the given remote directory
- *
- * @param path the remote directory
- * @return a list of backing objects representing the files
- * @throws RemoteFileOperationFailedException can be thrown
+ * @throws GenericFileOperationFailedException
+ * can be thrown
*/
- List listFiles(String path) throws RemoteFileOperationFailedException;
+ void disconnect() throws GenericFileOperationFailedException;
}