Issue 873:NPE on InstantiateVAppTemplate

This commit is contained in:
Adrian Cole 2012-03-15 22:38:46 -07:00
parent 1bef09ab91
commit 0365e58566
3 changed files with 19 additions and 6 deletions

View File

@ -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<Task> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> 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<Task> {
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<Task> {
@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<Task> {
endTime = null;
owner = null;
error = null;
} else if (qName.equalsIgnoreCase("Owner")) {
} else if (equalsOrSuffix(qName, "Owner")) {
inOwner = false;
}
}

View File

@ -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");

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<vcloud:Task xmlns:vcloud="http://www.vmware.com/vcloud/v1" status="running" startTime="2012-03-15T22:47:02.058-06:00" operation="Updating Virtual Machine UbuntuServer-x64-2GB(c9004a47-5e21-4cf1-860c-670d8965b24a)" expiryTime="2012-06-13T22:47:02.058-06:00" type="application/vnd.vmware.vcloud.task+xml" href="https://mycloud.greenhousedata.com/api/v1.0/task/77a33fd4-3401-423c-8167-6711fc51ee9a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://mycloud.greenhousedata.com/api/v1.0/schema/master.xsd">
<vcloud:Link rel="task:cancel" href="https://mycloud.greenhousedata.com/api/v1.0/task/77a33fd4-3401-423c-8167-6711fc51ee9a/action/cancel"/>
<vcloud:Owner type="application/vnd.vmware.vcloud.vm+xml" name="UbuntuServer-x64-2GB" href="https://mycloud.greenhousedata.com/api/v1.0/vApp/vm-c9004a47-5e21-4cf1-860c-670d8965b24a"/>
</vcloud:Task>