diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java index 5f27aecfc1..5a898b307b 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java @@ -18,6 +18,8 @@ */ package org.jclouds.vcloud.xml; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + import java.text.ParseException; import java.util.Date; import java.util.Map; @@ -69,7 +71,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult { @Override public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { Map attributes = SaxUtils.cleanseAttributes(attrs); - if (qName.equalsIgnoreCase("Task")) { + if (equalsOrSuffix(qName, "Task")) { if (attributes.get("href") != null && !inOwner)// queued tasks may not have an // href yet taskLink = Utils.newReferenceType(attributes); @@ -82,11 +84,11 @@ public class TaskHandler extends ParseSax.HandlerWithResult { if (attributes.containsKey("expiryTime")) expiryTime = parseDate(attributes.get("expiryTime")); // TODO technically the old Result object should only be owner for copy and delete tasks - } else if (qName.equals("Owner") || qName.equals("Result")) { + } else if (equalsOrSuffix(qName, "Owner") || equalsOrSuffix(qName, "Result")) { owner = Utils.newReferenceType(attributes); - } else if (qName.equals("Link") && "self".equals(attributes.get("rel"))) { + } else if (equalsOrSuffix(qName, "Link") && "self".equals(attributes.get("rel"))) { taskLink = Utils.newReferenceType(attributes); - } else if (qName.equals("Error")) { + } else if (equalsOrSuffix(qName, "Error")) { error = Utils.newError(attributes); } } @@ -108,7 +110,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult { @Override public void endElement(String uri, String localName, String qName) { - if (qName.equalsIgnoreCase("Task")) { + if (equalsOrSuffix(qName, "Task")) { this.task = new TaskImpl(taskLink.getHref(), operation, status, startTime, endTime, expiryTime, owner, error); operation = null; taskLink = null; @@ -117,7 +119,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult { endTime = null; owner = null; error = null; - } else if (qName.equalsIgnoreCase("Owner")) { + } else if (equalsOrSuffix(qName, "Owner")) { inOwner = false; } } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java index f967e34213..bb69c6be9d 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java @@ -52,6 +52,12 @@ public class TaskHandlerTest extends BaseHandlerTest { super.setUpInjector(); dateService = injector.getInstance(DateService.class); } + + public void testHrefWhenTaskElementIsNamespaced() { + InputStream is = getClass().getResourceAsStream("/task-vcd15.xml"); + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + assertEquals(result.getHref(), URI.create("https://mycloud.greenhousedata.com/api/v1.0/task/77a33fd4-3401-423c-8167-6711fc51ee9a")); + } public void test() { InputStream is = getClass().getResourceAsStream("/task-1.0.xml"); diff --git a/apis/vcloud/src/test/resources/task-vcd15.xml b/apis/vcloud/src/test/resources/task-vcd15.xml new file mode 100644 index 0000000000..452287dadd --- /dev/null +++ b/apis/vcloud/src/test/resources/task-vcd15.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file