[jboss-svn-commits] JBL Code SVN: r8270 - in labs/jbossesb/trunk/product/core/rosetta/src/org/jboss: internal/soa/esb/couriers internal/soa/esb/couriers/helpers soa/esb/couriers
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 12 16:10:47 EST 2006
Author: estebanschifman
Date: 2006-12-12 16:10:41 -0500 (Tue, 12 Dec 2006)
New Revision: 8270
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/FtpFileHandler.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
Log:
FileCourier and FtpFileHandler fixed and now fully tested for FTP
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 19:27:06 UTC (rev 8269)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2006-12-12 21:10:41 UTC (rev 8270)
@@ -35,7 +35,10 @@
import org.jboss.internal.soa.esb.couriers.helpers.FileHandler;
import org.jboss.internal.soa.esb.couriers.helpers.FileHandlerFactory;
import org.jboss.internal.soa.esb.couriers.helpers.LocalFileHandler;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
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.couriers.CourierUtil;
import org.jboss.soa.esb.message.Message;
@@ -159,7 +162,9 @@
{
Method upload = handler.getClass().getMethod("uploadFile",new Class[] {File.class});
- File dir = new File(System.getProperty("io.temp.dir",DEFAULT_TMP));
+ String sDir = ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE)
+ .getProperty(Environment.FTP_LOCALDIR, DEFAULT_TMP);
+ File dir = new File(sDir);
tmpFile = CourierUtil.messageToLocalFile(dir, message);
String name = message.getHeader().getCall().getMessageID().toString();
name += _outputSuffix;
@@ -195,22 +200,25 @@
{
File input = files[0];
File work = workFile(input);
- if (handler.renameFile(input, work))
- try { result = CourierUtil.messageFromLocalFile(work); }
- catch (Exception e)
- {
- if (null==errorFile(input))
- handler.deleteFile(work);
- else
- handler.renameFile(work, errorFile(input));
- continue;
- }
- File done = postFile(input);
- if (null==done)
+ handler.renameFile(input, work);
+ try
+ {
+ result = readOneMessage (handler,work);
+ }
+ catch (Exception e)
+ {
+ if (null==errorFile(input))
handler.deleteFile(work);
else
- handler.renameFile(work, done);
- return result;
+ handler.renameFile(work, errorFile(input));
+ continue;
+ }
+ File done = postFile(input);
+ if (null==done)
+ handler.deleteFile(work);
+ else
+ handler.renameFile(work, done);
+ return result;
}
try { Thread.sleep(200); }
catch (InterruptedException e) { return null;}
@@ -219,6 +227,26 @@
return null;
} //________________________________
+ private Message readOneMessage(FileHandler handler, File work) throws Exception
+ {
+ if (handler instanceof LocalFileHandler)
+ return CourierUtil.messageFromLocalFile(work);
+
+ File tmpFile = null;
+ try
+ {
+ Method download = handler.getClass().getMethod("downloadFile",new Class[] {File.class});
+ tmpFile = (File)download.invoke(handler, new Object[] {work});
+ return CourierUtil.messageFromLocalFile(tmpFile);
+ }
+ catch (Exception e) {throw new CourierException(e);}
+ finally
+ {
+ if (null!=tmpFile)
+ tmpFile.delete();
+ }
+ } //________________________________
+
protected File workFile(File input)
{
String sfx = null;
@@ -260,7 +288,7 @@
{
try
{
- if (_epr.getPostDelete())
+ if (_epr instanceof FTPEpr || _epr.getPostDelete())
return null;
}
catch (Exception e) { _logger.warn("Problems in FileEpr",e); }
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 19:27:06 UTC (rev 8269)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/FtpFileHandler.java 2006-12-12 21:10:41 UTC (rev 8270)
@@ -144,8 +144,6 @@
// 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
@@ -160,6 +158,22 @@
}
}
+ // FileCourier will try to invoke the downloadFile(File) method using
+ // reflection
+ public File downloadFile(File file) throws CourierException
+ {
+ try
+ {
+ String name = file.getName();
+ getHandler().downloadFile(name, name);
+ return new File(_localDir,name);
+ }
+ catch (Exception e)
+ {
+ throw new CourierException(e);
+ }
+ }
+
public File[] getFileList() throws CourierException
{
String[] names = null;
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2006-12-12 19:27:06 UTC (rev 8269)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2006-12-12 21:10:41 UTC (rev 8270)
@@ -31,6 +31,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@@ -142,6 +143,17 @@
{
reader = new FileInputStream(from);
serial = (Serializable)new ObjectInputStream(reader).readObject();
+ Message msg = Util.deserialize(serial);
+ URI msgId = msg.getHeader().getCall().getMessageID();
+ if (null==msgId || Util.isNullString(msgId.toString()))
+ {
+ // TODO this should not happen - Serialization/Deserialization perhaps ??
+ String sId = from.getName();
+ int iDot = sId.indexOf(".");
+ URI fileUri = new URI((iDot<0)?sId:sId.substring(0,iDot));
+ msg.getHeader().getCall().setMessageID(fileUri);
+ }
+ return msg;
}
catch (Exception e) { throw new CourierException(e); }
finally
@@ -149,7 +161,6 @@
if (null!=reader)
reader.close();
}
- return Util.deserialize(serial);
}
public static byte[] bytesFromLocalFile(File from)
More information about the jboss-svn-commits
mailing list