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 2010/06/21 11:12:55 UTC
svn commit: r956507 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/component/file/
components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/
Author: davsclaus
Date: Mon Jun 21 09:12:55 2010
New Revision: 956507
URL: http://svn.apache.org/viewvc?rev=956507&view=rev
Log:
CAMEL-2829: Improved re-connect logic in camel-ftp to cater for issue with Apache FTPSClient problem.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=956507&r1=956506&r2=956507&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Mon Jun 21 09:12:55 2010
@@ -205,6 +205,17 @@ public abstract class GenericFileConsume
protected abstract void pollDirectory(String fileName, List<GenericFile<T>> fileList);
/**
+ * Sets the operations to be used.
+ * <p/>
+ * Can be used to set a fresh operations in case of recovery attempts
+ *
+ * @param operations the operations
+ */
+ public void setOperations(GenericFileOperations<T> operations) {
+ this.operations = operations;
+ }
+
+ /**
* Processes the exchange
*
* @param exchange the exchange
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java?rev=956507&r1=956506&r2=956507&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java Mon Jun 21 09:12:55 2010
@@ -63,7 +63,7 @@ public final class GenericFileConverter
@Converter
public static InputStream genericFileToInputStream(GenericFile<?> file, Exchange exchange) throws IOException {
if (exchange != null) {
- // ensure the body is loaded as we do not want a toString of java.io.File handle returned, but the file content
+ // ensure the body is loaded as we want the input stream of the body
file.getBinding().loadContent(exchange, file);
return exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, file.getBody());
} else {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=956507&r1=956506&r2=956507&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java Mon Jun 21 09:12:55 2010
@@ -36,7 +36,7 @@ import org.apache.commons.logging.LogFac
public class GenericFileProducer<T> extends DefaultProducer {
protected final transient Log log = LogFactory.getLog(getClass());
protected final GenericFileEndpoint<T> endpoint;
- protected final GenericFileOperations<T> operations;
+ protected GenericFileOperations<T> operations;
protected GenericFileProducer(GenericFileEndpoint<T> endpoint, GenericFileOperations<T> operations) {
super(endpoint);
@@ -59,6 +59,17 @@ public class GenericFileProducer<T> exte
}
/**
+ * Sets the operations to be used.
+ * <p/>
+ * Can be used to set a fresh operations in case of recovery attempts
+ *
+ * @param operations the operations
+ */
+ public void setOperations(GenericFileOperations<T> operations) {
+ this.operations = operations;
+ }
+
+ /**
* Perform the work to process the fileExchange
*
* @param exchange fileExchange
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=956507&r1=956506&r2=956507&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 Jun 21 09:12:55 2010
@@ -44,7 +44,7 @@ public abstract class RemoteFileConsumer
}
protected boolean prePollCheck() throws Exception {
- connectIfNecessary();
+ recoverableConnectIfNecessary();
if (!loggedIn) {
String message = "Could not connect/login to: " + remoteServer() + ". Will skip this poll.";
log.warn(message);
@@ -85,6 +85,26 @@ public abstract class RemoteFileConsumer
}
}
+ protected void recoverableConnectIfNecessary() throws Exception {
+ try {
+ connectIfNecessary();
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not connect to: " + getEndpoint() + ". Will try to recover.", e);
+ }
+ loggedIn = false;
+ }
+
+ // recover by re-creating operations which should most likely be able to recover
+ if (!loggedIn) {
+ if (log.isDebugEnabled()) {
+ log.debug("Trying to recover connection to: " + getEndpoint() + " with a fresh client.");
+ }
+ setOperations(getEndpoint().createRemoteFileOperations());
+ connectIfNecessary();
+ }
+ }
+
protected void connectIfNecessary() throws IOException {
if (!loggedIn) {
if (log.isDebugEnabled()) {
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=956507&r1=956506&r2=956507&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 Jun 21 09:12:55 2010
@@ -112,6 +112,14 @@ public abstract class RemoteFileEndpoint
protected abstract GenericFileProducer<T> buildProducer();
/**
+ * Creates the operations to be used by the consumer or producer.
+ *
+ * @return a new created operations
+ * @throws Exception is thrown if error creating operations.
+ */
+ protected abstract RemoteFileOperations<T> createRemoteFileOperations() throws Exception;
+
+ /**
* Returns human readable server information for logging purpose
*/
public String remoteServerInformation() {
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java?rev=956507&r1=956506&r2=956507&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java Mon Jun 21 09:12:55 2010
@@ -23,8 +23,7 @@ import org.apache.camel.component.file.G
import org.apache.camel.util.ExchangeHelper;
/**
- * Remote file producer. Handles connecting and disconnecting if we are not.
- * Generic type F is the remote system implementation of a file.
+ * Generic remote file producer for all the FTP variations.
*/
public class RemoteFileProducer<T> extends GenericFileProducer<T> implements ServicePoolAware {
@@ -120,7 +119,7 @@ public class RemoteFileProducer<T> exten
}
}
- connectIfNecessary();
+ recoverableConnectIfNecessary();
if (!loggedIn) {
// must be logged in to be able to upload the file
String message = "Cannot connect/login to: " + getEndpoint().remoteServerInformation();
@@ -161,6 +160,26 @@ public class RemoteFileProducer<T> exten
super.doStop();
}
+ protected void recoverableConnectIfNecessary() throws Exception {
+ try {
+ connectIfNecessary();
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not connect to: " + getEndpoint() + ". Will try to recover.", e);
+ }
+ loggedIn = false;
+ }
+
+ // recover by re-creating operations which should most likely be able to recover
+ if (!loggedIn) {
+ if (log.isDebugEnabled()) {
+ log.debug("Trying to recover connection to: " + getEndpoint() + " with a fresh client.");
+ }
+ setOperations(getEndpoint().createRemoteFileOperations());
+ connectIfNecessary();
+ }
+ }
+
protected void connectIfNecessary() throws GenericFileOperationFailedException {
if (!loggedIn) {
if (log.isDebugEnabled()) {