From 6cee30bf78b979c9cabe7dbdc98be6a749519570 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 13 Aug 2008 23:36:41 +0000 Subject: [PATCH] Formatting FtpTarget and removed unused method from ByteArrayMailMessageMapper. --- .../integration/adapter/ftp/FtpTarget.java | 40 ++++++++++--------- .../mail/ByteArrayMailMessageMapper.java | 4 -- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java index fef2f555ed..69d394dd75 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java @@ -22,45 +22,53 @@ import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.net.ftp.FTPClient; + import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageDeliveryException; import org.springframework.integration.message.MessageMapper; import org.springframework.integration.message.MessageTarget; +import org.springframework.util.Assert; /** - * Target adapter for sending files to an ftp server. + * Target adapter for sending files to an FTP server. * * @author Iwein Fuld - * */ public class FtpTarget implements MessageTarget { private final MessageMapper messageMapper; - private FTPClientPool ftpClientPool = new FTPClientPool(); + private volatile FTPClientPool ftpClientPool = new FTPClientPool(); + public FtpTarget(MessageMapper messageMapper) { + Assert.notNull(messageMapper, "MessageMapper must not be null"); this.messageMapper = messageMapper; } + + public void setFtpClientPool(FTPClientPool ftpClientPool) { + Assert.notNull(ftpClientPool, "ftpClientPool must not be null"); + this.ftpClientPool = ftpClientPool; + } + public boolean send(Message message) { -boolean sent = false; - File file = messageMapper.mapMessage(message); - if (file.exists()) { - FTPClient client=null; - FileInputStream fileInputStream = null; + boolean sent = false; + File file = this.messageMapper.mapMessage(message); + if (file != null && file.exists()) { + FTPClient client = null; try { - fileInputStream = new FileInputStream(file); - client = ftpClientPool.getClient(); + FileInputStream fileInputStream = new FileInputStream(file); + client = this.ftpClientPool.getClient(); sent = client.storeFile(file.getName(), fileInputStream); fileInputStream.close(); - } + } catch (FileNotFoundException e) { - throw new MessageDeliveryException(message, "File " + file + " lost from local working directory", e); + throw new MessageDeliveryException(message, "File [" + file + "] lost from local working directory", e); } catch (IOException e) { - throw new MessageDeliveryException(message, "Error transferring " + file - + " from local working directory to remote ftp directory", e); + throw new MessageDeliveryException(message, "Error transferring File [" + file + + "] from local working directory to remote FTP directory", e); } finally { ftpClientPool.releaseClient(client); @@ -69,8 +77,4 @@ boolean sent = false; return sent; } - public void setFtpClientPool(FTPClientPool ftpClientPool) { - this.ftpClientPool = ftpClientPool; - } - } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java index d7a93ce0bb..b7f1369a65 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java @@ -59,10 +59,6 @@ public class ByteArrayMailMessageMapper implements MessageMapper toMessage(MailMessage source) { - throw new UnsupportedOperationException("mapping from MailMessage to byte array not supported"); - } - public MailMessage mapMessage(Message message) { try { MimeMessage mimeMessage = this.mailSender.createMimeMessage();