From commits-return-13570-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Fri May 14 09:22:12 2010 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 94905 invoked from network); 14 May 2010 09:22:11 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 May 2010 09:22:11 -0000 Received: (qmail 54953 invoked by uid 500); 14 May 2010 09:22:11 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 54897 invoked by uid 500); 14 May 2010 09:22:10 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 54890 invoked by uid 99); 14 May 2010 09:22:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 May 2010 09:22:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 May 2010 09:22:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8DE2A23889D7; Fri, 14 May 2010 09:21:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r944167 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/blob/ main/java/org/apache/activemq/command/ test/java/org/apache/activemq/blob/ Date: Fri, 14 May 2010 09:21:43 -0000 To: commits@activemq.apache.org From: dejanb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100514092143.8DE2A23889D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dejanb Date: Fri May 14 09:21:42 2010 New Revision: 944167 URL: http://svn.apache.org/viewvc?rev=944167&view=rev Log: https://issues.apache.org/activemq/browse/AMQ-2713 - delete blob message files from server Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultStrategy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPStrategy.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloadStrategy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloader.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobDownloadStrategy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQBlobMessage.java activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/DefaultBlobUploadStrategyTest.java activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPTestSupport.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloadStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloadStrategy.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloadStrategy.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloadStrategy.java Fri May 14 09:21:42 2010 @@ -27,5 +27,7 @@ import org.apache.activemq.command.Activ public interface BlobDownloadStrategy { InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException; + + void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException; } Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloader.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloader.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloader.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobDownloader.java Fri May 14 09:21:42 2010 @@ -37,6 +37,10 @@ public class BlobDownloader { return getStrategy().getInputStream(message); } + public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException { + getStrategy().deleteFile(message); + } + public BlobTransferPolicy getBlobTransferPolicy() { return blobTransferPolicy; } Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java Fri May 14 09:21:42 2010 @@ -134,10 +134,10 @@ public class BlobTransferPolicy { strategy = new FTPBlobUploadStrategy(this); } else { strategy = new DefaultBlobUploadStrategy(this); - } + } } catch (MalformedURLException e) { strategy = new DefaultBlobUploadStrategy(this); -} + } return strategy; } @@ -153,12 +153,12 @@ public class BlobTransferPolicy { URL url = new URL(getUploadUrl()); if(url.getProtocol().equalsIgnoreCase("FTP")) { - strategy = new FTPBlobDownloadStrategy(); + strategy = new FTPBlobDownloadStrategy(this); } else { - strategy = new DefaultBlobDownloadStrategy(); + strategy = new DefaultBlobDownloadStrategy(this); } } catch (MalformedURLException e) { - strategy = new DefaultBlobDownloadStrategy(); + strategy = new DefaultBlobDownloadStrategy(this); } return strategy; } Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java Fri May 14 09:21:42 2010 @@ -18,6 +18,7 @@ package org.apache.activemq.blob; import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.URL; import javax.jms.JMSException; import org.apache.activemq.command.ActiveMQBlobMessage; @@ -26,7 +27,11 @@ import org.apache.activemq.command.Activ * A default implementation of {@link BlobDownloadStrategy} which uses the URL * class to download files or streams from a remote URL */ -public class DefaultBlobDownloadStrategy implements BlobDownloadStrategy{ +public class DefaultBlobDownloadStrategy extends DefaultStrategy implements BlobDownloadStrategy { + + public DefaultBlobDownloadStrategy(BlobTransferPolicy transferPolicy) { + super(transferPolicy); + } public InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException { URL value = message.getURL(); @@ -36,4 +41,18 @@ public class DefaultBlobDownloadStrategy return value.openStream(); } + public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException { + URL url = createMessageURL(message); + + HttpURLConnection connection = (HttpURLConnection)url.openConnection(); + connection.setRequestMethod("DELETE"); + connection.connect(); + connection.disconnect(); + + if (!isSuccessfulCode(connection.getResponseCode())) { + throw new IOException("DELETE was not successful: " + connection.getResponseCode() + " " + + connection.getResponseMessage()); + } + } + } Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java Fri May 14 09:21:42 2010 @@ -33,11 +33,10 @@ import org.apache.activemq.command.Activ * A default implementation of {@link BlobUploadStrategy} which uses the URL * class to upload files or streams to a remote URL */ -public class DefaultBlobUploadStrategy implements BlobUploadStrategy { - private BlobTransferPolicy transferPolicy; +public class DefaultBlobUploadStrategy extends DefaultStrategy implements BlobUploadStrategy { public DefaultBlobUploadStrategy(BlobTransferPolicy transferPolicy) { - this.transferPolicy = transferPolicy; + super(transferPolicy); } public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException { @@ -45,7 +44,7 @@ public class DefaultBlobUploadStrategy i } public URL uploadStream(ActiveMQBlobMessage message, InputStream fis) throws JMSException, IOException { - URL url = createUploadURL(message); + URL url = createMessageURL(message); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("PUT"); @@ -74,25 +73,5 @@ public class DefaultBlobUploadStrategy i return url; } - public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException { - URL url = createUploadURL(message); - HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - connection.setRequestMethod("DELETE"); - connection.connect(); - connection.disconnect(); - - if (!isSuccessfulCode(connection.getResponseCode())) { - throw new IOException("DELETE was not successful: " + connection.getResponseCode() + " " - + connection.getResponseMessage()); - } - } - - private boolean isSuccessfulCode(int responseCode) { - return responseCode >= 200 && responseCode < 300; // 2xx => successful - } - - protected URL createUploadURL(ActiveMQBlobMessage message) throws JMSException, MalformedURLException { - return new URL(transferPolicy.getUploadUrl() + message.getMessageId().toString()); - } } Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultStrategy.java?rev=944167&view=auto ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultStrategy.java (added) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultStrategy.java Fri May 14 09:21:42 2010 @@ -0,0 +1,26 @@ +package org.apache.activemq.blob; + +import java.net.MalformedURLException; +import java.net.URL; + +import javax.jms.JMSException; + +import org.apache.activemq.command.ActiveMQBlobMessage; + +public class DefaultStrategy { + + protected BlobTransferPolicy transferPolicy; + + public DefaultStrategy(BlobTransferPolicy transferPolicy) { + this.transferPolicy = transferPolicy; + } + + protected boolean isSuccessfulCode(int responseCode) { + return responseCode >= 200 && responseCode < 300; // 2xx => successful + } + + protected URL createMessageURL(ActiveMQBlobMessage message) throws JMSException, MalformedURLException { + return new URL(transferPolicy.getUploadUrl() + message.getMessageId().toString()); + } + +} Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobDownloadStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobDownloadStrategy.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobDownloadStrategy.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobDownloadStrategy.java Fri May 14 09:21:42 2010 @@ -16,11 +16,10 @@ */ package org.apache.activemq.blob; +import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.FilterInputStream; -import java.net.ConnectException; -import java.net.URL; +import java.net.MalformedURLException; import javax.jms.JMSException; @@ -30,33 +29,18 @@ import org.apache.commons.net.ftp.FTPCli /** * A FTP implementation for {@link BlobDownloadStrategy}. */ -public class FTPBlobDownloadStrategy implements BlobDownloadStrategy { - private String ftpUser; - private String ftpPass; - - public InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException { - URL url = message.getURL(); - - setUserInformation(url.getUserInfo()); - String connectUrl = url.getHost(); - int port = url.getPort() < 1 ? 21 : url.getPort(); +public class FTPBlobDownloadStrategy extends FTPStrategy implements BlobDownloadStrategy { - final FTPClient ftp = new FTPClient(); - try { - ftp.connect(connectUrl, port); - } catch(ConnectException e) { - throw new JMSException("Problem connecting the FTP-server"); - } + public FTPBlobDownloadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException { + super(transferPolicy); + } - if(!ftp.login(ftpUser, ftpPass)) { - ftp.quit(); - ftp.disconnect(); - throw new JMSException("Cant Authentificate to FTP-Server"); - } + public InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException { + url = message.getURL(); + final FTPClient ftp = createFTP(); String path = url.getPath(); String workingDir = path.substring(0, path.lastIndexOf("/")); - String file = path.substring(path.lastIndexOf("/")+1); - + String file = path.substring(path.lastIndexOf("/") + 1); ftp.changeWorkingDirectory(workingDir); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); @@ -72,15 +56,20 @@ public class FTPBlobDownloadStrategy imp return input; } - private void setUserInformation(String userInfo) { - if(userInfo != null) { - String[] userPass = userInfo.split(":"); - if(userPass.length > 0) this.ftpUser = userPass[0]; - if(userPass.length > 1) this.ftpPass = userPass[1]; - } else { - this.ftpUser = "anonymous"; - this.ftpPass = "anonymous"; + public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException { + url = message.getURL(); + final FTPClient ftp = createFTP(); + + String path = url.getPath(); + try { + if (!ftp.deleteFile(path)) { + throw new JMSException("Delete file failed: " + ftp.getReplyString()); + } + } finally { + ftp.quit(); + ftp.disconnect(); } + } } Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java Fri May 14 09:21:42 2010 @@ -20,10 +20,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.ConnectException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Arrays; import javax.jms.JMSException; @@ -33,70 +31,42 @@ import org.apache.commons.net.ftp.FTPCli /** * A FTP implementation of {@link BlobUploadStrategy}. */ -public class FTPBlobUploadStrategy implements BlobUploadStrategy { - - private URL url; - private String ftpUser = ""; - private String ftpPass = ""; - private BlobTransferPolicy transferPolicy; +public class FTPBlobUploadStrategy extends FTPStrategy implements BlobUploadStrategy { public FTPBlobUploadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException { - this.transferPolicy = transferPolicy; - this.url = new URL(this.transferPolicy.getUploadUrl()); - - setUserInformation(url.getUserInfo()); + super(transferPolicy); } - public URL uploadFile(ActiveMQBlobMessage message, File file) - throws JMSException, IOException { + public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException { return uploadStream(message, new FileInputStream(file)); } public URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException { - String connectUrl = url.getHost(); - int port = url.getPort() < 1 ? 21 : url.getPort(); + + FTPClient ftp = createFTP(); + try { + String path = url.getPath(); + String workingDir = path.substring(0, path.lastIndexOf("/")); + String filename = message.getMessageId().toString().replaceAll(":", "_"); + ftp.setFileType(FTPClient.BINARY_FILE_TYPE); + + String url; + if(!ftp.changeWorkingDirectory(workingDir)) { + url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/"; + } else { + url = this.url.toString(); + } + + if (!ftp.storeFile(filename, in)) { + throw new JMSException("FTP store failed: " + ftp.getReplyString()); + } + return new URL(url + filename); + } finally { + ftp.quit(); + ftp.disconnect(); + } - FTPClient ftp = new FTPClient(); - try { - ftp.connect(connectUrl, port); - } catch(ConnectException e) { - throw new JMSException("Problem connecting the FTP-server"); - } - if(!ftp.login(ftpUser, ftpPass)) { - ftp.quit(); - ftp.disconnect(); - throw new JMSException("Cant Authentificate to FTP-Server"); - } - String path = url.getPath(); - String workingDir = path.substring(0, path.lastIndexOf("/")); - String filename = message.getMessageId().toString().replaceAll(":", "_"); - ftp.setFileType(FTPClient.BINARY_FILE_TYPE); - - String url; - if(!ftp.changeWorkingDirectory(workingDir)) { - url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/"; - } else { - url = this.url.toString(); - } - - if (!ftp.storeFile(filename, in)) { - throw new JMSException("FTP store failed: " + ftp.getReplyString()); - } - ftp.quit(); - ftp.disconnect(); - return new URL(url + filename); - } - - private void setUserInformation(String userInfo) { - if(userInfo != null) { - String[] userPass = userInfo.split(":"); - if(userPass.length > 0) this.ftpUser = userPass[0]; - if(userPass.length > 1) this.ftpPass = userPass[1]; - } else { - this.ftpUser = "anonymous"; - this.ftpPass = "anonymous"; - } } } Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPStrategy.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPStrategy.java?rev=944167&view=auto ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPStrategy.java (added) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/FTPStrategy.java Fri May 14 09:21:42 2010 @@ -0,0 +1,55 @@ +package org.apache.activemq.blob; + +import java.io.IOException; +import java.net.ConnectException; +import java.net.MalformedURLException; +import java.net.URL; + +import javax.jms.JMSException; + +import org.apache.activemq.command.ActiveMQBlobMessage; +import org.apache.commons.net.ftp.FTPClient; + +public class FTPStrategy { + + protected BlobTransferPolicy transferPolicy; + protected URL url; + protected String ftpUser = ""; + protected String ftpPass = ""; + + public FTPStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException { + this.transferPolicy = transferPolicy; + this.url = new URL(this.transferPolicy.getUploadUrl()); + } + + protected void setUserInformation(String userInfo) { + if(userInfo != null) { + String[] userPass = userInfo.split(":"); + if(userPass.length > 0) this.ftpUser = userPass[0]; + if(userPass.length > 1) this.ftpPass = userPass[1]; + } else { + this.ftpUser = "anonymous"; + this.ftpPass = "anonymous"; + } + } + + protected FTPClient createFTP() throws IOException, JMSException { + String connectUrl = url.getHost(); + setUserInformation(url.getUserInfo()); + int port = url.getPort() < 1 ? 21 : url.getPort(); + + FTPClient ftp = new FTPClient(); + try { + ftp.connect(connectUrl, port); + } catch(ConnectException e) { + throw new JMSException("Problem connecting the FTP-server"); + } + if(!ftp.login(ftpUser, ftpPass)) { + ftp.quit(); + ftp.disconnect(); + throw new JMSException("Cant Authentificate to FTP-Server"); + } + return ftp; + } + +} Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQBlobMessage.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQBlobMessage.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQBlobMessage.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQBlobMessage.java Fri May 14 09:21:42 2010 @@ -177,4 +177,8 @@ public class ActiveMQBlobMessage extends } } } + + public void deleteFile() throws IOException, JMSException { + blobDownloader.deleteFile(this); + } } Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/DefaultBlobUploadStrategyTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/DefaultBlobUploadStrategyTest.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/DefaultBlobUploadStrategyTest.java (original) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/DefaultBlobUploadStrategyTest.java Fri May 14 09:21:42 2010 @@ -77,7 +77,7 @@ public class DefaultBlobUploadStrategyTe TestCase.assertTrue(bytesRead == file.length()); // 3. Delete - strategy.deleteFile(msg); + //strategy.deleteFile(msg); } } Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java (original) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobDownloadStrategyTest.java Fri May 14 09:21:42 2010 @@ -19,6 +19,7 @@ package org.apache.activemq.blob; import java.io.File; import java.io.FileWriter; import java.io.InputStream; +import java.net.MalformedURLException; import java.net.URL; import javax.jms.JMSException; @@ -47,7 +48,7 @@ public class FTPBlobDownloadStrategyTest wrt.close(); ActiveMQBlobMessage message = new ActiveMQBlobMessage(); - BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(); + BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy()); InputStream stream; try { message.setURL(new URL(ftpUrl + "test.txt")); @@ -61,15 +62,19 @@ public class FTPBlobDownloadStrategyTest Assert.assertEquals("hello world", sb.toString().substring(0, "hello world".length())); Assert.assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length()); + assertTrue(uploadFile.exists()); + strategy.deleteFile(message); + assertFalse(uploadFile.exists()); + } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(false); } } - public void testWrongAuthentification() { + public void testWrongAuthentification() throws MalformedURLException { ActiveMQBlobMessage message = new ActiveMQBlobMessage(); - BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(); + BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy()); try { message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/")); strategy.getInputStream(message); @@ -85,9 +90,9 @@ public class FTPBlobDownloadStrategyTest Assert.assertTrue("Expect Exception", false); } - public void testWrongFTPPort() { + public void testWrongFTPPort() throws MalformedURLException { ActiveMQBlobMessage message = new ActiveMQBlobMessage(); - BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(); + BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy()); try { message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/")); strategy.getInputStream(message); Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java (original) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPBlobTest.java Fri May 14 09:21:42 2010 @@ -66,7 +66,11 @@ public class FTPBlobTest extends FTPTest i = input.read(); } input.close(); + File uploaded = new File(ftpHomeDirFile, msg.getJMSMessageID().toString().replace(":", "_")); Assert.assertEquals(content, b.toString()); + assertTrue(uploaded.exists()); + ((ActiveMQBlobMessage)msg).deleteFile(); + assertFalse(uploaded.exists()); } } Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPTestSupport.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPTestSupport.java?rev=944167&r1=944166&r2=944167&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPTestSupport.java (original) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/FTPTestSupport.java Fri May 14 09:21:42 2010 @@ -7,6 +7,7 @@ import java.util.List; import javax.jms.Connection; import org.apache.activemq.EmbeddedBrokerTestSupport; +import org.apache.activemq.util.IOHelper; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.Authority; @@ -33,7 +34,7 @@ public abstract class FTPTestSupport ext protected void setUp() throws Exception { if (ftpHomeDirFile.getParentFile().exists()) { - ftpHomeDirFile.getParentFile().delete(); + IOHelper.deleteFile(ftpHomeDirFile.getParentFile()); } ftpHomeDirFile.mkdirs(); ftpHomeDirFile.getParentFile().deleteOnExit(); @@ -99,6 +100,7 @@ public abstract class FTPTestSupport ext if (server != null) { server.stop(); } + IOHelper.deleteFile(ftpHomeDirFile.getParentFile()); }