Repository: activemq
Updated Branches:
  refs/heads/master 09acc504f -> b64ac1dd7


[AMQ-6646] improve error reporting to include url


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/b64ac1dd
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/b64ac1dd
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/b64ac1dd

Branch: refs/heads/master
Commit: b64ac1dd779e2eb62a8cda1775f2ab6491d05771
Parents: 09acc50
Author: gtully <gary.tu...@gmail.com>
Authored: Tue Apr 4 17:30:29 2017 +0100
Committer: gtully <gary.tu...@gmail.com>
Committed: Tue Apr 4 17:30:29 2017 +0100

----------------------------------------------------------------------
 .../blob/DefaultBlobDownloadStrategy.java       | 10 ++++--
 .../blob/DefaultBlobUploadStrategy.java         |  4 ++-
 .../blob/BlobTransferPolicyUriTest.java         | 34 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/b64ac1dd/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java
----------------------------------------------------------------------
diff --git 
a/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java
 
b/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java
index 56695c7..3b4ef0a 100644
--- 
a/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java
+++ 
b/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobDownloadStrategy.java
@@ -46,9 +46,13 @@ public class DefaultBlobDownloadStrategy extends 
DefaultStrategy implements Blob
 
         HttpURLConnection connection = (HttpURLConnection)url.openConnection();
         connection.setRequestMethod("DELETE");
-        connection.connect();
-        connection.disconnect();
-
+        try {
+            connection.connect();
+        } catch (IOException e) {
+            throw new IOException("DELETE failed on: " + url, e);
+        } finally {
+            connection.disconnect();
+        }
         if (!isSuccessfulCode(connection.getResponseCode())) {
             throw new IOException("DELETE was not successful: " + 
connection.getResponseCode() + " "
                                   + connection.getResponseMessage());

http://git-wip-us.apache.org/repos/asf/activemq/blob/b64ac1dd/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
----------------------------------------------------------------------
diff --git 
a/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
 
b/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
index 655c942..6672eec 100644
--- 
a/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
+++ 
b/activemq-client/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
@@ -63,10 +63,12 @@ public class DefaultBlobUploadStrategy extends 
DefaultStrategy implements BlobUp
                 os.write(buf, 0, c);
                 os.flush();
             }
+        } catch (IOException error) {
+            throw new IOException("PUT failed to: " + url, error);
         }
 
         if (!isSuccessfulCode(connection.getResponseCode())) {
-            throw new IOException("PUT was not successful: " + 
connection.getResponseCode() + " "
+            throw new IOException("PUT to " + url + " was not successful: " + 
connection.getResponseCode() + " "
                                   + connection.getResponseMessage());
         }
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/b64ac1dd/activemq-unit-tests/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
----------------------------------------------------------------------
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
index 4040569..28d1bb0 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
@@ -18,6 +18,11 @@ package org.apache.activemq.blob;
 
 import junit.framework.TestCase;
 import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQBlobMessage;
+import org.apache.activemq.command.MessageId;
+
+import java.io.IOException;
+import java.io.InputStream;
 
 /**
  * 
@@ -29,4 +34,33 @@ public class BlobTransferPolicyUriTest extends TestCase {
         assertEquals("http://foo.com";, policy.getDefaultUploadUrl());
         assertEquals("http://foo.com";, policy.getUploadUrl());
     }
+
+    public void testDefaultUploadStrategySensibleError() throws Exception {
+        ActiveMQConnectionFactory factory = new 
ActiveMQConnectionFactory("vm://localhost");
+        BlobTransferPolicy policy = factory.getBlobTransferPolicy();
+        BlobUploadStrategy strategy = policy.getUploadStrategy();
+        ActiveMQBlobMessage message = new ActiveMQBlobMessage();
+        message.setMessageId(new MessageId("1:0:0:0"));
+        try {
+            strategy.uploadStream(message, message.getInputStream());
+        } catch (IOException expected) {
+            assertTrue(expected.getMessage().contains("8080"));
+            expected.printStackTrace();
+        }
+    }
+
+    public void testDefaultDownlaodStrategySensibleError() throws Exception {
+        ActiveMQConnectionFactory factory = new 
ActiveMQConnectionFactory("vm://localhost");
+        BlobTransferPolicy policy = factory.getBlobTransferPolicy();
+        BlobDownloadStrategy strategy = policy.getDownloadStrategy();
+        ActiveMQBlobMessage message = new ActiveMQBlobMessage();
+        message.setMessageId(new MessageId("1:0:0:0"));
+        try {
+            strategy.deleteFile(message);
+        } catch (IOException expected) {
+            assertTrue(expected.getMessage().contains("8080"));
+            expected.printStackTrace();
+        }
+
+    }
 }

Reply via email to