[jboss-svn-commits] JBL Code SVN: r8249 - in labs/jbossesb/trunk/product: core/rosetta/src/org/jboss/internal/soa/esb/couriers core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers core/rosetta/src/org/jboss/internal/soa/esb/util core/rosetta/src/org/jboss/soa/esb/addressing/eprs core/rosetta/src/org/jboss/soa/esb/common core/rosetta/src/org/jboss/soa/esb/util core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests install/conf
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 12 06:32:36 EST 2006
Author: mark.little at jboss.com
Date: 2006-12-12 06:32:13 -0500 (Tue, 12 Dec 2006)
New Revision: 8249
Added:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandler.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FtpFileHandlerUnitTest.java
Removed:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerInterface.java
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerFactory.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FtpFileHandler.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
Log:
Added FtpFileHandler unit test and a few TODOs based on the results.
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -34,7 +34,7 @@
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.couriers.helpers.FileHandlerFactory;
-import org.jboss.internal.soa.esb.couriers.helpers.FileHandlerInterface;
+import org.jboss.internal.soa.esb.couriers.helpers.FileHandler;
import org.jboss.internal.soa.esb.couriers.helpers.LocalFileHandler;
import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.couriers.CourierException;
@@ -96,7 +96,7 @@
try
{
_url = _epr.getURL();
- FileHandlerInterface handler = FileHandlerFactory.getInstance().getFileHandler(_epr);
+ FileHandler handler = FileHandlerFactory.getInstance().getFileHandler(_epr);
if (handler instanceof LocalFileHandler)
{
_localFhandler = (LocalFileHandler)handler;
@@ -133,7 +133,7 @@
return false;
// FileHandler is durable only for local filesystem (see checkEprParms())
- FileHandlerInterface handler = (null!=_localFhandler) ? _localFhandler
+ FileHandler handler = (null!=_localFhandler) ? _localFhandler
: FileHandlerFactory.getInstance().getFileHandler(_epr);
if (null==handler)
throw new CourierException("Can't find appropriate file handler for "+_url.toString());
@@ -172,7 +172,7 @@
long limit = System.currentTimeMillis() + ((millis < 100) ? 100 : millis);
do
{
- FileHandlerInterface handler = (null!=_localFhandler) ? _localFhandler
+ FileHandler handler = (null!=_localFhandler) ? _localFhandler
: FileHandlerFactory.getInstance().getFileHandler(_epr);
File[] files = handler.getFileList();
if (null!=files && files.length>0)
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandler.java (from rev 8227, labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerInterface.java)
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerInterface.java 2006-12-11 15:04:16 UTC (rev 8227)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandler.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.internal.soa.esb.couriers.helpers;
+
+import java.io.File;
+
+import org.jboss.soa.esb.couriers.CourierException;
+
+public interface FileHandler
+{
+ abstract File[] getFileList() throws CourierException;
+ abstract byte[] getFileContents(File file) throws CourierException;
+ abstract boolean renameFile(File from, File to) throws CourierException;
+ abstract boolean deleteFile(File file) throws CourierException;
+}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerFactory.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerFactory.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -32,7 +32,7 @@
public static FileHandlerFactory getInstance() { return _instance; }
- public FileHandlerInterface getFileHandler(FileEpr epr) throws CourierException
+ public FileHandler getFileHandler(FileEpr epr) throws CourierException
{
if (epr instanceof FTPEpr) return new FtpFileHandler ((FTPEpr)epr);
Deleted: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerInterface.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerInterface.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FileHandlerInterface.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -1,35 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.internal.soa.esb.couriers.helpers;
-
-import java.io.File;
-
-import org.jboss.soa.esb.couriers.CourierException;
-
-public interface FileHandlerInterface
-{
- abstract File[] getFileList() throws CourierException;
- abstract byte[] getFileContents(File file) throws CourierException;
- abstract boolean renameFile(File from, File to) throws CourierException;
- abstract boolean deleteFile(File file) throws CourierException;
-}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FtpFileHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FtpFileHandler.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FtpFileHandler.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -1,3 +1,25 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
package org.jboss.internal.soa.esb.couriers.helpers;
import java.io.File;
@@ -7,6 +29,8 @@
import org.apache.log4j.Logger;
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.couriers.CourierUtil;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -14,74 +38,114 @@
import org.jboss.soa.esb.util.RemoteFileSystemException;
import org.jboss.soa.esb.util.RemoteFileSystemFactory;
-public class FtpFileHandler implements FileHandlerInterface
+public class FtpFileHandler implements FileHandler
{
- private FtpFileHandler() {}
- FtpFileHandler(FTPEpr epr) throws CourierException
+ private FtpFileHandler()
{
- _epr = epr;
+ }
+ FtpFileHandler(FTPEpr epr) throws CourierException
+ {
+ _epr = epr;
+
URL url = null;
- try { url = _epr.getURL(); }
- catch (MalformedURLException e) { throw new CourierException(e); }
- catch (URISyntaxException e) { throw new CourierException(e); }
+ try
+ {
+ url = _epr.getURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new CourierException(e);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new CourierException(e);
+ }
- _server = url.getHost();
+ _server = url.getHost();
- String[] sa = url.getUserInfo().split(":");
- if (null==sa)
- sa = new String[] {"",""};
- _user = (sa.length<1) ? "" : sa[0];
- _passwd = (sa.length<2) ? "" : sa[1];
+ String[] sa = null;
+
+ if (url.getUserInfo() != null)
+ sa = url.getUserInfo().split(":");
+
+ if (sa == null)
+ sa = new String[]
+ { "", "" };
+ _user = (sa.length < 1) ? "" : sa[0];
+ _passwd = (sa.length < 2) ? "" : sa[1];
- _remoteDir = url.getFile();
+ _remoteDir = url.getFile();
+ if ((_remoteDir == null) || (_remoteDir.equals("")))
+ _remoteDir = ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.FTP_REMOTEDIR, "/tmp");
+
_port = url.getPort();
if (_port < 0)
_port = url.getDefaultPort();
- //TODO resolve this - Best bet would be 'local dir' accessors in FTPEpr
- _localDir = System.getProperty("os.name").toLowerCase().contains("windows")?"/temp":"/tmp";
-// _localDir = _epr.getLocalDir();
+
+ _localDir = ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.FTP_LOCALDIR, "/tmp");
+
+ _isAscii = false;
+ _isPassive = false;
- //TODO setAscii(boolean) getAscii() in FTPEpr() ??
- _isAscii = true;
-// _isAscii = _epr.getAscii();
-
- _isPassive = false;
- try { _isPassive = _epr.getPassive();}
- catch (URISyntaxException e) { _logger.warn(e); }
-
- //TODO Once the RemoteFileSystem has a constructor that takes FTPEpr, we can get rid of this kludge
+ try
+ {
+ _isPassive = _epr.getPassive();
+ }
+ catch (URISyntaxException e)
+ {
+ _logger.warn(e);
+ }
+
+ // TODO Once the RemoteFileSystem has a constructor that takes FTPEpr,
+ // we can get rid of this kludge
configTreeFromEpr();
}
- public boolean deleteFile(File file) throws CourierException
+ public boolean deleteFile(File file) throws CourierException
{
+ // TODO would be better to return false if the file did not exist and leave exceptions
+ // for other error conditions (such as permission denied).
+
try
{
getHandler().deleteRemoteFile(file.getName());
return true;
}
- catch (Exception e) { throw new CourierException(e); }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ throw new CourierException(e);
+ }
}
- public byte[] getFileContents(File file) throws CourierException
+ public byte[] getFileContents(File file) throws CourierException
{
try
{
String name = file.getName();
getHandler().downloadFile(name, name);
- File local = new File(_localDir,name);
+ File local = new File(_localDir, name);
byte[] ba = CourierUtil.bytesFromLocalFile(local);
local.delete();
return ba;
}
- catch (Exception e) { throw new CourierException(e); }
+ catch (Exception e)
+ {
+ // TODO better error handling, e.g., what if someone
+ // tries to download a directory?
+
+ throw new CourierException(e);
+ }
}
- // FileCourier will try to invoke the uploadFile(File) method using reflection
- // FileHandlers that don't implement it (e.g. LocalFileHandler) will not upload
- public void uploadFile(File file) throws CourierException
+ // FileCourier will try to invoke the uploadFile(File) method using
+ // reflection
+ // FileHandlers that don't implement it (e.g. LocalFileHandler) will not
+ // upload
+ public void uploadFile(File file) throws CourierException
{
try
{
@@ -89,77 +153,113 @@
getHandler().uploadFile(file, name);
file.delete();
}
- catch (Exception e) { throw new CourierException(e); }
+ catch (Exception e)
+ {
+ throw new CourierException(e);
+ }
}
- public File[] getFileList() throws CourierException
+ public File[] getFileList() throws CourierException
{
String[] names = null;
-
- try { names = getHandler().getFileListFromRemoteDir(_epr.getInputSuffix()); }
- catch (Exception e) { throw new CourierException(e); }
-
- if (null==names)
+
+ try
+ {
+ names = getHandler()
+ .getFileListFromRemoteDir(_epr.getInputSuffix());
+ }
+ catch (Exception e)
+ {
+ throw new CourierException(e);
+ }
+
+ if (null == names)
return null;
File[] files = new File[names.length];
int i = 0;
for (String file : names)
- if (null!=file)
+ if (null != file)
files[i++] = new File(file);
return files;
}
- public boolean renameFile(File from, File to) throws CourierException
+ public boolean renameFile(File from, File to) throws CourierException
{
- try { getHandler().remoteRename(from, to); }
- catch (Exception e) {throw new CourierException(e); }
+ try
+ {
+ getHandler().remoteRename(from, to);
+ }
+ catch (Exception e)
+ {
+ throw new CourierException(e);
+ }
return true;
}
- // Because ftp connections are volatile, we are always getting a fresh handle
- //TODO there's room for optimization here - not for GA though
- //TODO check with Bruno - why is the getInstance() not needed ? is it OK ?
+ // Because ftp connections are volatile, we are always getting a fresh
+ // handle
+ // TODO there's room for optimization here - not for GA though
+ // TODO check with Bruno - why is the getInstance() not needed ? is it OK ?
protected RemoteFileSystem getHandler() throws CourierException
{
- try
- {
- RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(_tree,true);
+ try
+ {
+ RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(
+ _tree, true);
try
{
rfs.setRemoteDir(_remoteDir);
}
- catch (Exception e) { throw new CourierException(e); }
-
+ catch (Exception e)
+ {
+ throw new CourierException(e);
+ }
+
return rfs;
}
- catch (RemoteFileSystemException e) {throw new CourierException(e); }
+ catch (RemoteFileSystemException e)
+ {
+ throw new CourierException(e);
+ }
}
-
- // this method is only needed until there's an appropriate constructor that takes an EPR
+
+ // this method is only needed until there's an appropriate constructor that
+ // takes an EPR
// see TODO in constructor
private void configTreeFromEpr() throws CourierException
{
try
{
_tree = new ConfigTree("mockFromEPR");
- _tree.setAttribute(RemoteFileSystem.PARMS_FTP_SERVER ,_server);
- _tree.setAttribute(RemoteFileSystem.PARMS_USER ,_user);
- _tree.setAttribute(RemoteFileSystem.PARMS_PASSWD ,_passwd);
- _tree.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR ,_remoteDir);
- _tree.setAttribute(RemoteFileSystem.PARMS_PORT ,Integer.toString(_port));
- _tree.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR ,_localDir);
- _tree.setAttribute(RemoteFileSystem.PARMS_ASCII ,Boolean.toString(_isAscii));
- _tree.setAttribute(RemoteFileSystem.PARMS_PASSIVE ,Boolean.toString(_isPassive));
+ _tree.setAttribute(RemoteFileSystem.PARMS_FTP_SERVER, _server);
+ _tree.setAttribute(RemoteFileSystem.PARMS_USER, _user);
+ _tree.setAttribute(RemoteFileSystem.PARMS_PASSWD, _passwd);
+ _tree.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR, _remoteDir);
+ _tree.setAttribute(RemoteFileSystem.PARMS_PORT, Integer
+ .toString(_port));
+ _tree.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, _localDir);
+ _tree.setAttribute(RemoteFileSystem.PARMS_ASCII, Boolean
+ .toString(_isAscii));
+ _tree.setAttribute(RemoteFileSystem.PARMS_PASSIVE, Boolean
+ .toString(_isPassive));
}
- catch (Exception e) { throw new CourierException(e); }
+ catch (Exception e)
+ {
+ throw new CourierException(e);
+ }
}
- private static final Logger _logger = Logger.getLogger(FtpFileHandler.class);
+ private static final Logger _logger = Logger
+ .getLogger(FtpFileHandler.class);
- protected FTPEpr _epr;
+ protected FTPEpr _epr;
protected ConfigTree _tree;
+ protected String _server;
+ protected String _user;
+ protected String _passwd;
+ protected String _remoteDir;
+ protected String _localDir;
+ protected int _port;
+ protected boolean _isAscii, _isPassive;
- protected String _server ,_user ,_passwd ,_remoteDir ,_localDir;
- protected int _port;
- protected boolean _isAscii ,_isPassive;
}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -13,7 +13,7 @@
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.util.Util;
-public class LocalFileHandler implements FileHandlerInterface
+public class LocalFileHandler implements FileHandler
{
private LocalFileHandler() {}
LocalFileHandler(FileEpr epr) {_epr = epr; }
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-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -22,6 +22,7 @@
package org.jboss.internal.soa.esb.util;
import java.io.File;
+import java.net.UnknownHostException;
import java.util.List;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -45,10 +46,12 @@
* </p>
*/
-public class EdtFtpImpl implements RemoteFileSystem {
+public class EdtFtpImpl implements RemoteFileSystem
+{
private static final String TMP_SUFFIX = ".rosettaPart";
- public enum XFER_TYPE {
+ public enum XFER_TYPE
+ {
ascii, binary
};
@@ -67,7 +70,8 @@
*
* @see org.jboss.soa.esb.util.RemoteFileSystem#getRemoteDir()
*/
- public String getRemoteDir() {
+ public String getRemoteDir()
+ {
return m_sRemoteDir;
}
@@ -93,27 +97,41 @@
* 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(List<KeyValuePair> attribs, boolean connect)
- throws Exception {
+ throws Exception
+ {
m_oParms = new ConfigTree("fromProps");
for (KeyValuePair oCurr : attribs)
m_oParms.setAttribute(oCurr.getKey(), oCurr.getValue());
initialize(connect);
}
-
- private void initialize(boolean bConnect) throws Exception {
+
+ private void initialize(boolean bConnect) throws Exception
+ {
checkParms();
- if (bConnect) {
- m_oConn.setRemoteHost(m_sFtpServer);
+ if (bConnect)
+ {
+ try
+ {
+ m_oConn.setRemoteHost(m_sFtpServer);
+ }
+ catch (UnknownHostException ex)
+ {
+ ex.printStackTrace();
+
+ throw ex;
+ }
m_oConn.setRemotePort(m_iPort);
m_oConn.connect();
for (int i1 = 0; i1 < 10 && !m_oConn.connected(); i1++)
- Thread.sleep(200);
+ Thread.sleep(200); // TODO arbitrary MAGIC number!
+ // Configurable?
if (!m_oConn.connected())
throw new Exception("Can't connect to FTP server");
m_oConn.user(m_sUser);
@@ -122,57 +140,69 @@
: FTPConnectMode.ACTIVE);
}
}
-
+
/*
* (non-Javadoc)
*
* @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 {
+ 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(fileToFtpString(p_oFile));
}
-
+
/*
* (non-Javadoc)
*
* @see org.jboss.soa.esb.util.RemoteFileSystem#getFileListFromRemoteDir(java.lang.String)
*/
- public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception {
+ 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#setRemoteDir(java.lang.String)
*/
- public void setRemoteDir(String p_sDir) throws Exception {
+ public void setRemoteDir(String p_sDir) throws Exception
+ {
+ // TODO deal with null string
+
m_oConn.chdir(p_sDir);
}
-
+
/*
* (non-Javadoc)
*
@@ -180,52 +210,61 @@
* 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()
+ ">";
throw new Exception(sMess);
}
}
-
+
/*
* (non-Javadoc)
*
* @see org.jboss.soa.esb.util.RemoteFileSystem#remoteRename(java.io.File,
* java.io.File)
*/
- public void remoteRename(File p_oFrom, File p_oTo) throws Exception {
- try {
+ public void remoteRename(File p_oFrom, File p_oTo) throws Exception
+ {
+ try
+ {
m_oConn.rename(fileToFtpString(p_oFrom), fileToFtpString(p_oTo));
- } catch (Exception e) {
+ }
+ 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#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(fileToFtpString(p_oFile), sRemoteTmp);
m_oConn.rename(sRemoteTmp, sRemoteOK);
}
-
+
/*
* (non-Javadoc)
*
@@ -233,14 +272,18 @@
* java.lang.String)
*/
public void downloadFile(String p_sFile, String p_sFinalName)
- throws Exception {
+ throws Exception
+ {
File oLocalDir = new File(m_sLocalDir);
File oLclFile = File.createTempFile("Rosetta_", TMP_SUFFIX, oLocalDir);
- try {
+ try
+ {
oLclFile.delete();
- } catch (Exception e) {
}
+ catch (Exception e)
+ {
+ }
m_oConn.setType(m_oXferType);
m_oConn.get(fileToFtpString(oLclFile), p_sFile);
@@ -249,17 +292,19 @@
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) {
+ private void setXferType(XFER_TYPE p_oMode)
+ {
m_oXferType = !XFER_TYPE.ascii.equals(p_oMode) ? FTPTransferType.ASCII
: FTPTransferType.BINARY;
}
-
- private void checkParms() 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");
@@ -295,9 +340,10 @@
return;
}
-
- public static String fileToFtpString(File p_oF) {
+
+ public static String fileToFtpString(File p_oF)
+ {
return (null == p_oF) ? null : p_oF.toString().replace("\\", "/");
}
-
+
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -89,7 +89,7 @@
}
/**
- * Set the username for this FTP EPR.
+ * Set the username for this FTP EPR. In case it cannot be put in the URL.
*
* @param username the user's name.
* @throws URISyntaxException thrown if this EPR is malformed.
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -37,6 +37,9 @@
public static final String SMTP_FROM = "org.jboss.soa.esb.mail.smtp.from";
public static final String SMTP_AUTH = "org.jboss.soa.esb.mail.smtp.auth";
+ public static final String FTP_LOCALDIR = "org.jboss.soa.esb.ftp.localdir";
+ public static final String FTP_REMOTEDIR = "org.jboss.soa.esb.ftp.remotedir";
+
/*
* Code properties
*/
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -25,6 +25,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.net.UnknownHostException;
import org.jboss.internal.soa.esb.util.EdtFtpImpl;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -53,6 +54,10 @@
// return new SecureFtpImpl(p_oP,p_bConnect);
return new EdtFtpImpl(p_oP,p_bConnect);
}
+ catch (UnknownHostException ex)
+ {
+ throw new RemoteFileSystemException(ex);
+ }
catch (URISyntaxException e) {
throw new RemoteFileSystemException(e);
}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FtpFileHandlerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FtpFileHandlerUnitTest.java 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FtpFileHandlerUnitTest.java 2006-12-12 11:32:13 UTC (rev 8249)
@@ -0,0 +1,268 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.internal.soa.esb.couriers.tests;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.PrintStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.UUID;
+
+import junit.framework.Assert;
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.couriers.helpers.FileHandlerFactory;
+import org.jboss.internal.soa.esb.couriers.helpers.FtpFileHandler;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.TwoWayCourier;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests for internal FtpFileHandler class
+ *
+ * @since Version 4.0
+ *
+ */
+public class FtpFileHandlerUnitTest
+{
+ private static Logger _logger = Logger.getLogger(FtpFileHandlerUnitTest.class);
+
+ @BeforeClass
+ public static void setUp() throws Exception
+ {
+ _logger.setLevel(Level.DEBUG);
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception
+ {
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(FtpFileHandlerUnitTest.class);
+ }
+
+ @Test
+ public void testConstructor () throws Exception
+ {
+ FTPEpr ftpEpr = new FTPEpr("ftp://test:password@foo.bar");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+
+ ftpEpr = new FTPEpr("ftp://foo.bar");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void testInvalidConnect () throws Exception
+ {
+ File theFile = new File("test.txt");
+ FTPEpr ftpEpr = new FTPEpr("ftp://test:password@foo.bar");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ byte[] content = handler.getFileContents(theFile);
+ }
+ catch (CourierException ex)
+ {
+ // good!!
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+
+ ftpEpr = new FTPEpr("ftp://anonymous@ftp.ncl.ac.uk:9090");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ byte[] content = handler.getFileContents(theFile);
+ }
+ catch (CourierException ex)
+ {
+ // good!!
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+
+ ftpEpr = new FTPEpr("ftp://anonymous@ftp.ncl.ac.uk");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ byte[] content = handler.getFileContents(theFile);
+ }
+ catch (CourierException ex)
+ {
+ // good!!
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void testValidConnect () throws Exception
+ {
+ File theFile = new File("test1234567890.txt");
+ FTPEpr ftpEpr = new FTPEpr("ftp://anonymous@ftp.ncl.ac.uk/pub");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ File[] files = handler.getFileList();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void testDeleteBadFile () throws Exception
+ {
+ File theFile = new File("test1234567890.txt");
+ FTPEpr ftpEpr = new FTPEpr("ftp://anonymous@ftp.ncl.ac.uk/pub");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ handler.deleteFile(theFile);
+ }
+ catch (CourierException ex)
+ {
+ // TODO should really look for false being returned to indicate no such file!
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void testGetFileList () throws Exception
+ {
+ FTPEpr ftpEpr = new FTPEpr("ftp://anonymous@ftp.ncl.ac.uk/pub");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ File[] files = handler.getFileList();
+
+ System.err.println("Received information on "+files.length+" files");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void testGetFile () throws Exception
+ {
+ FTPEpr ftpEpr = new FTPEpr("ftp://anonymous@ftp.ncl.ac.uk/pub/DNS");
+
+ try
+ {
+ FtpFileHandler handler = (FtpFileHandler) FileHandlerFactory.getInstance().getFileHandler(ftpEpr);
+
+ File[] files = handler.getFileList();
+
+ if (files.length > 0)
+ {
+ System.err.println("Getting file "+files[0]);
+
+ byte[] contents = handler.getFileContents(files[0]);
+
+ String theFile = new String(contents);
+
+ System.err.println("Received:\n"+theFile);
+ }
+ else
+ System.err.println("No files on remote server.");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ Assert.fail();
+ }
+ }
+
+}
Modified: labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2006-12-12 11:27:17 UTC (rev 8248)
+++ labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2006-12-12 11:32:13 UTC (rev 8249)
@@ -50,6 +50,8 @@
<property name="org.jboss.soa.esb.mail.smtp.user" value="jbossesb"/>
<property name="org.jboss.soa.esb.mail.smtp.password" value=""/>
<property name="org.jboss.soa.esb.mail.smtp.port" value="25"/>
+ <property name="org.jboss.soa.esb.ftp.localdir" value="/tmp"/>
+ <property name="org.jboss.soa.esb.ftp.remotedir" value="/tmp"/>
</properties>
<properties name="connection">
<property name="min-pool-size" value="5"/>
More information about the jboss-svn-commits
mailing list