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 2008/04/12 11:33:30 UTC
svn commit: r647407 - in
/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote:
FtpConsumer.java FtpProducer.java SftpConsumer.java SftpEndpoint.java
SftpProducer.java
Author: davsclaus
Date: Sat Apr 12 02:33:26 2008
New Revision: 647407
URL: http://svn.apache.org/viewvc?rev=647407&view=rev
Log:
CAMEL-445 porting FTP fixes to SFTP
Modified:
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=647407&r1=647406&r2=647407&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java Sat Apr 12 02:33:26 2008
@@ -32,7 +32,7 @@
public class FtpConsumer extends RemoteFileConsumer<RemoteFileExchange> {
private static final transient Log LOG = LogFactory.getLog(FtpConsumer.class);
- private final FtpEndpoint endpoint;
+ private FtpEndpoint endpoint;
private long lastPollTime;
private FTPClient client;
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java?rev=647407&r1=647406&r2=647407&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java Sat Apr 12 02:33:26 2008
@@ -29,8 +29,8 @@
public class FtpProducer extends RemoteFileProducer<RemoteFileExchange> {
private static final transient Log LOG = LogFactory.getLog(FtpProducer.class);
- FtpEndpoint endpoint;
- private final FTPClient client;
+ private FtpEndpoint endpoint;
+ private FTPClient client;
public FtpProducer(FtpEndpoint endpoint, FTPClient client) {
super(endpoint);
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java?rev=647407&r1=647406&r2=647407&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java Sat Apr 12 02:33:26 2008
@@ -54,7 +54,6 @@
this.session = session;
}
- // TODO: is there a way to avoid copy-pasting the reconnect logic?
protected void connectIfNecessary() throws JSchException {
if (channel == null || !channel.isConnected()) {
if (session == null || !session.isConnected()) {
@@ -69,7 +68,6 @@
}
}
- // TODO: is there a way to avoid copy-pasting the reconnect logic?
protected void disconnect() throws JSchException {
if (session != null) {
LOG.info("Session is being explicitly disconnected");
@@ -81,8 +79,8 @@
}
}
- // TODO: is there a way to avoid copy-pasting the reconnect logic?
protected void poll() throws Exception {
+ // TODO: is there a way to avoid copy-pasting the reconnect logic?
connectIfNecessary();
// If the attempt to connect isn't successful, then the thrown
// exception will signify that we couldn't poll
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java?rev=647407&r1=647406&r2=647407&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java Sat Apr 12 02:33:26 2008
@@ -21,6 +21,7 @@
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
+
import org.apache.camel.Processor;
public class SftpEndpoint extends RemoteFileEndpoint<RemoteFileExchange> {
Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java?rev=647407&r1=647406&r2=647407&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java Sat Apr 12 02:33:26 2008
@@ -33,7 +33,7 @@
public class SftpProducer extends RemoteFileProducer<RemoteFileExchange> {
private static final transient Log LOG = LogFactory.getLog(SftpProducer.class);
- SftpEndpoint endpoint;
+ private SftpEndpoint endpoint;
private ChannelSftp channel;
private Session session;
@@ -43,7 +43,6 @@
this.session = session;
}
- // TODO: is there a way to avoid copy-pasting the reconnect logic?
protected void connectIfNecessary() throws JSchException {
if (channel == null || !channel.isConnected()) {
if (session == null || !session.isConnected()) {
@@ -58,7 +57,6 @@
}
}
- // TODO: is there a way to avoid copy-pasting the reconnect logic?
protected void disconnect() throws JSchException {
if (session != null) {
LOG.info("Session is being explicitly disconnected");
@@ -70,8 +68,8 @@
}
}
- // TODO: is there a way to avoid copy-pasting the reconnect logic?
public void process(Exchange exchange) throws Exception {
+ // TODO: is there a way to avoid copy-pasting the reconnect logic?
connectIfNecessary();
// If the attempt to connect isn't successful, then the thrown
// exception will signify that we couldn't deliver
@@ -101,16 +99,17 @@
int lastPathIndex = fileName.lastIndexOf('/');
if (lastPathIndex != -1) {
- boolean success = buildDirectory(channel, fileName.substring(0, lastPathIndex));
+ String directory = fileName.substring(0, lastPathIndex);
+ boolean success = buildDirectory(channel, directory);
if (!success) {
- LOG.warn("Couldn't buildDirectory: " + fileName.substring(0, lastPathIndex) + " (either permissions deny it, or it already exists)");
+ LOG.warn("Couldn't build directory: " + directory + " (either permissions deny it, or it already exists)");
}
}
channel.put(payload, fileName);
LOG.info("Sent: " + fileName + " to " + endpoint.getConfiguration());
} finally {
- if (null != payload) {
+ if (payload != null) {
payload.close();
}
}
@@ -134,21 +133,26 @@
super.doStop();
}
- protected static boolean buildDirectory(ChannelSftp sftpClient, String dirName) throws IOException {
+ protected static boolean buildDirectory(ChannelSftp sftpClient, String dirName)
+ throws IOException, SftpException {
+
boolean atLeastOneSuccess = false;
final StringBuilder sb = new StringBuilder(dirName.length());
final String[] dirs = dirName.split("\\/");
for (String dir : dirs) {
sb.append(dir).append('/');
- try {
- sftpClient.mkdir(sb.toString());
- if (!atLeastOneSuccess) {
- atLeastOneSuccess = true;
- }
- } catch (SftpException e) {
- // TODO: not sure what to do here...
+ String directory = sb.toString();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Trying to build directory: " + directory);
+ }
+ sftpClient.mkdir(directory);
+ if (!atLeastOneSuccess) {
+ atLeastOneSuccess = true;
}
}
+
return atLeastOneSuccess;
}
+
}