[jboss-svn-commits] JBL Code SVN: r8759 - 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
Mon Jan 8 07:13:50 EST 2007
Author: mark.little at jboss.com
Date: 2007-01-08 07:13:48 -0500 (Mon, 08 Jan 2007)
New Revision: 8759
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
Log:
Improved error handling.
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 2007-01-08 12:13:19 UTC (rev 8758)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java 2007-01-08 12:13:48 UTC (rev 8759)
@@ -22,6 +22,7 @@
package org.jboss.internal.soa.esb.util;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
@@ -33,6 +34,7 @@
import org.jboss.soa.esb.addressing.eprs.FileEpr;
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;
@@ -113,10 +115,12 @@
try
{
url = m_oEpr.getURL();
- } catch (MalformedURLException e)
+ }
+ catch (MalformedURLException e)
{
throw new RemoteFileSystemException(e);
- } catch (URISyntaxException e)
+ }
+ catch (URISyntaxException e)
{
throw new RemoteFileSystemException(e);
}
@@ -130,7 +134,7 @@
if (sa == null)
sa = new String[]
- { "", "" };
+ { "", "" };
m_sUser = (sa.length < 1) ? "" : sa[0];
m_sPasswd = (sa.length < 2) ? "" : sa[1];
@@ -141,7 +145,7 @@
if ((m_sRemoteDir == null) || (m_sRemoteDir.equals("")))
m_sRemoteDir = ModulePropertyManager.getPropertyManager(
ModulePropertyManager.TRANSPORTS_MODULE).getProperty(
- Environment.FTP_REMOTEDIR, tmpdir);
+ Environment.FTP_REMOTEDIR, tmpdir);
m_iPort = url.getPort();
if (m_iPort < 0)
@@ -149,14 +153,15 @@
m_sLocalDir = ModulePropertyManager.getPropertyManager(
ModulePropertyManager.TRANSPORTS_MODULE).getProperty(
- Environment.FTP_LOCALDIR, tmpdir);
+ Environment.FTP_LOCALDIR, tmpdir);
m_bPassive = false;
try
{
m_bPassive = m_oEpr.getPassive();
- } catch (URISyntaxException e)
+ }
+ catch (URISyntaxException e)
{
_logger.warn(e);
}
@@ -169,7 +174,7 @@
}
public EdtFtpImpl(List<KeyValuePair> p_oAttribs, boolean p_bConnect)
- throws Exception
+ throws Exception
{
m_oParms = new ConfigTree("fromProps");
for (KeyValuePair oCurr : p_oAttribs)
@@ -180,24 +185,23 @@
private void checkParms() throws Exception
{
String att = m_oParms.getAttribute(FileEpr.URL_TAG);
- URL url = (null==att) ? null : new URL(att);
- m_sFtpServer = (null != url) ? url.getHost()
- : m_oParms.getAttribute(PARMS_FTP_SERVER);
+ URL url = (null == att) ? null : new URL(att);
+ m_sFtpServer = (null != url) ? url.getHost() : m_oParms
+ .getAttribute(PARMS_FTP_SERVER);
if (null == m_sFtpServer)
throw new Exception("No FTP server specified");
- String[] sa = (null == url) ? null
- : url.getUserInfo().split(":");
- m_sUser = (null!=sa) ? sa[0] :m_oParms.getAttribute(PARMS_USER);
+ String[] sa = (null == url) ? null : url.getUserInfo().split(":");
+ m_sUser = (null != sa) ? sa[0] : m_oParms.getAttribute(PARMS_USER);
if (null == m_sUser)
throw new Exception("No username specified for FTP");
- m_sPasswd = (null!=sa) ? sa[1] :m_oParms.getAttribute(PARMS_PASSWD);
+ m_sPasswd = (null != sa) ? sa[1] : m_oParms.getAttribute(PARMS_PASSWD);
if (null == m_sPasswd)
throw new Exception("No password specified for FTP");
- m_sRemoteDir = (null != url) ? url.getFile()
- : m_oParms.getAttribute(PARMS_REMOTE_DIR);
+ m_sRemoteDir = (null != url) ? url.getFile() : m_oParms
+ .getAttribute(PARMS_REMOTE_DIR);
if (null == m_sRemoteDir)
m_sRemoteDir = "";
@@ -206,8 +210,8 @@
m_sLocalDir = ".";
String sAux = m_oParms.getAttribute(PARMS_PORT);
- m_iPort = (null != url) ? url.getPort()
- : (null == sAux) ? 21 : Integer.parseInt(sAux);
+ m_iPort = (null != url) ? url.getPort() : (null == sAux) ? 21 : Integer
+ .parseInt(sAux);
if (m_iPort < 0)
m_iPort = new URL("ftp://").getDefaultPort();
@@ -234,12 +238,14 @@
m_sRemoteDir);
m_oParms.setAttribute(RemoteFileSystem.PARMS_PORT, Integer
.toString(m_iPort));
- m_oParms.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, m_sLocalDir);
+ m_oParms
+ .setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, m_sLocalDir);
m_oParms.setAttribute(RemoteFileSystem.PARMS_ASCII, Boolean
.toString(false));
m_oParms.setAttribute(RemoteFileSystem.PARMS_PASSIVE, Boolean
.toString(m_bPassive));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RemoteFileSystemException(e);
}
@@ -259,7 +265,7 @@
catch (Exception ex)
{
// TODO better error handling
-
+
/*
* It seems as though we have a race condition whereby one thread
* tries to remove a file when another renames it!
@@ -274,7 +280,7 @@
* 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);
@@ -282,10 +288,11 @@
try
{
oLclFile.delete();
- } catch (Exception e)
+ }
+ catch (Exception e)
{
}
-
+
m_oConn.get(FtpUtils.fileToFtpString(oLclFile), p_sFile);
File oNew = new File(oLocalDir, p_sFinalName);
@@ -302,14 +309,18 @@
public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception
{
String sSuffix = (null == p_sSuffix) ? "*" : "*" + p_sSuffix;
+
try
{
return m_oConn.dir(sSuffix);
}
- catch (Exception ex)
- {
+ catch (FTPException ex)
+ {
+ if (ex.getReplyCode() == 550) // means File Not Found
+ return null;
+
String msg = ex.getMessage();
-
+
if(msg.equals("NLST command failed")) // despite correct permission this may happen in some FTP servers
{
_logger.debug("No matching file or directory. Server returns the following message: "+ msg);
@@ -323,9 +334,7 @@
+ " can't list "+ sSuffix + " due to: " + msg;
throw new Exception(sMess);
}
-
}
-
}
/*
@@ -346,13 +355,15 @@
try
{
m_oConn.setRemoteHost(m_sFtpServer);
- } catch (UnknownHostException ex)
+ }
+ catch (UnknownHostException ex)
{
-// ex.printStackTrace();
+ // 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); // TODO arbitrary MAGIC number!
@@ -375,11 +386,14 @@
public void quit()
{
if (null != m_oConn)
+ {
try
- {
+ {
m_oConn.quit();
- } catch (Exception e)
- {
+ }
+ catch (Exception e)
+ {
+ }
}
}
@@ -405,11 +419,29 @@
{
m_oConn.rename(FtpClientUtil.fileToFtpString(p_oFrom), FtpUtils
.fileToFtpString(p_oTo));
- } catch (Exception e)
+ }
+ catch (FTPException ex)
{
+ if (ex.getReplyCode() == 550) // EdtFtp error code meaning File Not Found
+ {
+ _logger.debug("EdtFtpImpl tried to rename file that had moved.");
+
+ throw new IOException("File not found.");
+ }
+ else
+ {
+ ex.printStackTrace();
+
+ throw ex;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
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);
}
}
@@ -421,7 +453,7 @@
* 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();
@@ -430,11 +462,12 @@
{
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);
}
}
@@ -461,7 +494,7 @@
{
String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
String sRemoteTmp = sRemoteOK + TMP_SUFFIX;
-
+
m_oConn.put(FtpUtils.fileToFtpString(p_oFile), sRemoteTmp);
m_oConn.rename(sRemoteTmp, sRemoteOK);
}
More information about the jboss-svn-commits
mailing list