Skip to content

Commit 6839697

Browse files
[CSAPI] Fix exception after parsing procedure XML
When parsing the XML for a (new) procedure, BaseResourceHandler.create() calls SmlProcessBindingSmlXml.deserialize() repeatedly until there is no more data to be parsed. However, the code that decides there is no more data did not actually work. After parsing the last object, the parser would still point at the last closing tag, so hasNext() would return true. However, the only event that then is still available is END_OF_DOCUMENT, which is not enough for nextTag(), which then throws. In practice, this meant that an object to be added would be added as expected but then an exception was raised. Note that this has not been tested with actually adding more than one object, since I could not figure out how to format multiple objects in a way they would be accepted at all (simply concatenating them produces "Illegal to have multiple roots"). This fixes #251
1 parent 5a70843 commit 6839697

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

sensorhub-service-consys/src/main/java/org/sensorhub/impl/service/consys/sensorml/SmlProcessBindingSmlXml.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,25 @@ public V deserialize() throws IOException
7474
if (!xmlReader.hasNext())
7575
return null;
7676

77-
xmlReader.nextTag();
77+
try
78+
{
79+
xmlReader.nextTag();
80+
}
81+
catch (XMLStreamException e)
82+
{
83+
// If the xmlReader is not advanced to END_OF_DOCUMENT
84+
// before calling nextTag(), hasNext() above will still
85+
// return true and nextTag() will fail. The best
86+
// heuristic of this situation we have is to catch the
87+
// exception and call hasNext. If so, that just means
88+
// there was nothing (except maybe whitespace and
89+
// comments) after the previous document, and that is
90+
// not an exception.
91+
if (!xmlReader.hasNext())
92+
return null;
93+
94+
throw e;
95+
}
7896
var sml = smlBindings.readDescribedObject(xmlReader);
7997

8098
if (sml instanceof Deployment)

0 commit comments

Comments
 (0)