Skip to content

Commit

Permalink
KEYCLOAK-14952 - Unit test failure in keycloak-saml-core on Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
dteleguin authored and hmlnarik committed Sep 14, 2020
1 parent 3186f1b commit b62d68a
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
Expand Down Expand Up @@ -304,6 +305,18 @@ public static InputStream getSourceAsStream(Source source) throws ConfigurationE
Result streamResult = new StreamResult(baos);
// Write the DOM document to the stream
Transformer transformer = TransformerUtil.getTransformer();

if (DOMSource.class.isInstance(source)) {
Node node = ((DOMSource) source).getNode();
if (Document.class.isInstance(node)) {
String xmlEncoding = ((Document) node).getXmlEncoding();
if (xmlEncoding != null) {
transformer.setOutputProperty(OutputKeys.ENCODING, xmlEncoding);
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
}
}
}

try {
transformer.transform(source, streamResult);
} catch (TransformerException e) {
Expand Down

0 comments on commit b62d68a

Please sign in to comment.