From b62d68a591e2d61e21291fd2d1905cbddb45f583 Mon Sep 17 00:00:00 2001 From: Dmitry Telegin Date: Thu, 10 Sep 2020 17:19:24 +0300 Subject: [PATCH] KEYCLOAK-14952 - Unit test failure in keycloak-saml-core on Java 11 --- .../org/keycloak/saml/common/util/DocumentUtil.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/saml-core/src/main/java/org/keycloak/saml/common/util/DocumentUtil.java b/saml-core/src/main/java/org/keycloak/saml/common/util/DocumentUtil.java index 952be764de..6b4cc5fee7 100755 --- a/saml-core/src/main/java/org/keycloak/saml/common/util/DocumentUtil.java +++ b/saml-core/src/main/java/org/keycloak/saml/common/util/DocumentUtil.java @@ -34,6 +34,7 @@ import javax.xml.namespace.QName; 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; @@ -304,6 +305,18 @@ public class DocumentUtil { 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) {