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/04 15:56:49 UTC
svn commit: r951412 - in
/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote:
FtpOperations.java FtpsComponent.java FtpsConfiguration.java
FtpsEndpoint.java FtpsOperations.java
Author: davsclaus
Date: Fri Jun 4 13:56:49 2010
New Revision: 951412
URL: http://svn.apache.org/viewvc?rev=951412&view=rev
Log:
CAMEL-2790: FTPS now allows to use secure data channel for transfering file data. Added options to set protection level and buffer size as well.
Added:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java (with props)
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsConfiguration.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsEndpoint.java
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=951412&r1=951411&r2=951412&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Fri Jun 4 13:56:49 2010
@@ -436,6 +436,10 @@ public class FtpOperations implements Re
}
}
+ protected FTPClient getFtpClient() {
+ return client;
+ }
+
private boolean buildDirectoryChunks(String dirName) throws IOException {
final StringBuilder sb = new StringBuilder(dirName.length());
final String[] dirs = dirName.split("/|\\\\");
@@ -457,5 +461,5 @@ public class FtpOperations implements Re
return success;
}
-
+
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java?rev=951412&r1=951411&r2=951412&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsComponent.java Fri Jun 4 13:56:49 2010
@@ -27,10 +27,9 @@ import org.apache.commons.net.ftp.FTPFil
/**
* FTP Secure (FTP over SSL/TLS) Component.
* <p/>
- * If desired, the JVM property -Djavax.net.debug=all can be used to see wire-level SSL details.
+ * If desired, the JVM property <tt>-Djavax.net.debug=all</tt> can be used to see wire-level SSL details.
*
* @version $Revision$
- * @author muellerc
*/
public class FtpsComponent extends FtpComponent {
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsConfiguration.java?rev=951412&r1=951411&r2=951412&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsConfiguration.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsConfiguration.java Fri Jun 4 13:56:49 2010
@@ -22,12 +22,14 @@ import java.net.URI;
* FTP Secure (FTP over SSL/TLS) configuration
*
* @version $Revision$
- * @author muellerc
*/
public class FtpsConfiguration extends FtpConfiguration {
private String securityProtocol = "TLS";
private boolean isImplicit;
+ private boolean useSecureDataChannel;
+ private String execProt = "P";
+ private long execPbsz;
public FtpsConfiguration() {
setProtocol("ftps");
@@ -71,4 +73,51 @@ public class FtpsConfiguration extends F
public void setIsImplicit(boolean isImplicit) {
this.isImplicit = isImplicit;
}
+
+ public boolean isUseSecureDataChannel() {
+ return useSecureDataChannel;
+ }
+
+ /**
+ * Sets whether to use secure data channel when transferring file content
+ * <p/>
+ * Default is <tt>false</tt>
+ * @see #setExecPbsz(long)
+ * @see #setExecProt(String)
+ */
+ public void setUseSecureDataChannel(boolean useSecureDataChannel) {
+ this.useSecureDataChannel = useSecureDataChannel;
+ }
+
+ public String getExecProt() {
+ return execProt;
+ }
+
+ /**
+ * When using secure data channel you can set the exec protection level
+ * <p/>
+ * PROT command. C - Clear S - Safe(SSL protocol only) E - Confidential(SSL protocol only) P - Private
+ * <p/>
+ * Default value is <tt>P</tt>
+ *
+ * @param execProt either C, S, E or P
+ */
+ public void setExecProt(String execProt) {
+ this.execProt = execProt;
+ }
+
+ public long getExecPbsz() {
+ return execPbsz;
+ }
+
+ /**
+ * When using secure data channel you can set the exec protection buffer size
+ * <p/>
+ * Default value is <tt>0</tt>
+ *
+ * @param execPbsz the buffer size
+ */
+ public void setExecPbsz(long execPbsz) {
+ this.execPbsz = execPbsz;
+ }
}
\ No newline at end of file
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsEndpoint.java?rev=951412&r1=951411&r2=951412&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsEndpoint.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsEndpoint.java Fri Jun 4 13:56:49 2010
@@ -25,8 +25,9 @@ import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.IntrospectionSupport;
import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPSClient;
@@ -34,7 +35,6 @@ import org.apache.commons.net.ftp.FTPSCl
* FTP Secure (FTP over SSL/TLS) endpoint
*
* @version $Revision$
- * @author muellerc
*/
public class FtpsEndpoint extends FtpEndpoint<FTPFile> {
@@ -110,6 +110,33 @@ public class FtpsEndpoint extends FtpEnd
return client;
}
+ @Override
+ protected RemoteFileOperations<FTPFile> createRemoteFileOperations() throws Exception {
+ // configure ftp client
+ FTPSClient client = getFtpsClient();
+
+ if (client == null) {
+ // must use a new client if not explicit configured to use a custom client
+ client = (FTPSClient) createFtpClient();
+ }
+
+ if (ftpClientParameters != null) {
+ IntrospectionSupport.setProperties(client, ftpClientParameters);
+ }
+
+ if (ftpClientConfigParameters != null) {
+ // client config is optional so create a new one if we have parameter for it
+ if (ftpClientConfig == null) {
+ ftpClientConfig = new FTPClientConfig();
+ }
+ IntrospectionSupport.setProperties(ftpClientConfig, ftpClientConfigParameters);
+ }
+
+ FtpsOperations operations = new FtpsOperations(client, getFtpClientConfig());
+ operations.setEndpoint(this);
+ return operations;
+ }
+
/**
* Returns the FTPSClient. This method exists only for convenient.
*
Added: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java?rev=951412&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java (added)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java Fri Jun 4 13:56:49 2010
@@ -0,0 +1,70 @@
+/**
+ * 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.io.IOException;
+import javax.net.ssl.SSLException;
+
+import org.apache.camel.component.file.GenericFileOperationFailedException;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.commons.net.ftp.FTPSClient;
+
+/**
+ * FTP Secure (FTP over SSL/TLS) operations
+ *
+ * @version $Revision$
+ */
+public class FtpsOperations extends FtpOperations {
+
+ public FtpsOperations(FTPSClient client, FTPClientConfig clientConfig) {
+ super(client, clientConfig);
+ }
+
+ @Override
+ public boolean connect(RemoteFileConfiguration configuration) throws GenericFileOperationFailedException {
+ boolean answer = super.connect(configuration);
+
+ FtpsConfiguration config = (FtpsConfiguration) configuration;
+ if (answer && config.isUseSecureDataChannel()) {
+ try {
+ // execProt must be configured
+ ObjectHelper.notEmpty(config.getExecProt(), "execProt", config);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Secure data channel being initialized with execPbsz=" + config.getExecPbsz() + ", execPort=" + config.getExecProt());
+ }
+ getFtpClient().execPBSZ(config.getExecPbsz());
+ getFtpClient().execPROT(config.getExecProt());
+ } catch (SSLException e) {
+ throw new GenericFileOperationFailedException(client.getReplyCode(),
+ client.getReplyString(), e.getMessage(), e);
+ } catch (IOException e) {
+ throw new GenericFileOperationFailedException(client.getReplyCode(),
+ client.getReplyString(), e.getMessage(), e);
+ }
+ }
+
+ return answer;
+ }
+
+ @Override
+ protected FTPSClient getFtpClient() {
+ return (FTPSClient) super.getFtpClient();
+ }
+
+}
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
------------------------------------------------------------------------------
svn:keywords = Rev Date