Issue 467:terremark ecloud: NumberFormatException

This commit is contained in:
Adrian Cole 2011-02-08 17:16:09 -08:00
parent a75486f2e6
commit 33dd0cce8a
9 changed files with 269 additions and 87 deletions

View File

@ -39,17 +39,19 @@ public class CustomizationParametersHandler extends HandlerWithResult<Customizat
@Override @Override
public CustomizationParameters getResult() { public CustomizationParameters getResult() {
return new CustomizationParameters(customizeNetwork, customizePassword, return new CustomizationParameters(customizeNetwork, customizePassword, customizeSSH);
customizeSSH);
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("CustomizeNetwork")) { String current = currentOrNull();
customizeNetwork = Boolean.parseBoolean(currentOrNull()); if (current != null) {
} else if (qName.equals("CustomizePassword")) { if (qName.equals("CustomizeNetwork")) {
customizePassword = Boolean.parseBoolean(currentOrNull()); customizeNetwork = Boolean.parseBoolean(current);
} else if (qName.equals("CustomizeSSH")) { } else if (qName.equals("CustomizePassword")) {
customizeSSH = Boolean.parseBoolean(currentOrNull()); customizePassword = Boolean.parseBoolean(current);
} else if (qName.equals("CustomizeSSH")) {
customizeSSH = Boolean.parseBoolean(current);
}
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -70,31 +70,34 @@ public class InternetServiceHandler extends HandlerWithResult<InternetService> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Href") && currentOrNull() != null) { String current = currentOrNull();
if (inPublicIpAddress) if (qName.equals("PublicIpAddress")) {
addressLocation = URI.create(currentOrNull());
else
location = URI.create(currentOrNull());
} else if (qName.equals("Name")) {
if (inPublicIpAddress)
address = currentOrNull();
else
serviceName = currentOrNull();
} else if (qName.equals("PublicIpAddress")) {
publicIpAddress = new PublicIpAddress(address, addressLocation); publicIpAddress = new PublicIpAddress(address, addressLocation);
address = null; address = null;
addressLocation = null; addressLocation = null;
inPublicIpAddress = false; inPublicIpAddress = false;
} else if (qName.equals("Port")) { } else if (current != null) {
port = Integer.parseInt(currentOrNull()); if (qName.equals("Href")) {
} else if (qName.equals("Protocol")) { if (inPublicIpAddress)
protocol = Protocol.valueOf(currentOrNull()); addressLocation = URI.create(current);
} else if (qName.equals("Enabled")) { else
enabled = Boolean.parseBoolean(currentOrNull()); location = URI.create(current);
} else if (qName.equals("Timeout")) { } else if (qName.equals("Name")) {
timeout = Integer.parseInt(currentOrNull()); if (inPublicIpAddress)
} else if (qName.equals("Description")) { address = current;
description = currentOrNull(); else
serviceName = current;
} else if (qName.equals("Port")) {
port = Integer.parseInt(current);
} else if (qName.equals("Protocol")) {
protocol = Protocol.valueOf(current);
} else if (qName.equals("Enabled")) {
enabled = Boolean.parseBoolean(current);
} else if (qName.equals("Timeout")) {
timeout = Integer.parseInt(current);
} else if (qName.equals("Description")) {
description = current;
}
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -53,8 +53,7 @@ public class IpAddressesHandler extends ParseSax.HandlerWithResult<Set<IpAddress
return addresses; return addresses;
} }
public void startElement(String uri, String localName, String qName, Attributes attributes) public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
throws SAXException {
if (attributes.getIndex("xsi:nil") != -1) { if (attributes.getIndex("xsi:nil") != -1) {
skip = true; skip = true;
return; return;
@ -65,12 +64,15 @@ public class IpAddressesHandler extends ParseSax.HandlerWithResult<Set<IpAddress
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("Name")) { String current = currentOrNull();
address = currentOrNull(); if (current != null) {
} else if (qName.equals("Status")) { if (qName.equals("Name")) {
status = IpAddress.Status.fromValue(currentOrNull()); address = current;
} else if (!skip && qName.equals("Server")) { } else if (qName.equals("Status")) {
server = currentOrNull(); status = IpAddress.Status.fromValue(current);
} else if (!skip && qName.equals("Server")) {
server = current;
}
} else if (qName.equals("IpAddress")) { } else if (qName.equals("IpAddress")) {
addresses.add(new IpAddress(address, status, server)); addresses.add(new IpAddress(address, status, server));
address = null; address = null;

View File

@ -53,16 +53,19 @@ public class KeyPairHandler extends HandlerWithResult<KeyPair> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Href") && currentOrNull() != null) { String current = currentOrNull();
location = URI.create(currentOrNull()); if (current != null) {
} else if (qName.equals("Name")) { if (qName.equals("Href")) {
this.name = currentOrNull(); location = URI.create(current);
} else if (qName.equals("IsDefault")) { } else if (qName.equals("Name")) {
isDefault = Boolean.parseBoolean(currentOrNull()); this.name = current;
} else if (qName.equals("PrivateKey")) { } else if (qName.equals("IsDefault")) {
privateKey = currentOrNull(); isDefault = Boolean.parseBoolean(current);
} else if (qName.equals("FingerPrint")) { } else if (qName.equals("PrivateKey")) {
fingerPrint = currentOrNull(); privateKey = current;
} else if (qName.equals("FingerPrint")) {
fingerPrint = current;
}
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -54,18 +54,21 @@ public class NodeHandler extends HandlerWithResult<Node> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Href") && currentOrNull() != null) { String current = currentOrNull();
location = URI.create(currentOrNull()); if (current != null) {
} else if (qName.equals("Name")) { if (qName.equals("Href")) {
serviceName = currentOrNull(); location = URI.create(current);
} else if (qName.equals("Port")) { } else if (qName.equals("Name")) {
port = Integer.parseInt(currentOrNull()); serviceName = current;
} else if (qName.equals("Enabled")) { } else if (qName.equals("Port")) {
enabled = Boolean.parseBoolean(currentOrNull()); port = Integer.parseInt(current);
} else if (qName.equals("IpAddress")) { } else if (qName.equals("Enabled")) {
address = currentOrNull(); enabled = Boolean.parseBoolean(current);
} else if (qName.equals("Description")) { } else if (qName.equals("IpAddress")) {
description = currentOrNull(); address = current;
} else if (qName.equals("Description")) {
description = current;
}
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -52,10 +52,13 @@ public class PublicIpAddressHandler extends HandlerWithResult<PublicIpAddress> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Href") && currentOrNull() != null) { String current = currentOrNull();
location = URI.create(currentOrNull()); if (current != null) {
} else if (qName.equals("Name")) { if (qName.equals("Href")) {
address = currentOrNull(); location = URI.create(current);
} else if (qName.equals("Name")) {
address = current;
}
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -60,26 +60,29 @@ public class TerremarkNetworkHandler extends HandlerWithResult<TerremarkNetwork>
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Href") && currentOrNull() != null) { String current = currentOrNull();
href = URI.create(currentOrNull()); if (current != null) {
} else if (qName.equals("Id")) { if (qName.equals("Href")) {
id = currentOrNull(); href = URI.create(current);
} else if (qName.equals("Name")) { } else if (qName.equals("Id")) {
this.name = currentOrNull(); id = current;
} else if (qName.equals("RnatAddress")) { } else if (qName.equals("Name")) {
rnatAddress = currentOrNull(); this.name = current;
} else if (qName.equals("Address")) { } else if (qName.equals("RnatAddress")) {
address = currentOrNull(); rnatAddress = current;
} else if (qName.equals("BroadcastAddress")) { } else if (qName.equals("Address")) {
broadcastAddress = currentOrNull(); address = current;
} else if (qName.equals("GatewayAddress")) { } else if (qName.equals("BroadcastAddress")) {
gatewayAddress = currentOrNull(); broadcastAddress = current;
} else if (qName.equals("NetworkType")) { } else if (qName.equals("GatewayAddress")) {
networkType = TerremarkNetwork.Type.fromValue(currentOrNull()); gatewayAddress = current;
} else if (qName.equals("Vlan")) { } else if (qName.equals("NetworkType")) {
vlan = currentOrNull(); networkType = TerremarkNetwork.Type.fromValue(current);
} else if (qName.equals("FriendlyName")) { } else if (qName.equals("Vlan")) {
friendlyName = currentOrNull(); vlan = current;
} else if (qName.equals("FriendlyName")) {
friendlyName = current;
}
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -43,13 +43,21 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "InternetServicesHandlerTest") @Test(groups = "unit", testName = "InternetServicesHandlerTest")
public class InternetServicesHandlerTest extends BaseHandlerTest { public class InternetServicesHandlerTest extends BaseHandlerTest {
public void test2() throws UnknownHostException { public void test() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/InternetServices.xml"); InputStream is = getClass().getResourceAsStream("/terremark/InternetServices.xml");
Set<InternetService> result = factory.create(injector.getInstance(InternetServicesHandler.class)).parse(is); Set<InternetService> result = factory.create(injector.getInstance(InternetServicesHandler.class)).parse(is);
assertEquals(result, ImmutableSet.of(new InternetService("IS_for_Jim2", URI assertEquals(result, ImmutableSet.of(new InternetService("IS_for_Jim2", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"), new PublicIpAddress( .create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"),
"10.1.22.159", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208")), 45, new PublicIpAddress("10.1.22.159", URI
Protocol.HTTP, false, 1, "Some test service"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208")), 45,
Protocol.HTTP, false, 1, "Some test service")));
}
public void test2() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/InternetServices-2.xml");
Set<InternetService> result = factory.create(injector.getInstance(InternetServicesHandler.class)).parse(is);
assertEquals(result.size(), 6);
} }
} }

View File

@ -0,0 +1,155 @@
<InternetServices xmlns="urn:tmrk:eCloudExtensions-2.6"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<InternetService>
<Id>18792</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/internetService/18792</Href>
<Name>cl960b-62752757-443</Name>
<PublicIpAddress>
<Id>29232</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/publicIp/29232</Href>
<Name>209.251.180.145</Name>
</PublicIpAddress>
<Port>443</Port>
<Protocol>TCP</Protocol>
<Enabled>true</Enabled>
<Timeout>2</Timeout>
<Description />
<RedirectURL />
<Monitor i:nil="true" />
<IsBackupService>false</IsBackupService>
<BackupService i:nil="true" />
<BackupOf />
<PersistenceType>SourceIP</PersistenceType>
<TrustedNetworkGroup i:nil="true" />
</InternetService>
<InternetService>
<Id>19264</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/internetService/19264</Href>
<Name>OpenVPN</Name>
<PublicIpAddress>
<Id>36648</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/publicIp/36648</Href>
<Name>209.251.180.245</Name>
</PublicIpAddress>
<Port>1194</Port>
<Protocol>UDP</Protocol>
<Enabled>true</Enabled>
<Timeout>2</Timeout>
<Description />
<RedirectURL />
<Monitor i:nil="true" />
<IsBackupService>false</IsBackupService>
<BackupService i:nil="true" />
<BackupOf />
<PersistenceType>SourceIP</PersistenceType>
<TrustedNetworkGroup i:nil="true" />
</InternetService>
<InternetService>
<Id>20870</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/internetService/20870</Href>
<Name>cid6b2-64d1f1e8-443</Name>
<PublicIpAddress>
<Id>40097</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/publicIp/40097</Href>
<Name>209.251.181.14</Name>
</PublicIpAddress>
<Port>443</Port>
<Protocol>TCP</Protocol>
<Enabled>true</Enabled>
<Timeout>2</Timeout>
<Description />
<RedirectURL />
<Monitor i:nil="true" />
<IsBackupService>false</IsBackupService>
<BackupService i:nil="true" />
<BackupOf />
<PersistenceType>SourceIP</PersistenceType>
<TrustedNetworkGroup i:nil="true" />
</InternetService>
<InternetService>
<Id>21170</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/internetService/21170</Href>
<Name>cic908-6b6a0ac2-443</Name>
<PublicIpAddress>
<Id>40162</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/publicIp/40162</Href>
<Name>209.251.181.16</Name>
</PublicIpAddress>
<Port>443</Port>
<Protocol>TCP</Protocol>
<Enabled>true</Enabled>
<Timeout i:nil="true" />
<Description />
<RedirectURL />
<Monitor>
<MonitorType>Disabled</MonitorType>
<UrlSendString i:nil="true" />
<HttpHeader i:nil="true" />
<ReceiveString i:nil="true" />
<Interval>0</Interval>
<ResponseTimeOut>0</ResponseTimeOut>
<DownTime>0</DownTime>
<Retries>0</Retries>
<IsEnabled>true</IsEnabled>
</Monitor>
<IsBackupService>false</IsBackupService>
<BackupService i:nil="true" />
<BackupOf />
<PersistenceType>None</PersistenceType>
<TrustedNetworkGroup i:nil="true" />
</InternetService>
<InternetService>
<Id>21319</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/internetService/21319</Href>
<Name>ci7eeb-7a6baa70-443</Name>
<PublicIpAddress>
<Id>40203</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/publicIp/40203</Href>
<Name>209.251.181.17</Name>
</PublicIpAddress>
<Port>443</Port>
<Protocol>TCP</Protocol>
<Enabled>true</Enabled>
<Timeout>2</Timeout>
<Description />
<RedirectURL />
<Monitor>
<MonitorType>Disabled</MonitorType>
<UrlSendString i:nil="true" />
<HttpHeader i:nil="true" />
<ReceiveString i:nil="true" />
<Interval>0</Interval>
<ResponseTimeOut>0</ResponseTimeOut>
<DownTime>0</DownTime>
<Retries>0</Retries>
<IsEnabled>true</IsEnabled>
</Monitor>
<IsBackupService>false</IsBackupService>
<BackupService i:nil="true" />
<BackupOf />
<PersistenceType>SourceIP</PersistenceType>
<TrustedNetworkGroup i:nil="true" />
</InternetService>
<InternetService>
<Id>13798</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/internetService/13798</Href>
<Name>cl8116-4df02afd-443</Name>
<PublicIpAddress>
<Id>48625</Id>
<Href>https://services.enterprisecloud.terremark.com/api/v0.8b-ext2.6/extensions/publicIp/48625</Href>
<Name>209.251.181.60</Name>
</PublicIpAddress>
<Port>443</Port>
<Protocol>TCP</Protocol>
<Enabled>true</Enabled>
<Timeout>2</Timeout>
<Description />
<RedirectURL />
<Monitor i:nil="true" />
<IsBackupService>false</IsBackupService>
<BackupService i:nil="true" />
<BackupOf />
<PersistenceType>SourceIP</PersistenceType>
<TrustedNetworkGroup i:nil="true" />
</InternetService>
</InternetServices>