[jboss-svn-commits] JBL Code SVN: r8277 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 13 03:46:31 EST 2006
Author: b_georges
Date: 2006-12-13 03:46:29 -0500 (Wed, 13 Dec 2006)
New Revision: 8277
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
Log:
Added EPR constructor. Plus some house keeping.
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java 2006-12-13 03:28:33 UTC (rev 8276)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java 2006-12-13 08:46:29 UTC (rev 8277)
@@ -22,14 +22,23 @@
package org.jboss.internal.soa.esb.util;
import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.couriers.helpers.FtpFileHandler;
import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.util.FtpClientUtil;
import org.jboss.soa.esb.util.RemoteFileSystem;
+import org.jboss.soa.esb.util.RemoteFileSystemException;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPConnectMode;
@@ -48,35 +57,29 @@
* </p>
*/
-public class EdtFtpImpl implements RemoteFileSystem {
+public class EdtFtpImpl implements RemoteFileSystem
+{
+
+ private static final Logger _logger = Logger.getLogger(EdtFtpImpl.class);
+
private static final String TMP_SUFFIX = ".rosettaPart";
- public enum XFER_TYPE {
- ascii, binary
- };
+ private boolean m_bPassive;
- private ConfigTree m_oParms;
+ private int m_iPort;
- private String m_sFtpServer, m_sUser, m_sPasswd;
+ private FTPClient m_oConn = new FTPClient();
- private String m_sRemoteDir, m_sLocalDir;
+ private FTPEpr m_oEpr;
- private int m_iPort;
+ private ConfigTree m_oParms, m_oTree;
- private boolean m_bPassive;
+ private FTPTransferType m_oXferType;
- /*
- * (non-Javadoc)
- *
- * @see org.jboss.soa.esb.util.RemoteFileSystem#getRemoteDir()
- */
- public String getRemoteDir() {
- return m_sRemoteDir;
- }
+ private String m_sFtpServer, m_sUser, m_sPasswd;
- private FTPClient m_oConn = new FTPClient();
+ private String m_sRemoteDir, m_sLocalDir;
- private FTPTransferType m_oXferType = FTPTransferType.BINARY;
/**
* Checks validity and completeness of parameters, and keeps the info
@@ -96,29 +99,211 @@
* in remote computer </li>
*/
- public EdtFtpImpl(ConfigTree p_oP, boolean p_bConnect) throws Exception {
+ public EdtFtpImpl(ConfigTree p_oP, boolean p_bConnect) throws Exception
+ {
m_oParms = p_oP;
initialize(p_bConnect);
}
- public EdtFtpImpl(FTPEpr p_oP, boolean p_bConnect) throws Exception {
- // TODO initialize
+
+ public EdtFtpImpl(FTPEpr p_oP, boolean p_bConnect) throws Exception
+ {
+
+ m_oEpr = p_oP;
+
+ URL url = null;
+ try
+ {
+ url = m_oEpr.getURL();
+ } catch (MalformedURLException e)
+ {
+ throw new RemoteFileSystemException(e);
+ } catch (URISyntaxException e)
+ {
+ throw new RemoteFileSystemException(e);
+ }
+
+ m_sFtpServer = url.getHost();
+
+ String[] sa = null;
+
+ if (url.getUserInfo() != null)
+ sa = url.getUserInfo().split(":");
+
+ if (sa == null)
+ sa = new String[]
+ { "", "" };
+
+ m_sUser = (sa.length < 1) ? "" : sa[0];
+ m_sPasswd = (sa.length < 2) ? "" : sa[1];
+
+ m_sRemoteDir = url.getFile();
+
+ final String tmpdir = System.getProperty("java.io.tmpdir");
+ if ((m_sRemoteDir == null) || (m_sRemoteDir.equals("")))
+ m_sRemoteDir = ModulePropertyManager.getPropertyManager(
+ ModulePropertyManager.TRANSPORTS_MODULE).getProperty(
+ Environment.FTP_REMOTEDIR, tmpdir);
+
+ m_iPort = url.getPort();
+ if (m_iPort < 0)
+ m_iPort = url.getDefaultPort();
+
+ m_sLocalDir = ModulePropertyManager.getPropertyManager(
+ ModulePropertyManager.TRANSPORTS_MODULE).getProperty(
+ Environment.FTP_LOCALDIR, tmpdir);
+
+ m_bPassive = false;
+
+ try
+ {
+ m_bPassive = m_oEpr.getPassive();
+ } catch (URISyntaxException e)
+ {
+ _logger.warn(e);
+ }
+
+ // TODO there is still a bit of space for improvements here.
+ configTreeFromEpr();
+
+ initialize(p_bConnect);
+
}
- public EdtFtpImpl(List<KeyValuePair> attribs, boolean connect)
- throws Exception {
+ public EdtFtpImpl(List<KeyValuePair> p_oAttribs, boolean p_bConnect)
+ throws Exception
+ {
m_oParms = new ConfigTree("fromProps");
- for (KeyValuePair oCurr : attribs)
+ for (KeyValuePair oCurr : p_oAttribs)
m_oParms.setAttribute(oCurr.getKey(), oCurr.getValue());
- initialize(connect);
+ initialize(p_bConnect);
}
- private void initialize(boolean bConnect) throws Exception {
+ private void checkParms() throws Exception
+ {
+ m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
+ if (null == m_sFtpServer)
+ throw new Exception("No FTP server specified");
+
+ m_sUser = m_oParms.getAttribute(PARMS_USER);
+ if (null == m_sUser)
+ throw new Exception("No username specified for FTP");
+
+ m_sPasswd = m_oParms.getAttribute(PARMS_PASSWD);
+ if (null == m_sPasswd)
+ throw new Exception("No password specified for FTP");
+
+ m_sRemoteDir = m_oParms.getAttribute(PARMS_REMOTE_DIR);
+ if (null == m_sRemoteDir)
+ m_sRemoteDir = "";
+
+ m_sLocalDir = m_oParms.getAttribute(PARMS_LOCAL_DIR);
+ if (null == m_sLocalDir)
+ m_sLocalDir = ".";
+
+ String sAux = m_oParms.getAttribute(PARMS_PORT);
+ m_iPort = (null == sAux) ? 21 : Integer.parseInt(sAux);
+
+ // Dec-2006 (b_georges): it has been decided to set the Type to binary.
+ m_oXferType = FTPTransferType.BINARY;
+
+ m_bPassive = false;
+ sAux = m_oParms.getAttribute(PARMS_PASSIVE);
+ m_bPassive = (null != sAux) && Boolean.parseBoolean(sAux);
+
+ return;
+ }
+
+ private void configTreeFromEpr() throws RemoteFileSystemException
+ {
+ try
+ {
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_FTP_SERVER,
+ m_sFtpServer);
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_USER, m_sUser);
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_PASSWD, m_sPasswd);
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR,
+ m_sRemoteDir);
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_PORT, Integer
+ .toString(m_iPort));
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, m_sLocalDir);
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_ASCII, Boolean
+ .toString(false));
+ m_oTree.setAttribute(RemoteFileSystem.PARMS_PASSIVE, Boolean
+ .toString(m_bPassive));
+ } catch (Exception e)
+ {
+ throw new RemoteFileSystemException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.util.RemoteFileSystem#deleteRemoteFile(java.lang.String)
+ */
+ public void deleteRemoteFile(String p_sFile) throws Exception
+ {
+ m_oConn.delete(getRemoteDir() + "/" + new File(p_sFile).getName());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.util.RemoteFileSystem#downloadFile(java.lang.String,
+ * java.lang.String)
+ */
+ public void downloadFile(String p_sFile, String p_sFinalName)
+ throws Exception
+ {
+ File oLocalDir = new File(m_sLocalDir);
+ File oLclFile = File.createTempFile("Rosetta_", TMP_SUFFIX, oLocalDir);
+
+ try
+ {
+ oLclFile.delete();
+ } catch (Exception e)
+ {
+ }
+ m_oConn.get(FtpUtils.fileToFtpString(oLclFile), p_sFile);
+
+ File oNew = new File(oLocalDir, p_sFinalName);
+ if (oNew.exists())
+ oNew.delete();
+ oLclFile.renameTo(oNew);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.util.RemoteFileSystem#getFileListFromRemoteDir(java.lang.String)
+ */
+ public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception
+ {
+ String sSuffix = (null == p_sSuffix) ? "*" : "*" + p_sSuffix;
+ return m_oConn.dir(sSuffix);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.util.RemoteFileSystem#getRemoteDir()
+ */
+ public String getRemoteDir()
+ {
+ return m_sRemoteDir;
+ }
+
+ private void initialize(boolean bConnect) throws Exception
+ {
checkParms();
- if (bConnect) {
- try {
+ if (bConnect)
+ {
+ try
+ {
m_oConn.setRemoteHost(m_sFtpServer);
- } catch (UnknownHostException ex) {
+ } catch (UnknownHostException ex)
+ {
ex.printStackTrace();
throw ex;
@@ -134,6 +319,7 @@
m_oConn.password(m_sPasswd);
m_oConn.setConnectMode((m_bPassive) ? FTPConnectMode.PASV
: FTPConnectMode.ACTIVE);
+ m_oConn.setType(m_oXferType);
}
}
@@ -142,73 +328,69 @@
*
* @see org.jboss.soa.esb.util.RemoteFileSystem#quit()
*/
- public void quit() {
+ public void quit()
+ {
if (null != m_oConn)
- try {
+ try
+ {
m_oConn.quit();
- } catch (Exception e) {
- }
+ } catch (Exception e)
+ {
+ }
}
/*
* (non-Javadoc)
*
- * @see org.jboss.soa.esb.util.RemoteFileSystem#deleteRemoteFile(java.lang.String)
- */
- public void deleteRemoteFile(String p_sFile) throws Exception {
- // TODO improve error handling.
-
- m_oConn.delete(getRemoteDir() + "/" + new File(p_sFile).getName());
- }
-
- /*
- * (non-Javadoc)
- *
* @see org.jboss.soa.esb.util.RemoteFileSystem#remoteDelete(java.io.File)
*/
- public void remoteDelete(File p_oFile) throws Exception {
+ public void remoteDelete(File p_oFile) throws Exception
+ {
m_oConn.delete(FtpUtils.fileToFtpString(p_oFile));
}
/*
* (non-Javadoc)
*
- * @see org.jboss.soa.esb.util.RemoteFileSystem#getFileListFromRemoteDir(java.lang.String)
+ * @see org.jboss.soa.esb.util.RemoteFileSystem#remoteRename(java.io.File,
+ * java.io.File)
*/
- public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception {
- String sSuffix = (null == p_sSuffix) ? "*" : "*" + p_sSuffix;
- return m_oConn.dir(sSuffix);
+ public void remoteRename(File p_oFrom, File p_oTo) throws Exception
+ {
+ try
+ {
+ m_oConn.rename(FtpClientUtil.fileToFtpString(p_oFrom), FtpUtils
+ .fileToFtpString(p_oTo));
+ } catch (Exception e)
+ {
+ String sMess = this.getClass().getSimpleName()
+ + " can't rename in remote directory <" + e.getMessage()
+ + ">";
+ throw new Exception(sMess);
+ }
}
/*
* (non-Javadoc)
*
- * @see org.jboss.soa.esb.util.RemoteFileSystem#setRemoteDir(java.lang.String)
- */
- public void setRemoteDir(String p_sDir) throws Exception {
- // TODO deal with null string
-
- m_oConn.chdir(p_sDir);
- }
-
- /*
- * (non-Javadoc)
- *
* @see org.jboss.soa.esb.util.RemoteFileSystem#renameInRemoteDir(java.lang.String,
* java.lang.String)
*/
public void renameInRemoteDir(String p_sFrom, String p_sTo)
- throws Exception {
+ throws Exception
+ {
String sRmtFrom = new File(p_sFrom).getName();
String sRmtTo = new File(p_sTo).getName();
- try {
+ try
+ {
m_oConn.rename(getRemoteDir() + "/" + sRmtFrom, getRemoteDir()
+ "/" + sRmtTo);
- } catch (Exception e) {
+ } catch (Exception e)
+ {
String sMess = this.getClass().getSimpleName()
- + " can't rename in remote directory <" + e.getMessage()
- + ">";
+ + " can't rename in remote directory <" + e.getMessage()
+ + ">";
throw new Exception(sMess);
}
}
@@ -216,19 +398,13 @@
/*
* (non-Javadoc)
*
- * @see org.jboss.soa.esb.util.RemoteFileSystem#remoteRename(java.io.File,
- * java.io.File)
+ * @see org.jboss.soa.esb.util.RemoteFileSystem#setRemoteDir(java.lang.String)
*/
- public void remoteRename(File p_oFrom, File p_oTo) throws Exception {
- try {
- m_oConn.rename(FtpClientUtil.fileToFtpString(p_oFrom), FtpUtils
- .fileToFtpString(p_oTo));
- } catch (Exception e) {
- String sMess = this.getClass().getSimpleName()
- + " can't rename in remote directory <" + e.getMessage()
- + ">";
- throw new Exception(sMess);
- }
+ public void setRemoteDir(String p_sDir) throws Exception
+ {
+ // TODO deal with null string
+
+ m_oConn.chdir(p_sDir);
}
/*
@@ -237,82 +413,12 @@
* @see org.jboss.soa.esb.util.RemoteFileSystem#uploadFile(java.io.File,
* java.lang.String)
*/
- public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception {
+ public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception
+ {
String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
String sRemoteTmp = sRemoteOK + TMP_SUFFIX;
- m_oConn.setType(m_oXferType);
m_oConn.put(FtpUtils.fileToFtpString(p_oFile), sRemoteTmp);
m_oConn.rename(sRemoteTmp, sRemoteOK);
}
- /*
- * (non-Javadoc)
- *
- * @see org.jboss.soa.esb.util.RemoteFileSystem#downloadFile(java.lang.String,
- * java.lang.String)
- */
- public void downloadFile(String p_sFile, String p_sFinalName)
- throws Exception {
- File oLocalDir = new File(m_sLocalDir);
- File oLclFile = File.createTempFile("Rosetta_", TMP_SUFFIX, oLocalDir);
-
- try {
- oLclFile.delete();
- } catch (Exception e) {
- }
- m_oConn.setType(m_oXferType);
- m_oConn.get(FtpUtils.fileToFtpString(oLclFile), p_sFile);
-
- File oNew = new File(oLocalDir, p_sFinalName);
- if (oNew.exists())
- oNew.delete();
- oLclFile.renameTo(oNew);
- }
-
- // Beware !!! The logic here seems wrong, but it works
- // It appears that there's some kind of bug in the edtftpj.jar library
- // The !XFER_TYPE.ascii.equals(p_oMode) should NOT be negated
- // But it works when negated (newlines from Unix to DOS)
- private void setXferType(XFER_TYPE p_oMode) {
- m_oXferType = !XFER_TYPE.ascii.equals(p_oMode) ? FTPTransferType.ASCII
- : FTPTransferType.BINARY;
- }
-
- private void checkParms() throws Exception {
- m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
- if (null == m_sFtpServer)
- throw new Exception("No FTP server specified");
-
- m_sUser = m_oParms.getAttribute(PARMS_USER);
- if (null == m_sUser)
- throw new Exception("No username specified for FTP");
-
- m_sPasswd = m_oParms.getAttribute(PARMS_PASSWD);
- if (null == m_sPasswd)
- throw new Exception("No password specified for FTP");
-
- m_sRemoteDir = m_oParms.getAttribute(PARMS_REMOTE_DIR);
- if (null == m_sRemoteDir)
- m_sRemoteDir = "";
-
- m_sLocalDir = m_oParms.getAttribute(PARMS_LOCAL_DIR);
- if (null == m_sLocalDir)
- m_sLocalDir = ".";
-
- String sAux = m_oParms.getAttribute(PARMS_PORT);
- m_iPort = (null == sAux) ? 21 : Integer.parseInt(sAux);
-
- boolean bAscii = false;
- sAux = m_oParms.getAttribute(PARMS_ASCII);
- if (null != sAux)
- bAscii = Boolean.parseBoolean(sAux);
- setXferType((bAscii) ? XFER_TYPE.ascii : XFER_TYPE.binary);
-
- m_bPassive = false;
- sAux = m_oParms.getAttribute(PARMS_PASSIVE);
- m_bPassive = (null != sAux) && Boolean.parseBoolean(sAux);
-
- return;
- }
-
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list