You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/11/21 11:26:00 UTC
[cxf] 01/01: Stop using static factories in StaxUtils
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch staxutils_static
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 7acbf78775b8e50c03b7d82dd0fb232556175349
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Nov 21 11:25:30 2018 +0000
Stop using static factories in StaxUtils
---
.../java/org/apache/cxf/staxutils/StaxUtils.java | 50 +++-------------------
1 file changed, 5 insertions(+), 45 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java b/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
index b56e789..86c40c3 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
@@ -125,9 +125,7 @@ public final class StaxUtils {
private static final Logger LOG = LogUtils.getL7dLogger(StaxUtils.class);
private static final BlockingQueue<XMLInputFactory> NS_AWARE_INPUT_FACTORY_POOL;
- private static final XMLInputFactory SAFE_INPUT_FACTORY;
private static final BlockingQueue<XMLOutputFactory> OUTPUT_FACTORY_POOL;
- private static final XMLOutputFactory SAFE_OUTPUT_FACTORY;
private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
private static final String[] DEF_PREFIXES = new String[] {
@@ -170,34 +168,6 @@ public final class StaxUtils {
if (!StringUtils.isEmpty(s)) {
allowInsecureParser = "1".equals(s) || Boolean.parseBoolean(s);
}
-
- XMLInputFactory xif = null;
- try {
- xif = createXMLInputFactory(true);
- String xifClassName = xif.getClass().getName();
- if (!xifClassName.contains("ctc.wstx") && !xifClassName.contains("xml.xlxp")
- && !xifClassName.contains("xml.xlxp2") && !xifClassName.contains("bea.core")) {
- xif = null;
- }
- } catch (Throwable t) {
- //ignore, can always drop down to the pooled factories
- xif = null;
- }
- SAFE_INPUT_FACTORY = xif;
-
- XMLOutputFactory xof = null;
- try {
- xof = XMLOutputFactory.newInstance();
- String xofClassName = xof.getClass().getName();
- if (!xofClassName.contains("ctc.wstx") && !xofClassName.contains("xml.xlxp")
- && !xofClassName.contains("xml.xlxp2") && !xofClassName.contains("bea.core")) {
- xof = null;
- }
- } catch (Throwable t) {
- //ignore, can always drop down to the pooled factories
- }
- SAFE_OUTPUT_FACTORY = xof;
-
}
private StaxUtils() {
@@ -240,14 +210,12 @@ public final class StaxUtils {
i = 500;
}
innerElementLevelThreshold = i;
- setProperty(SAFE_INPUT_FACTORY, "com.ctc.wstx.maxElementDepth", i);
}
public static void setInnerElementCountThreshold(int i) {
if (i == -1) {
i = 50000;
}
innerElementCountThreshold = i;
- setProperty(SAFE_INPUT_FACTORY, "com.ctc.wstx.maxChildrenPerElement", i);
}
/**
@@ -270,26 +238,20 @@ public final class StaxUtils {
* Return a cached, namespace-aware, factory.
*/
private static XMLInputFactory getXMLInputFactory() {
- if (SAFE_INPUT_FACTORY != null) {
- return SAFE_INPUT_FACTORY;
- }
XMLInputFactory f = NS_AWARE_INPUT_FACTORY_POOL.poll();
if (f == null) {
f = createXMLInputFactory(true);
+ } else {
+ setRestrictionProperties(f);
}
return f;
}
private static void returnXMLInputFactory(XMLInputFactory factory) {
- if (SAFE_INPUT_FACTORY != factory) {
- NS_AWARE_INPUT_FACTORY_POOL.offer(factory);
- }
+ NS_AWARE_INPUT_FACTORY_POOL.offer(factory);
}
private static XMLOutputFactory getXMLOutputFactory() {
- if (SAFE_OUTPUT_FACTORY != null) {
- return SAFE_OUTPUT_FACTORY;
- }
XMLOutputFactory f = OUTPUT_FACTORY_POOL.poll();
if (f == null) {
f = XMLOutputFactory.newInstance();
@@ -298,9 +260,7 @@ public final class StaxUtils {
}
private static void returnXMLOutputFactory(XMLOutputFactory factory) {
- if (SAFE_OUTPUT_FACTORY != factory) {
- OUTPUT_FACTORY_POOL.offer(factory);
- }
+ OUTPUT_FACTORY_POOL.offer(factory);
}
/**
@@ -712,7 +672,7 @@ public final class StaxUtils {
/**
* Copies the reader to the writer. The start and end document methods must
- * be handled on the writer manually.
+ * be handled on the writer manually.
*
* @param reader
* @param writer