From 01cda8582a834feeed50b97f7042bb2b94581b35 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 5 Jun 2013 18:29:35 +0000 Subject: [PATCH] Fix test failure after recent MessageId changes. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1489994 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/blob/FTPBlobUploadStrategy.java | 56 ++++++++++--------- .../apache/activemq/command/MessageId.java | 23 ++++---- .../blob/FTPBlobUploadStrategyTest.java | 9 ++- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/activemq-client/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java b/activemq-client/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java index 9ce52bd253..6cb0e8ae74 100644 --- a/activemq-client/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java +++ b/activemq-client/src/main/java/org/apache/activemq/blob/FTPBlobUploadStrategy.java @@ -32,41 +32,43 @@ import org.apache.commons.net.ftp.FTPClient; * A FTP implementation of {@link BlobUploadStrategy}. */ public class FTPBlobUploadStrategy extends FTPStrategy implements BlobUploadStrategy { - - public FTPBlobUploadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException { - super(transferPolicy); - } - public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException { - return uploadStream(message, new FileInputStream(file)); - } + public FTPBlobUploadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException { + super(transferPolicy); + } - public URL uploadStream(ActiveMQBlobMessage message, InputStream in) - throws JMSException, IOException { + @Override + public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException { + return uploadStream(message, new FileInputStream(file)); + } - FTPClient ftp = createFTP(); - try { - String path = url.getPath(); + @Override + public URL uploadStream(ActiveMQBlobMessage message, InputStream in) + throws JMSException, IOException { + + FTPClient ftp = createFTP(); + try { + String path = url.getPath(); String workingDir = path.substring(0, path.lastIndexOf("/")); - String filename = message.getMessageId().toString().replaceAll(":", "_"); + 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(), "")+"/"; + url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/"; } else { - url = this.url.toString(); + 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(); - } - - } + + if (!ftp.storeFile(filename, in)) { + throw new JMSException("FTP store failed: " + ftp.getReplyString()); + } + return new URL(url + filename); + } finally { + ftp.quit(); + ftp.disconnect(); + } + + } } diff --git a/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java b/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java index 4a223d0b84..5c3069f9d6 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java @@ -77,9 +77,8 @@ public class MessageId implements DataStructure, Comparable { } /** - * Sets the transient text view of the message which will be ignored if the - * message is marshaled on a transport; so is only for in-JVM changes to - * accommodate foreign JMS message IDs + * Sets the transient text view of the message which will be ignored if the message is marshaled on a transport; so + * is only for in-JVM changes to accommodate foreign JMS message IDs */ public void setTextView(String key) { this.textView = key; @@ -107,20 +106,20 @@ public class MessageId implements DataStructure, Comparable { return false; } - MessageId id = (MessageId)o; + MessageId id = (MessageId) o; return producerSequenceId == id.producerSequenceId && producerId.equals(id.producerId); } @Override public int hashCode() { if (hashCode == 0) { - hashCode = producerId.hashCode() ^ (int)producerSequenceId; + hashCode = producerId.hashCode() ^ (int) producerSequenceId; } return hashCode; } public String toProducerKey() { - if( textView==null ) { + if (textView == null) { return toString(); } else { return producerId.toString() + ":" + producerSequenceId; @@ -130,11 +129,11 @@ public class MessageId implements DataStructure, Comparable { @Override public String toString() { if (key == null) { - if( textView!=null ) { - if( textView.startsWith("ID:") ) { + if (textView != null) { + if (textView.startsWith("ID:")) { key = textView; } else { - key = "ID:"+textView; + key = "ID:" + textView; } } else { key = producerId.toString() + ":" + producerSequenceId; @@ -207,16 +206,14 @@ public class MessageId implements DataStructure, Comparable { } /** - * @return a locator which aids a message store in loading a message faster. Only used - * by the message stores. + * @return a locator which aids a message store in loading a message faster. Only used by the message stores. */ public Object getDataLocator() { return dataLocator.get(); } /** - * Sets a locator which aids a message store in loading a message faster. Only used - * by the message stores. + * Sets a locator which aids a message store in loading a message faster. Only used by the message stores. */ public void setDataLocator(Object value) { this.dataLocator.set(value); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java index f76dbc39e4..cac9a0aabd 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/FTPBlobUploadStrategyTest.java @@ -26,7 +26,6 @@ import javax.jms.Session; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQSession; import org.apache.activemq.command.ActiveMQBlobMessage; -import org.apache.activemq.command.MessageId; public class FTPBlobUploadStrategyTest extends FTPTestSupport { @@ -43,10 +42,10 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport { ((ActiveMQConnection)connection).setCopyMessageOnSend(false); ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file); - message.setMessageId(new MessageId("testmessage")); + message.setJMSMessageID("testmessage"); message.onSend(); - assertEquals(ftpUrl + "testmessage", message.getURL().toString()); - File uploaded = new File(ftpHomeDirFile, "testmessage"); + assertEquals(ftpUrl + "ID_testmessage", message.getURL().toString()); + File uploaded = new File(ftpHomeDirFile, "ID_testmessage"); assertTrue("File doesn't exists", uploaded.exists()); } @@ -63,7 +62,7 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport { ((ActiveMQConnection)connection).setCopyMessageOnSend(false); ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file); - message.setMessageId(new MessageId("testmessage")); + message.setJMSMessageID("testmessage"); try { message.onSend(); } catch (JMSException e) {