DescribeSnapshotsResponseHandler bug parsing tags

DescribeSnapshotsResponseHandler behaved incorrectly when a snapshot had
metadata tags added - it would stop parsing and start the next Snapshot
object every time it saw an </item> tag. Since metadata tags contain
</item>, each tag would cause a new Snapshot object in the response
containing all nulls. Fixed by counting the tag nesting depth and only
responding to </item> at the correct nesting level.
This commit is contained in:
Richard Downer 2012-07-25 16:20:12 +01:00
parent 17172a7d17
commit 6c86b89d83
2 changed files with 11 additions and 1 deletions

View File

@ -37,6 +37,7 @@ public class DescribeSnapshotsResponseHandler extends ParseSax.HandlerWithResult
private Set<Snapshot> snapshots = Sets.newLinkedHashSet();
private final SnapshotHandler snapshotHandler;
private int itemDepth = 0;
@Inject
public DescribeSnapshotsResponseHandler(SnapshotHandler snapshotHandler) {
@ -50,13 +51,16 @@ public class DescribeSnapshotsResponseHandler extends ParseSax.HandlerWithResult
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
itemDepth++;
snapshotHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
snapshotHandler.endElement(uri, localName, qName);
if (qName.equals("item")) {
itemDepth--;
if (qName.equals("item") && itemDepth == 2) {
this.snapshots.add(snapshotHandler.getResult());
}
}

View File

@ -9,6 +9,12 @@
<ownerId>218213537122</ownerId>
<volumeSize>10</volumeSize>
<description>Daily Backup</description>
<tagSet>
<item>
<key>Name</key>
<value>example_name_tag</value>
</item>
</tagSet>
</item>
</snapshotSet>
</DescribeSnapshotsResponse>