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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jan 17 11:01:40 EST 2007


Author: kurt.stam at jboss.com
Date: 2007-01-17 11:01:40 -0500 (Wed, 17 Jan 2007)
New Revision: 8884

Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
Log:
don't use depricated methods.

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java	2007-01-17 15:23:50 UTC (rev 8883)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java	2007-01-17 16:01:40 UTC (rev 8884)
@@ -24,17 +24,18 @@
 
 import java.io.File;
 
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ListenerUtil;
 import org.jboss.soa.esb.util.FtpClientUtil;
 import org.jboss.soa.esb.util.RemoteFileSystem;
 import org.jboss.soa.esb.util.RemoteFileSystemFactory;
 
 public class RemoteGatewayListener extends FileGatewayListener
 {
-	protected RemoteGatewayListener()
-	{
-	}
+	protected RemoteGatewayListener(){}
 
 	public RemoteGatewayListener(GatewayListenerController commandListener,
 			ConfigTree config) throws Exception
@@ -53,12 +54,17 @@
 		_config.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, localDir);
 		final String remoteDir = _config.getAttribute(ListenerTagNames.FILE_INPUT_DIR_TAG) ;
 		_config.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR, remoteDir);
-		RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(
-				_config, true);
-		rfs.quit();
+		EPR epr = ListenerUtil.assembleEpr(_config);
+		if (epr instanceof FTPEpr)  {
+			FTPEpr ftpEpr = (FTPEpr) epr;
+			RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
+			rfs.quit();
+		} else {
+			throw new GatewayException("This Gateway only accepts FTP and SFTP.");
+		}
+		
 	}
 
-	@Override
 	protected void seeIfOkToWorkOnDir(File p_oDir) throws GatewayException
 	{
 		// TODO: Implement. Very expensive though.
@@ -70,16 +76,22 @@
 
 	}
 
-	// @Override
 	public boolean deleteFile(File file) throws GatewayException
 	{
 		RemoteFileSystem rfs = null;
 		try
 		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
-			rfs.deleteRemoteFile(file.toString());
-			return true;
+			EPR epr = ListenerUtil.assembleEpr(_config);
+			if (epr instanceof FTPEpr)  {
+				FTPEpr ftpEpr = (FTPEpr) epr;
+				rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
+				rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+				rfs.deleteRemoteFile(file.toString());
+				return true;
+			} else {
+				throw new GatewayException("This Gateway only accepts FTP and SFTP.");
+			}
+			
 		} catch (Exception e)
 		{
 			throw new GatewayException(e);
@@ -90,7 +102,6 @@
 		}
 	}
 
-	// @Override
 	byte[] getFileContents(File file) throws GatewayException
 	{
 		RemoteFileSystem rfs = null;
@@ -98,12 +109,19 @@
 		{
 			File temp = File.createTempFile("FTPdown", ".tmp");
 			temp.delete();
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
-			rfs.downloadFile(file.toString(), temp.getName());
-			final byte[] contents = super.getFileContents(temp);
-			temp.delete() ;
-			return contents ;
+			EPR epr = ListenerUtil.assembleEpr(_config);
+			if (epr instanceof FTPEpr)  {
+				FTPEpr ftpEpr = (FTPEpr) epr;
+				rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
+				rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+				rfs.downloadFile(file.toString(), temp.getName());
+				final byte[] contents = super.getFileContents(temp);
+				temp.delete() ;
+				return contents ;
+			} else {
+				throw new GatewayException("This Gateway only accepts FTP and SFTP.");
+			}
+			
 		} catch (Exception e)
 		{
 			throw new GatewayException(e);
@@ -114,46 +132,52 @@
 		}
 	}
 
-	// @Override
 	File[] getFileList(String suffix) throws GatewayException
 	{
 		RemoteFileSystem rfs = null;
 		try
 		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
-			String[] sa = rfs.getFileListFromRemoteDir(_inputSuffix);
-			File[] oaRet = new File[(null == sa) ? 0 : sa.length];
-			int i1 = 0;
-			if (null != sa)
-				for (String sCurr : sa)
-					oaRet[i1++] = new File(sCurr);
-			return oaRet;
-		} catch (Exception e)
-		{
+			EPR epr = ListenerUtil.assembleEpr(_config);
+			if (epr instanceof FTPEpr)  {
+				FTPEpr ftpEpr = (FTPEpr) epr;
+				rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
+				rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+				String[] sa = rfs.getFileListFromRemoteDir(_inputSuffix);
+				File[] oaRet = new File[(null == sa) ? 0 : sa.length];
+				int i1 = 0;
+				if (null != sa)
+					for (String sCurr : sa)
+						oaRet[i1++] = new File(sCurr);
+				return oaRet;
+			} else {
+				throw new GatewayException("This Gateway only accepts FTP and SFTP.");
+			}
+		} catch (Exception e){
 			throw new GatewayException(e);
-		} finally
-		{
+		} finally {
 			if (null != rfs)
 				rfs.quit();
 		}
 	}
 
-	// @Override
 	boolean renameFile(File from, File to) throws GatewayException
 	{
 		RemoteFileSystem rfs = null;
 		try
 		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
-			rfs.renameInRemoteDir(from.toString(), to.toString());
-			return true;
-		} catch (Exception e)
-		{
+			EPR epr = ListenerUtil.assembleEpr(_config);
+			if (epr instanceof FTPEpr)  {
+				FTPEpr ftpEpr = (FTPEpr) epr;
+				rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
+				rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+				rfs.renameInRemoteDir(from.toString(), to.toString());
+				return true;
+			} else {
+				throw new GatewayException("This Gateway only accepts FTP and SFTP.");
+			}
+		} catch (Exception e) {
 			throw new GatewayException(e);
-		} finally
-		{
+		} finally {
 			if (null != rfs)
 				rfs.quit();
 		}

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	2007-01-17 15:23:50 UTC (rev 8883)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java	2007-01-17 16:01:40 UTC (rev 8884)
@@ -29,9 +29,7 @@
 import org.jboss.internal.soa.esb.util.EdtFtpImpl;
 import org.jboss.internal.soa.esb.util.SecureFtpImpl;
 import org.jboss.soa.esb.addressing.eprs.FTPEpr;
-import org.jboss.soa.esb.addressing.eprs.FileEpr;
 import org.jboss.soa.esb.addressing.eprs.SFTPEpr;
-import org.jboss.soa.esb.helpers.ConfigTree;
 
 public class RemoteFileSystemFactory
 {
@@ -52,7 +50,7 @@
 	 * @return
 	 * @throws RemoteFileSystemException
 	 */
-	public static RemoteFileSystem getRemoteFileSystem(FileEpr p_oEpr,
+	public static RemoteFileSystem getRemoteFileSystem(FTPEpr p_oEpr,
 			boolean p_bConnect) throws RemoteFileSystemException
 	{
 		URL url = null;
@@ -77,34 +75,4 @@
 		throw new RemoteFileSystemException("Unknown or unsupported protocol");
 	}
 
-	/**
-	 * @deprecated
-	 * @param p_oP
-	 * @param p_bConnect
-	 * @return
-	 * @throws RemoteFileSystemException
-	 */
-	public static RemoteFileSystem getRemoteFileSystem(ConfigTree p_oP,
-			boolean p_bConnect) throws RemoteFileSystemException
-	{
-		String att = p_oP.getAttribute(FileEpr.URL_TAG);
-		URL url = null;
-		try { url = (null==att) ? null : new URL(att); }
-		catch (MalformedURLException e) { /*  OK just leave it null */}
-		
-		final String protocol =  (null!=url) ? url.getProtocol()
-			: p_oP.getAttribute(RemoteFileSystem.PARMS_PROTOCOL) ;
-		try
-		{
-			if (RemoteFileSystem.FTP_PROTOCOL.equals(protocol))
-				return new EdtFtpImpl(p_oP, p_bConnect);
-			else if (RemoteFileSystem.SFTP_PROTOCOL.equals(protocol))
-				return new SecureFtpImpl(p_oP, p_bConnect);
-		} 
-		catch (Exception ex)
-		{
-			throw new RemoteFileSystemException(ex);
-		}
-		throw new RemoteFileSystemException("Unknown protocol: " + protocol);
-	}
 }




More information about the jboss-svn-commits mailing list