[jboss-svn-commits] JBL Code SVN: r8942 - in labs/jbossesb/trunk/product/core/rosetta: src/org/jboss/soa/esb/util and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jan 20 12:57:32 EST 2007


Author: mark.little at jboss.com
Date: 2007-01-20 12:57:31 -0500 (Sat, 20 Jan 2007)
New Revision: 8942

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java
Log:
Method signature changes for finer granularity exceptions.

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java	2007-01-20 17:27:32 UTC (rev 8941)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java	2007-01-20 17:57:31 UTC (rev 8942)
@@ -24,40 +24,46 @@
 
 import java.io.Serializable;
 
+import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.notification.NotificationException;
 
 /**
- * Use this interface to group all methods that can be useful to
- * trigger events that can be caught by listeners, within or outside of
- * the Rosetta framework
+ * Use this interface to group all methods that can be useful to trigger events
+ * that can be caught by listeners, within or outside of the Rosetta framework
  * 
  * @author Esteban
- *
+ * 
  */
-public interface NotificationManager {
-	
+public interface NotificationManager
+{
+
 	// REVIEW: Add some Javadoc for this interface!!!
-/**
- * public void sendNotifications(ConfigTree p_oP, Serializable p_o)
- * 
- * @param p_oP ConfigTree - A serialized NotificationList object (as a ConfigTree)
- * @param p_o  The Serializable object that will be sent to all the
- * NotificationTarget objects contained in the NotificationList
- * 
- *  <p/>Implementations of this interface will be responsible of sending
- *  the Serializable (arg 1) to destinations determined by each
- *  NotificationTarget contained in the NotificationList represented by
- *  arg 0.
- *  <p/>Please see org.jboss.soa.esb.notification package for existing 
- *  classes that extend NotificationTarget (Files, Queues, Topics, SqlTable...)
- *  
- *  <p/> Invoking processes are responsible to provide dynamic content 
- *  of notification
- *  <p/> The NotificationTarget objects can define 'static' content for
- *  (suc as contents of certain columns in SQL, or message properties for
- *  JMS notification targets, etc. 
- */	
-	public void sendNotifications(ConfigTree p_oP, Serializable p_o) throws Exception;
+	/**
+	 * public void sendNotifications(ConfigTree p_oP, Serializable p_o)
+	 * 
+	 * @param p_oP
+	 *            ConfigTree - A serialized NotificationList object (as a
+	 *            ConfigTree)
+	 * @param p_o
+	 *            The Serializable object that will be sent to all the
+	 *            NotificationTarget objects contained in the NotificationList
+	 * 
+	 * <p/>Implementations of this interface will be responsible of sending the
+	 * Serializable (arg 1) to destinations determined by each
+	 * NotificationTarget contained in the NotificationList represented by arg
+	 * 0. <p/>Please see org.jboss.soa.esb.notification package for existing
+	 * classes that extend NotificationTarget (Files, Queues, Topics,
+	 * SqlTable...)
+	 * 
+	 * <p/> Invoking processes are responsible to provide dynamic content of
+	 * notification <p/> The NotificationTarget objects can define 'static'
+	 * content for (suc as contents of certain columns in SQL, or message
+	 * properties for JMS notification targets, etc.
+	 */
+	public void sendNotifications (ConfigTree p_oP, Serializable p_o)
+			throws ConfigurationException, NotificationException;
 
-	public void sendNotifications(Serializable p_o) throws Exception;
+	public void sendNotifications (Serializable p_o)
+			throws NotificationException;
 } // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java	2007-01-20 17:27:32 UTC (rev 8941)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java	2007-01-20 17:57:31 UTC (rev 8942)
@@ -1,297 +1,469 @@
 /*
-* 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.
-*/
+ * 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.soa.esb.util;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
+import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 
 import com.enterprisedt.net.ftp.FTPClient;
 import com.enterprisedt.net.ftp.FTPConnectMode;
+import com.enterprisedt.net.ftp.FTPException;
 import com.enterprisedt.net.ftp.FTPTransferType;
 
 /**
  * Simplified FTP transfers
- * <p>Description:  Implements a simple set of FTP functionality
- * Parameters to establish the FTP connection are provided at construction time
- * and cannot change during the lifetime of the object
- * <br/>Hides low level details.  Current implementation is based on the
- * "Entreprise Distributed Technology edtFTPj" library
- * but this can be changed with no impact to existing code, just by changing
- * this class without modifying the signature of it's public methods
+ * <p>
+ * Description: Implements a simple set of FTP functionality Parameters to
+ * establish the FTP connection are provided at construction time and cannot
+ * change during the lifetime of the object <br/>Hides low level details.
+ * Current implementation is based on the "Entreprise Distributed Technology
+ * edtFTPj" library but this can be changed with no impact to existing code,
+ * just by changing this class without modifying the signature of it's public
+ * methods
  * </p>
  */
 
 public class FtpClientUtil
 {
-  public  static final String PARMS_FTP_SERVER = "ftpServer";
-  public  static final String PARMS_USER    = "ftpUser";
-  public  static final String PARMS_PASSWD  = "ftpPassword";
-  public  static final String PARMS_PORT    = "ftpPort";
-  public  static final String PARMS_REMOTE_DIR = "ftpRemoteDir";
-  public  static final String PARMS_LOCAL_DIR  = "ftpLocalDir";
-  public  static final String PARMS_ASCII      = "ftpAscii";
-  public  static final String PARMS_PASSIVE    = "ftpPassive";
+	public static final String PARMS_FTP_SERVER = "ftpServer";
 
-  private static final String TMP_SUFFIX	= ".rosettaPart";
+	public static final String PARMS_USER = "ftpUser";
 
-  public enum XFER_TYPE
-  {ascii
-  ,binary
-  };
+	public static final String PARMS_PASSWD = "ftpPassword";
 
-  private ConfigTree	m_oParms;
-  private String    	m_sFtpServer  ,m_sUser        ,m_sPasswd;
-  private String    	m_sRemoteDir  ,m_sLocalDir;
-  private int			m_iPort;
-  private boolean		m_bPassive;
-  public  String getRemoteDir()  { return m_sRemoteDir; }
+	public static final String PARMS_PORT = "ftpPort";
 
-  private FTPClient  	m_oConn = new FTPClient();
-  private FTPTransferType m_oXferType = FTPTransferType.BINARY;
+	public static final String PARMS_REMOTE_DIR = "ftpRemoteDir";
 
-  /**
-   * Checks validity and completeness of parameters, and keeps the info internally
-   * for subsequent FTP requests
-   * @param p_oP ConfigTree
-   * @throws Exception : if parameters are invalid or incomplete
-   * <li>Parameters: (XML attributes at the root level) </li>
-   * <li> ftpServer = name or IP of FTP server </li>
-   * <li> ftpUser = login ID for server </li>
-   * <li> ftpPassword </li>
-   * <li> localDirURI = absolute path in the local filesystem </li>
-   * <li> remoteDirURI = remote path is relative to ftp user home in remote
-   * computer </li>
-   */
+	public static final String PARMS_LOCAL_DIR = "ftpLocalDir";
 
-  public FtpClientUtil (ConfigTree p_oP, boolean p_bConnect) throws Exception
-   { m_oParms = p_oP;
-   	 initialize(p_bConnect);
-   } //_________________________________
+	public static final String PARMS_ASCII = "ftpAscii";
 
-  public FtpClientUtil (List<KeyValuePair> attribs, boolean connect) throws Exception
-  {
-	  m_oParms = new ConfigTree("fromProps");
-	  for (KeyValuePair oCurr : attribs)
-		m_oParms.setAttribute(oCurr.getKey(),oCurr.getValue());
-	  initialize(connect);
-  } //__________________________________
+	public static final String PARMS_PASSIVE = "ftpPassive";
 
-  private void initialize(boolean bConnect) throws Exception
-  {
-	     checkParms();
-	     if (bConnect)
-	     {
-		     m_oConn.setRemoteHost	(m_sFtpServer);
-		     m_oConn.setRemotePort(m_iPort);
-		     m_oConn.connect();
-		     for (int i1=0; i1<10 && ! m_oConn.connected(); i1++)
-		    	 Thread.sleep(200);
-		     if (! m_oConn.connected())
-		    	 throw new Exception("Can't connect to FTP server");
-		     m_oConn.user	      	(m_sUser);
-		     m_oConn.password		(m_sPasswd);
-		     m_oConn.setConnectMode	((m_bPassive) ? FTPConnectMode.PASV : FTPConnectMode.ACTIVE);
-	     }
-  } //__________________________________
-   /**
-    * Terminates ftp session and frees resources
-    * <li>Well behaved programs should make sure to call this method </li>
-    */
-   public void quit ()
-   { if (null != m_oConn)
-      try { m_oConn.quit(); }
-      catch (Exception e) {}
-   } //_________________________________
+	private static final String TMP_SUFFIX = ".rosettaPart";
 
-   /**
-    * Deletes specified file in remote directory
-    * @param p_sFile String : filename to delete.  Method will attempt to delete
-    * file with rightmost node of argument within remote directory specified in 'remoteDirURI'
-    * @throws Exception : if ftp connection cannot be established, or file
-    * cannot be deleted in remote directory
-    */
-   public void deleteRemoteFile (String p_sFile) throws Exception
-   { m_oConn.delete(getRemoteDir()+"/"+new File(p_sFile).getName());
-   } //_________________________________
+	public enum XFER_TYPE
+	{
+		ascii, binary
+	};
 
-   public void remoteDelete (File p_oFile) throws Exception
-   { m_oConn.delete(fileToFtpString(p_oFile));
-   } //_________________________________
+	private ConfigTree m_oParms;
 
-   /**
-    * Gets the list of files in the remote directory that end with arg0
-    * @param p_sSuffix String : retrieve only files that end with that suffix - all files if null
-    * @throws Exception : if ftp connection cannot be established, or problems encountered
-    */
-   public String[] getFileListFromRemoteDir (String p_sSuffix) throws Exception
-   {
-	   String sSuffix = (null==p_sSuffix)?"*":"*"+p_sSuffix;
-	   return m_oConn.dir(sSuffix);
-   } //_________________________________
+	private String m_sFtpServer, m_sUser, m_sPasswd;
 
-   /**
-    * Change remote directory
-    * @param p_sDir String : directory to set
-    * @throws Exception : if ftp connection cannot be established, or problems encountered
-    */
-   public void setRemoteDir (String p_sDir) throws Exception
-   {
-	   m_oConn.chdir(p_sDir);
-   } //_________________________________
+	private String m_sRemoteDir, m_sLocalDir;
 
-   /**
-    * Renames specified file in remote directory to specified new name
-    * @param p_sFrom String : filename to rename
-    * @param p_sTo String : new filename
-    * @throws Exception : if ftp connection cannot be established, or file
-    * cannot be renamed to new name in remote directory
-    * <li>Method will attempt to rename file with rightmost node of argument
-    * within remote directory specified in 'remoteDirURI', to new name inside
-    * the SAME remote directory
-    */
-   public void renameInRemoteDir (String p_sFrom, String p_sTo) throws Exception
-   {
-	 String sRmtFrom = new File(p_sFrom).getName();
-     String sRmtTo   = new File(p_sTo).getName();
+	private int m_iPort;
 
-     try { m_oConn.rename   (getRemoteDir()+"/"+sRmtFrom,getRemoteDir()+"/"+sRmtTo); }
-     catch (Exception e)
-     {	String sMess = this.getClass().getSimpleName()
-    	 +" can't rename in remote directory <"
-    	 +e.getMessage()+">"
-    	 ;
-    	 throw new Exception(sMess);
-     }
-   } //_________________________________
+	private boolean m_bPassive;
 
-   public void remoteRename(File p_oFrom, File p_oTo) throws Exception
-   {
-     try { m_oConn.rename   (fileToFtpString(p_oFrom),fileToFtpString(p_oTo)); }
-     catch (Exception e)
-     {	String sMess = this.getClass().getSimpleName()
-    	 +" can't rename in remote directory <"
-    	 +e.getMessage()+">"
-    	 ;
-    	 throw new Exception(sMess);
-     }
-   } //_________________________________
+	public String getRemoteDir ()
+	{
+		return m_sRemoteDir;
+	}
 
-   /**
-    * Uploads specified file from local directory (localDirURI) to remote
-    * directory (remoteDirURI)
-    * @param p_sFile String : filename to upload
-    * @throws Exception : if ftp connection cannot be established, or file
-    * cannot be uploaded
-    * <li> local file will be renamed during transfer ('.xferNotReady' appended
-    * to name)</li>
-    * <li> upon successful completion. the suffix '.xferDone' will be appended
-    * to the original filename </li>
-    */
-   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);
-   } //_________________________________
+	private FTPClient m_oConn = new FTPClient();
 
-   /**
-    * Downloads specified file from remote directory (remoteDirURI) to local
-    * directory (localDirURI)
-    * @param p_sFile String : filename to download
-    * @throws Exception : if ftp connection cannot be established, or file
-    * cannot be downloaded
-    * <li> local file is assigned a temporary name during transfer  </li>
-    * <li> upon successful completion, local temporary file will be renamed to
-    * name specified in argument, and suffix '.xferDone' will be appended
-    * to the original filename in the remote directory </li>
-    */
-   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);
+	private FTPTransferType m_oXferType = FTPTransferType.BINARY;
 
-     try { oLclFile.delete(); }
-     catch (Exception e) {}
-     m_oConn.setType(m_oXferType);
-     m_oConn.get(fileToFtpString(oLclFile),p_sFile);
+	/**
+	 * Checks validity and completeness of parameters, and keeps the info
+	 * internally for subsequent FTP requests
+	 * 
+	 * @param p_oP
+	 *            ConfigTree
+	 * @throws ConfigurationException :
+	 *             if parameters are invalid or incomplete
+	 *             <li>Parameters: (XML attributes at the root level) </li>
+	 *             <li> ftpServer = name or IP of FTP server </li>
+	 *             <li> ftpUser = login ID for server </li>
+	 *             <li> ftpPassword </li>
+	 *             <li> localDirURI = absolute path in the local filesystem
+	 *             </li>
+	 *             <li> remoteDirURI = remote path is relative to ftp user home
+	 *             in remote computer </li>
+	 * @throws RemoteFileSystemException
+	 */
 
-     File oNew = new File(oLocalDir,p_sFinalName);
-     if (oNew.exists()) oNew.delete();
-     oLclFile.renameTo(oNew);
-   } //_________________________________
+	public FtpClientUtil (ConfigTree p_oP, boolean p_bConnect) throws RemoteFileSystemException, ConfigurationException
+	{
+		m_oParms = p_oP;
+		initialize(p_bConnect);
+	} // _________________________________
 
-   // 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;
-   } //_________________________________
+	public FtpClientUtil (List<KeyValuePair> attribs, boolean connect)
+			throws RemoteFileSystemException, ConfigurationException
+	{
+		m_oParms = new ConfigTree("fromProps");
+		for (KeyValuePair oCurr : attribs)
+			m_oParms.setAttribute(oCurr.getKey(), oCurr.getValue());
+		initialize(connect);
+	} // __________________________________
 
-   private void checkParms() throws Exception
-   {
-     m_sFtpServer  = m_oParms.getAttribute(PARMS_FTP_SERVER);
-     if (null==m_sFtpServer) throw new Exception ("No FTP server specified");
+	private void initialize (boolean bConnect) throws RemoteFileSystemException, ConfigurationException
+	{
+		checkParms();
+		
+		try
+		{
+			if (bConnect)
+			{
+				m_oConn.setRemoteHost(m_sFtpServer);
+				m_oConn.setRemotePort(m_iPort);
+				m_oConn.connect();
+				
+				for (int i1 = 0; i1 < 10 && !m_oConn.connected(); i1++)
+				{
+					try
+					{
+						// TODO magic number
+						Thread.sleep(200);
+					}
+					catch (InterruptedException ex)
+					{
+					}
+				}
+				
+				if (!m_oConn.connected())
+					throw new RemoteFileSystemException("Can't connect to FTP server");
+				m_oConn.user(m_sUser);
+				m_oConn.password(m_sPasswd);
+				m_oConn
+						.setConnectMode((m_bPassive) ? FTPConnectMode.PASV : FTPConnectMode.ACTIVE);
+			}
+		}
+		catch (RemoteFileSystemException ex)
+		{
+			throw ex;
+		}
+		catch (Exception ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // __________________________________
 
-     m_sUser       = m_oParms.getAttribute(PARMS_USER);
-     if (null==m_sUser) throw new Exception ("No username specified for FTP");
+	/**
+	 * Terminates ftp session and frees resources
+	 * <li>Well behaved programs should make sure to call this method </li>
+	 */
+	public void quit ()
+	{
+		if (null != m_oConn) try
+		{
+			m_oConn.quit();
+		}
+		catch (Exception e)
+		{
+		}
+	} // _________________________________
 
-     m_sPasswd     = m_oParms.getAttribute(PARMS_PASSWD);
-     if (null==m_sPasswd) throw new Exception ("No password specified for FTP");
+	/**
+	 * Deletes specified file in remote directory
+	 * 
+	 * @param p_sFile
+	 *            String : filename to delete. Method will attempt to delete
+	 *            file with rightmost node of argument within remote directory
+	 *            specified in 'remoteDirURI'
+	 * @throws RemoteFileSystemException :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             deleted in remote directory
+	 */
+	public void deleteRemoteFile (String p_sFile) throws RemoteFileSystemException
+	{
+		try
+		{
+			m_oConn.delete(getRemoteDir() + "/" + new File(p_sFile).getName());
+		}
+		catch (FTPException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+		catch (IOException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // _________________________________
 
-     m_sRemoteDir  = m_oParms.getAttribute(PARMS_REMOTE_DIR);
-     if (null==m_sRemoteDir)
-    	 m_sRemoteDir = "";
+	public void remoteDelete (File p_oFile) throws RemoteFileSystemException
+	{
+		try
+		{
+			m_oConn.delete(fileToFtpString(p_oFile));
+		}
+		catch (FTPException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+		catch (IOException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // _________________________________
 
-     m_sLocalDir  = m_oParms.getAttribute(PARMS_LOCAL_DIR);
-     if (null==m_sLocalDir)
-    	 m_sLocalDir = ".";
+	/**
+	 * Gets the list of files in the remote directory that end with arg0
+	 * 
+	 * @param p_sSuffix
+	 *            String : retrieve only files that end with that suffix - all
+	 *            files if null
+	 * @throws RemoteFileSystemException :
+	 *             if ftp connection cannot be established, or problems
+	 *             encountered
+	 */
+	public String[] getFileListFromRemoteDir (String p_sSuffix)
+			throws RemoteFileSystemException
+	{
+		String sSuffix = (null == p_sSuffix) ? "*" : "*" + p_sSuffix;
+		
+		try
+		{
+			return m_oConn.dir(sSuffix);
+		}
+		catch (FTPException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+		catch (IOException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // _________________________________
 
-     String sAux	= m_oParms.getAttribute(PARMS_PORT);
-     m_iPort = (null==sAux) ? 21 : Integer.parseInt(sAux);
+	/**
+	 * Change remote directory
+	 * 
+	 * @param p_sDir
+	 *            String : directory to set
+	 * @throws RemoteFileSystemException :
+	 *             if ftp connection cannot be established, or problems
+	 *             encountered
+	 */
+	public void setRemoteDir (String p_sDir) throws RemoteFileSystemException
+	{
+		try
+		{
+			m_oConn.chdir(p_sDir);
+		}
+		catch (FTPException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+		catch (IOException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // _________________________________
 
-     boolean bAscii = false;
-     sAux = m_oParms.getAttribute(PARMS_ASCII);
-     if (null!=sAux)
-    	 bAscii = Boolean.parseBoolean(sAux);
-     setXferType((bAscii)?XFER_TYPE.ascii:XFER_TYPE.binary);
+	/**
+	 * Renames specified file in remote directory to specified new name
+	 * 
+	 * @param p_sFrom
+	 *            String : filename to rename
+	 * @param p_sTo
+	 *            String : new filename
+	 * @throws RemoteFileSystemException :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             renamed to new name in remote directory
+	 *             <li>Method will attempt to rename file with rightmost node
+	 *             of argument within remote directory specified in
+	 *             'remoteDirURI', to new name inside the SAME remote directory
+	 */
+	public void renameInRemoteDir (String p_sFrom, String p_sTo)
+			throws RemoteFileSystemException
+	{
+		String sRmtFrom = new File(p_sFrom).getName();
+		String sRmtTo = new File(p_sTo).getName();
 
-     m_bPassive = false;
-     sAux = m_oParms.getAttribute(PARMS_PASSIVE);
-     m_bPassive = (null!=sAux) && Boolean.parseBoolean(sAux);
+		try
+		{
+			m_oConn.rename(getRemoteDir() + "/" + sRmtFrom,
+					getRemoteDir() + "/" + sRmtTo);
+		}
+		catch (Exception e)
+		{
+			String sMess = this.getClass().getSimpleName() + " can't rename in remote directory <" + e
+					.getMessage() + ">";
+			throw new RemoteFileSystemException(sMess);
+		}
+	} // _________________________________
 
-     return;
-   } //__________________________________
+	public void remoteRename (File p_oFrom, File p_oTo) throws RemoteFileSystemException
+	{
+		try
+		{
+			m_oConn.rename(fileToFtpString(p_oFrom), fileToFtpString(p_oTo));
+		}
+		catch (Exception e)
+		{
+			String sMess = this.getClass().getSimpleName() + " can't rename in remote directory <" + e
+					.getMessage() + ">";
+			throw new RemoteFileSystemException(sMess);
+		}
+	} // _________________________________
 
-   public static String fileToFtpString(File p_oF)
+	/**
+	 * Uploads specified file from local directory (localDirURI) to remote
+	 * directory (remoteDirURI)
+	 * 
+	 * @param p_sFile
+	 *            String : filename to upload
+	 * @throws RemoteFileSystemException :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             uploaded
+	 *             <li> local file will be renamed during transfer
+	 *             ('.xferNotReady' appended to name)</li>
+	 *             <li> upon successful completion. the suffix '.xferDone' will
+	 *             be appended to the original filename </li>
+	 */
+	public void uploadFile (File p_oFile, String p_sRemoteName)
+			throws RemoteFileSystemException
 	{
-		return(null==p_oF) ? null
-			: p_oF.toString().replace("\\","/");
-    } //________________________________
+		String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
+		String sRemoteTmp = sRemoteOK + TMP_SUFFIX;
+		
+		try
+		{
+			m_oConn.setType(m_oXferType);
+			m_oConn.put(fileToFtpString(p_oFile), sRemoteTmp);
+			m_oConn.rename(sRemoteTmp, sRemoteOK);
+		}
+		catch (FTPException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+		catch (IOException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // _________________________________
 
-} //____________________________________________________________________________
+	/**
+	 * Downloads specified file from remote directory (remoteDirURI) to local
+	 * directory (localDirURI)
+	 * 
+	 * @param p_sFile
+	 *            String : filename to download
+	 * @throws RemoteFileSystemException :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             downloaded
+	 *             <li> local file is assigned a temporary name during transfer
+	 *             </li>
+	 *             <li> upon successful completion, local temporary file will be
+	 *             renamed to name specified in argument, and suffix '.xferDone'
+	 *             will be appended to the original filename in the remote
+	 *             directory </li>
+	 */
+	public void downloadFile (String p_sFile, String p_sFinalName)
+			throws RemoteFileSystemException
+	{
+		try
+		{
+			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(fileToFtpString(oLclFile), p_sFile);
+	
+			File oNew = new File(oLocalDir, p_sFinalName);
+			
+			if (oNew.exists()) 
+				oNew.delete();
+			
+			oLclFile.renameTo(oNew);
+		}
+		catch (FTPException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+		catch (IOException ex)
+		{
+			throw new RemoteFileSystemException(ex);
+		}
+	} // _________________________________
+
+	// 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 ConfigurationException
+	{
+		m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
+		if (null == m_sFtpServer)
+			throw new ConfigurationException("No FTP server specified");
+
+		m_sUser = m_oParms.getAttribute(PARMS_USER);
+		if (null == m_sUser)
+			throw new ConfigurationException("No username specified for FTP");
+
+		m_sPasswd = m_oParms.getAttribute(PARMS_PASSWD);
+		if (null == m_sPasswd)
+			throw new ConfigurationException("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);
+	} // __________________________________
+
+	public static String fileToFtpString (File p_oF)
+	{
+		return (null == p_oF) ? null : p_oF.toString().replace("\\", "/");
+	} // ________________________________
+
+} // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java	2007-01-20 17:27:32 UTC (rev 8941)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java	2007-01-20 17:57:31 UTC (rev 8942)
@@ -33,18 +33,21 @@
 
 /**
  * NotifyUtil unit tests.
+ * 
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public class NotifyUtilUnitTest extends TestCase {
+public class NotifyUtilUnitTest extends TestCase
+{
 
-	public void test_NotifyUtil() {
+	public void test_NotifyUtil ()
+	{
 		ConfigTree rootEl = new ConfigTree("rootEl");
-		
+
 		addNotificationConfig(rootEl, "message1", "ok");
 		addNotificationConfig(rootEl, "message2", "err");
 		addNotificationConfig(rootEl, "message3", "ok");
 		addNotificationConfig(rootEl, "message4", "err");
-		
+
 		TestNotificationHandler handler = new TestNotificationHandler();
 		NotifyUtil.notifyOK(handler, rootEl, "somemessage", new HashMap());
 		assertEquals(2, handler.messages.size());
@@ -52,26 +55,34 @@
 		assertEquals("message3 - somemessage", handler.messages.get(1));
 
 		handler.messages.clear();
-		NotifyUtil.notifyError(handler, rootEl, "somemessage", new HashMap(), new Exception("test"));
+		NotifyUtil.notifyError(handler, rootEl, "somemessage", new HashMap(),
+				new Exception("test"));
 		assertEquals(3, handler.messages.size());
 		assertTrue(handler.messages.get(0).startsWith("somemessage"));
 		assertTrue(handler.messages.get(1).startsWith("message2 - somemessage"));
 		assertTrue(handler.messages.get(2).startsWith("message4 - somemessage"));
 	}
-	
-	private void addNotificationConfig(ConfigTree rootEl, String message, String type) {
-		ConfigTree notifEl = new ConfigTree(NotificationList.ELEMENT,rootEl);
+
+	private void addNotificationConfig (ConfigTree rootEl, String message,
+			String type)
+	{
+		ConfigTree notifEl = new ConfigTree(NotificationList.ELEMENT, rootEl);
 		notifEl.setAttribute("message", message);
 		notifEl.setAttribute(NotificationList.TYPE, type);
 	}
 
-	private class TestNotificationHandler implements NotificationManager {
+	private class TestNotificationHandler implements NotificationManager
+	{
 		private List<String> messages = new ArrayList<String>();
-		
-		public void sendNotifications(ConfigTree p_oP, Serializable p_o) throws Exception {
+
+		public void sendNotifications (ConfigTree p_oP, Serializable p_o)
+				throws NotificationException
+		{
 			messages.add(p_oP.getAttribute("message") + " - " + p_o);
 		}
-		public void sendNotifications(Serializable p_o) throws Exception {
+
+		public void sendNotifications (Serializable p_o) throws NotificationException
+		{
 			messages.add(p_o.toString());
 		}
 	}




More information about the jboss-svn-commits mailing list