From commits-return-49330-archive-asf-public=cust-asf.ponee.io@cxf.apache.org Mon Jun 11 11:20:49 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id B0F0E18077A for ; Mon, 11 Jun 2018 11:20:48 +0200 (CEST) Received: (qmail 50380 invoked by uid 500); 11 Jun 2018 09:20:47 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 50249 invoked by uid 99); 11 Jun 2018 09:20:47 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jun 2018 09:20:47 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 20861827CD; Mon, 11 Jun 2018 09:20:47 +0000 (UTC) Date: Mon, 11 Jun 2018 09:20:48 +0000 To: "commits@cxf.apache.org" Subject: [cxf-fediz] 01/02: Revert "Switching static DocumentBuilderFactory to use a ThreadLocal instead" MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: coheigea@apache.org In-Reply-To: <152870884705.2226.4208104564700802316@gitbox.apache.org> References: <152870884705.2226.4208104564700802316@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: cxf-fediz X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: cc5b810b99904220c752a1935d3bf62ee5925ef2 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180611092047.20861827CD@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git commit cc5b810b99904220c752a1935d3bf62ee5925ef2 Author: Colm O hEigeartaigh AuthorDate: Mon Jun 11 09:57:13 2018 +0100 Revert "Switching static DocumentBuilderFactory to use a ThreadLocal instead" This reverts commit 62b61ec06bd5199a2e2712261199e513fd8db52a. --- .../org/apache/cxf/fediz/core/util/DOMUtils.java | 60 ++++++++++++---------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java index fc43aef..9c533fc 100644 --- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java +++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java @@ -65,7 +65,23 @@ public final class DOMUtils { private static final String XMLNAMESPACE = "xmlns"; - private static final ThreadLocal DOC_BUILDER_TL = new MyThreadLocal(); + private static final DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance(); + + static { + try { + DBF.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + DBF.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + + DBF.setValidating(false); + DBF.setIgnoringComments(false); + DBF.setIgnoringElementContentWhitespace(true); + DBF.setNamespaceAware(true); + // DBF.setCoalescing(true); + // DBF.setExpandEntityReferences(true); + } catch (ParserConfigurationException ex) { + LOG.error("Error configuring DocumentBuilderFactory", ex); + } + } private DOMUtils() { } @@ -412,12 +428,14 @@ public final class DOMUtils { */ public static Document readXml(InputStream is) throws SAXException, IOException, ParserConfigurationException { - return createDocumentBuilder().parse(is); + DocumentBuilder db = DBF.newDocumentBuilder(); + return db.parse(is); } public static Document readXml(Reader is) throws SAXException, IOException, ParserConfigurationException { InputSource ips = new InputSource(is); - return createDocumentBuilder().parse(ips); + DocumentBuilder db = DBF.newDocumentBuilder(); + return db.parse(ips); } public static Document readXml(StreamSource is) throws SAXException, IOException, @@ -427,7 +445,8 @@ public final class DOMUtils { is2.setByteStream(is.getInputStream()); is2.setCharacterStream(is.getReader()); - return createDocumentBuilder().parse(is2); + DocumentBuilder db = DBF.newDocumentBuilder(); + return db.parse(is2); } public static void writeXml(Node n, OutputStream os) throws TransformerException { @@ -440,13 +459,19 @@ public final class DOMUtils { } public static DocumentBuilder createDocumentBuilder() { - DocumentBuilder documentBuilder = DOC_BUILDER_TL.get(); - documentBuilder.reset(); - return documentBuilder; + try { + return DBF.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RuntimeException("Couldn't find a DOM parser.", e); + } } public static Document createDocument() { - return createDocumentBuilder().newDocument(); + try { + return DBF.newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + throw new RuntimeException("Couldn't find a DOM parser.", e); + } } public static String getPrefixRecursive(Element el, String ns) { @@ -633,23 +658,4 @@ public final class DOMUtils { public static void addNamespacePrefix(Element element, String namespaceUri, String prefix) { element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespaceUri); } - - private static final class MyThreadLocal extends ThreadLocal { - - @Override - protected DocumentBuilder initialValue() { - try { - DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); - dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); - dfactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); - dfactory.setValidating(false); - dfactory.setNamespaceAware(true); - - return dfactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - LOG.error("Error configuring DocumentBuilderFactory", e); - throw new RuntimeException(e); - } - } - } } -- To stop receiving notification emails like this one, please contact coheigea@apache.org.