From b508f87e3d000d72a17dea43e328167f913b39a9 Mon Sep 17 00:00:00 2001 From: andreisavu Date: Tue, 15 Nov 2011 12:22:03 +0200 Subject: [PATCH] Throw an IllegalStateException on firewall authorization failure --- .../cloudstack/handlers/CloudStackErrorHandler.java | 3 +++ .../handlers/CloudStackErrorHandlerTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java index 8988d649a4..170f89069a 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java @@ -77,6 +77,9 @@ public class CloudStackErrorHandler implements HttpErrorHandler { exception = new IllegalStateException(message, exception); } break; + case 537: + exception = new IllegalStateException(message, exception); + break; } } finally { if (response.getPayload() != null) diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandlerTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandlerTest.java index 81f0a88239..36ea5eaacb 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandlerTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandlerTest.java @@ -91,6 +91,16 @@ public class CloudStackErrorHandlerTest { assertCodeMakes("GET", URI.create("https://cloudstack.com/foo"), 409, "", "Conflict", IllegalStateException.class); } + @Test void test537MakesIllegalStateException() { + assertCodeMakes( + "GET", + URI.create("http://10.26.26.155:8080/client/api?response=json&command=createIpForwardingRule&ipaddressid=37&startport=22&protocol=tcp"), + 537, + "", + "{ \"createipforwardingruleresponse\" : {\"errorcode\" : 537, \"errortext\" : \"There is already firewall rule specified for the ip address id=37\"} }", + IllegalStateException.class); + } + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, Class expected) { assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);