Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,32 +260,27 @@ public OMNode lookup(String key) {
StAXOMBuilder builder = new StAXOMBuilder(parser);
result = builder.getDocumentElement();

} catch (OMException | XMLStreamException ignored) {

if (log.isDebugEnabled()) {
log.debug("The resource at the provided URL isn't well-formed XML,So,takes it as a text");
if (result != null && result.getParent() != null) {
result.detach();
OMDocumentImpl parent = new OMDocumentImpl(OMAbstractFactory.getOMFactory());
parent.addChild(result);
}

try {
inputStream.close();
} catch (IOException e) {
log.error("Error in closing the input stream. ", e);
}

try {
result = readNonXML(url);
} catch (IOException e) {
log.error("Error occurred while retrieving text content from registry artifact", e);
result = null;
} catch (OMException | XMLStreamException ignored) {
result = treatContentAsNonXmlOnXmlError(url);
Comment on lines +269 to +270
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 1

Suggested change
} catch (OMException | XMLStreamException ignored) {
result = treatContentAsNonXmlOnXmlError(url);
} catch (OMException | XMLStreamException ignored) {
log.warn("Failed to parse content as XML from URL: " + url.toString());
result = treatContentAsNonXmlOnXmlError(url);

} catch (RuntimeException runtimeException) {
// Woodstox Exception Handling:
// The WstxLazyException is often wrapped by internal layers and its ClassLoader
// is isolated from this component's ClassLoader. Here, we check the message
// to safely identify this specific, anticipated XML parsing failure.
if (runtimeException.getMessage() != null
&& runtimeException.getMessage().contains("com.ctc.wstx.exc.WstxLazyException")) {
result = treatContentAsNonXmlOnXmlError(url);
} else {
throw runtimeException;
Comment on lines +278 to +280
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Improvement Suggestion No: 2

Suggested change
result = treatContentAsNonXmlOnXmlError(url);
} else {
throw runtimeException;
result = treatContentAsNonXmlOnXmlError(url);
} else {
log.error("Unexpected runtime exception while parsing XML: " + runtimeException.getMessage());
throw runtimeException;

}

} finally {
try {
if (result != null && result.getParent() != null) {
result.detach();
OMDocumentImpl parent = new OMDocumentImpl(OMAbstractFactory.getOMFactory());
parent.addChild(result);
}
inputStream.close();
} catch (IOException e) {
log.error("Error in closing the input stream.", e);
Expand All @@ -295,6 +290,28 @@ public OMNode lookup(String key) {
return result;
}

private OMNode treatContentAsNonXmlOnXmlError(URL url) {
if (log.isDebugEnabled()) {
log.debug("The resource at the provided URL isn't well-formed XML. So, takes it as a text");
}

OMNode result;
try {
result = readNonXML(url);
} catch (IOException e) {
log.error("Error occurred while retrieving text content from registry artifact", e);
result = null;
}

if (result != null && result.getParent() != null) {
result.detach();
OMDocumentImpl parent = new OMDocumentImpl(OMAbstractFactory.getOMFactory());
parent.addChild(result);
}

return result;
}

private boolean lookupUtil(String key, URL url) {
if (url == null) {
handleException("Unable to create URL for target resource : " + key);
Expand Down
Loading