workaround eucalyptus problem

This commit is contained in:
Adrian Cole 2010-09-13 20:53:18 -07:00
parent 754a511ec2
commit b1da61fa03
3 changed files with 26 additions and 12 deletions

View File

@ -33,8 +33,7 @@ import com.google.common.collect.Maps;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class DescribeRegionsResponseHandler extends public class DescribeRegionsResponseHandler extends ParseSax.HandlerWithResult<Map<String, URI>> {
ParseSax.HandlerWithResult<Map<String, URI>> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private Map<String, URI> regionEndpoints = Maps.newHashMap(); private Map<String, URI> regionEndpoints = Maps.newHashMap();
@ -52,11 +51,11 @@ public class DescribeRegionsResponseHandler extends
String pending = currentText.toString().trim(); String pending = currentText.toString().trim();
if (pending.indexOf("Walrus") == -1) if (pending.indexOf("Walrus") == -1)
region = pending; region = pending;
} else if (qName.equals("regionEndpoint")) { // Eucalyptus uses regionUrl
} else if (qName.equals("regionEndpoint") || qName.equals("regionUrl")) {
String pending = currentText.toString().trim(); String pending = currentText.toString().trim();
if (pending.indexOf("Walrus") == -1) if (pending.indexOf("Walrus") == -1)
regionEndpoint = URI.create(pending.startsWith("http") ? pending regionEndpoint = URI.create(pending.startsWith("http") ? pending : String.format("https://%s", pending));
: String.format("https://%s", pending));
} else if (qName.equals("item") && region != null) { } else if (qName.equals("item") && region != null) {
regionEndpoints.put(region, regionEndpoint); regionEndpoints.put(region, regionEndpoint);
this.region = null; this.region = null;

View File

@ -96,6 +96,21 @@ public class DescribeRegionsResponseHandlerTest extends BaseHandlerTest {
assertEquals(result, expected); assertEquals(result, expected);
} }
public void testEuc2() {
InputStream is = Utils
.toInputStream("<?xml version=\"1.0\" ?><DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-11-30/\"><requestId>1LAQRTCLTLPS6CEIC627</requestId><regionInfo><item><regionUrl>http://10.255.255.1:8773/services/Cloud</regionUrl><regionName>nova</regionName></item></regionInfo></DescribeRegionsResponse>");
Map<String, URI> expected = ImmutableMap.<String, URI> of("nova",
URI.create("http://10.255.255.1:8773/services/Cloud"));
Map<String, URI> result = factory.create(
injector.getInstance(DescribeRegionsResponseHandler.class)).parse(
is);
assertEquals(result, expected);
}
public void testUnsupportedAdditionalRegionDoesntBreak() { public void testUnsupportedAdditionalRegionDoesntBreak() {
InputStream is = getClass().getResourceAsStream( InputStream is = getClass().getResourceAsStream(