Skip to content

Commit

Permalink
Fix XML Namespace Handling in serializeExceptionToXml
Browse files Browse the repository at this point in the history
In the commit 1b59089,
we inadvertently introduced an issue in the
serializeExceptionToXml method where the XML namespace was
set in a manner not compliant with XML standards,
causing issues in XML parsing.
Additionally, the method did not utilize the currentDatabindContext
for writing the error-path, which could lead to incorrect
serialization of error paths in certain contexts.

The fix involves correctly setting the default XML namespace for
the errors element. Additionally, the method now properly utilizes
the currentDatabindContext for encoding error paths.

JIRA: NETCONF-1130
Change-Id: Ia7900bff2e63d23213896b5e0c96a514ace92873
Signed-off-by: Yaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
  • Loading branch information
YaroslavLa committed Jan 16, 2024
1 parent 25716d2 commit b9a3d71
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ private static String serializeExceptionToXml(final RestconfDocumentedException
try (var outputStream = new ByteArrayOutputStream()) {
final var xmlWriter = XML_OUTPUT_FACTORY.createXMLStreamWriter(outputStream,
StandardCharsets.UTF_8.name());
final var currentDatabindContext = exception.modelContext() != null
? DatabindContext.ofModel(exception.modelContext()) : databindProvider.currentDatabind();
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement(Errors.QNAME.getLocalName());
xmlWriter.writeNamespace("xmlns", Errors.QNAME.getNamespace().toString());
xmlWriter.writeDefaultNamespace(Errors.QNAME.getNamespace().toString());
if (exception.getErrors() != null && !exception.getErrors().isEmpty()) {
for (final var error : exception.getErrors()) {
xmlWriter.writeStartElement(Error.QNAME.getLocalName());
Expand All @@ -202,7 +204,7 @@ private static String serializeExceptionToXml(final RestconfDocumentedException

if (error.getErrorPath() != null) {
xmlWriter.writeStartElement(ERROR_PATH_QNAME.getLocalName());
databindProvider.currentDatabind().xmlCodecs().instanceIdentifierCodec()
currentDatabindContext.xmlCodecs().instanceIdentifierCodec()
.writeValue(xmlWriter, error.getErrorPath());
xmlWriter.writeEndElement();
}
Expand Down

0 comments on commit b9a3d71

Please sign in to comment.