[AMQ-6646] improve error reporting to include url

This commit is contained in:
gtully 2017-04-04 17:30:29 +01:00
parent 09acc504f1
commit b64ac1dd77
3 changed files with 44 additions and 4 deletions

View File

@ -46,9 +46,13 @@ public class DefaultBlobDownloadStrategy extends DefaultStrategy implements Blob
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("DELETE");
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());

View File

@ -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());
}

View File

@ -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();
}
}
}