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
public CustomizationParameters getResult() {
return new CustomizationParameters(customizeNetwork, customizePassword,
customizeSSH);
return new CustomizationParameters(customizeNetwork, customizePassword, customizeSSH);
}
public void endElement(String uri, String name, String qName) {
if (qName.equals("CustomizeNetwork")) {
customizeNetwork = Boolean.parseBoolean(currentOrNull());
} else if (qName.equals("CustomizePassword")) {
customizePassword = Boolean.parseBoolean(currentOrNull());
} else if (qName.equals("CustomizeSSH")) {
customizeSSH = Boolean.parseBoolean(currentOrNull());
String current = currentOrNull();
if (current != null) {
if (qName.equals("CustomizeNetwork")) {
customizeNetwork = Boolean.parseBoolean(current);
} else if (qName.equals("CustomizePassword")) {
customizePassword = Boolean.parseBoolean(current);
} else if (qName.equals("CustomizeSSH")) {
customizeSSH = Boolean.parseBoolean(current);
}
}
currentText = new StringBuilder();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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