| Commit in servicemix/base/src/main/java/org/servicemix/components/net on MAIN | |||
| FTPPoller.java | +12 | -13 | 1.2 -> 1.3 |
Fix SM-78 : patch provided by John Hurst
servicemix/base/src/main/java/org/servicemix/components/net
diff -u -r1.2 -r1.3 --- FTPPoller.java 19 Jul 2005 10:52:39 -0000 1.2 +++ FTPPoller.java 6 Oct 2005 07:35:44 -0000 1.3 @@ -40,7 +40,7 @@
* and then sends them into the normalized message service, using a plugable transformer * and removes them. *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class FTPPoller extends PollingComponentSupport {
private static final Log log = LogFactory.getLog(FTPPoller.class);
@@ -50,17 +50,14 @@
private FileMarshaler marshaler = new DefaultFileMarshaler();
private Set workingSet = new CopyOnWriteArraySet();
+ private String getWorkingPath() {
+ return path == null ? "." : path;
+ }
public void poll() throws Exception {
FTPClient ftp = (FTPClient) borrowClient();
try {
- FTPFile[] files = null;
- if (path != null) {
- files = ftp.listFiles(path);
- }
- else {
- files = ftp.listFiles();
- }
+ FTPFile[] files = ftp.listFiles(getWorkingPath());
for (int i = 0; i < files.length; i++) {
final FTPFile file = files[i];
workingSet.add(file);
@@ -109,8 +106,6 @@
/**
* The set of FTPFiles that this component is currently working on
- * - * @return
*/
public Set getWorkingSet() {
return workingSet;
@@ -127,11 +122,14 @@
}
protected void processFile(FTPFile file) {
+ if (file.getName().equals(".") || file.getName().equals("..")) { // TODO: what about other directories? + return; + }
FTPClient client = null;
try {
client = (FTPClient) borrowClient();
processFile(client, file);
- client.deleteFile(file.getName());
+ client.deleteFile(getWorkingPath() + file.getName()); // REVIEW: what if deleteFile() fails?
}
catch (Exception e) {
log.error("Failed to process file: " + file + ". Reason: " + e, e);
@@ -145,12 +143,13 @@
protected void processFile(FTPClient client, FTPFile file) throws Exception {
String name = file.getName();
- InputStream in = client.retrieveFileStream(name);
+ InputStream in = client.retrieveFileStream(getWorkingPath() + name);
+ client.completePendingCommand();
InOnly exchange = getExchangeFactory().createInOnlyExchange();
NormalizedMessage message = exchange.createMessage();
exchange.setInMessage(message);
marshaler.readMessage(exchange, message, in, name);
-
+ done(exchange);
}
