You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2019/09/30 15:37:38 UTC
[cxf] 01/02: CXF-8125: support for thread-safe application-defined
StAX factories
This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit b6fd6f7d96ce178030b3537165c9b779ce2d927c
Author: Barnabas Bodnar <ba...@ser.de>
AuthorDate: Sun Sep 29 00:31:38 2019 +0200
CXF-8125: support for thread-safe application-defined StAX factories
(cherry picked from commit e41775274815d4080166548172023aaabf72f8e3)
---
.../java/org/apache/cxf/interceptor/StaxInInterceptor.java | 11 ++++++++++-
.../java/org/apache/cxf/interceptor/StaxOutInterceptor.java | 12 +++++++++++-
core/src/main/java/org/apache/cxf/message/Message.java | 6 ++++++
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
index 3465f15..3dadf07 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
@@ -34,6 +34,7 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PropertyUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.HttpHeaderHelper;
@@ -127,12 +128,20 @@ public class StaxInInterceptor extends AbstractPhaseInterceptor<Message> {
xreader = StaxUtils.createXMLStreamReader(is, encoding);
}
} else {
- synchronized (factory) {
+ if (PropertyUtils.isTrue(message.getContextualProperty(Message.THREAD_SAFE_STAX_FACTORIES))) {
if (reader != null) {
xreader = factory.createXMLStreamReader(reader);
} else {
xreader = factory.createXMLStreamReader(is, encoding);
}
+ } else {
+ synchronized (factory) {
+ if (reader != null) {
+ xreader = factory.createXMLStreamReader(reader);
+ } else {
+ xreader = factory.createXMLStreamReader(is, encoding);
+ }
+ }
}
}
xreader = StaxUtils.configureReader(xreader, message);
diff --git a/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
index 3f03845..086b92b 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
@@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.util.PropertyUtils;
import org.apache.cxf.io.AbstractWrappedOutputStream;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
@@ -84,13 +85,22 @@ public class StaxOutInterceptor extends AbstractPhaseInterceptor<Message> {
xwriter = StaxUtils.createXMLStreamWriter(writer);
}
} else {
- synchronized (factory) {
+ if (PropertyUtils.isTrue(message.getContextualProperty(Message.THREAD_SAFE_STAX_FACTORIES))) {
if (writer == null) {
os = setupOutputStream(os);
xwriter = factory.createXMLStreamWriter(os, encoding);
} else {
xwriter = factory.createXMLStreamWriter(writer);
}
+ } else {
+ synchronized (factory) {
+ if (writer == null) {
+ os = setupOutputStream(os);
+ xwriter = factory.createXMLStreamWriter(os, encoding);
+ } else {
+ xwriter = factory.createXMLStreamWriter(writer);
+ }
+ }
}
}
if (MessageUtils.getContextualBoolean(message, FORCE_START_DOCUMENT, false)) {
diff --git a/core/src/main/java/org/apache/cxf/message/Message.java b/core/src/main/java/org/apache/cxf/message/Message.java
index ed7be5b..aa4dbe3 100644
--- a/core/src/main/java/org/apache/cxf/message/Message.java
+++ b/core/src/main/java/org/apache/cxf/message/Message.java
@@ -183,6 +183,12 @@ public interface Message extends StringMap {
String CONNECTION_TIMEOUT = "javax.xml.ws.client.connectionTimeout";
String RECEIVE_TIMEOUT = "javax.xml.ws.client.receiveTimeout";
+ /**
+ * Boolean property to indicate whether application-defined StAX-factories (stored as contextual property in the
+ * message) are thread-safe. If set to {@code true}, CXF doesn't synchronize accesses to the factories.
+ */
+ String THREAD_SAFE_STAX_FACTORIES = Message.class.getName() + ".THREAD_SAFE_STAX_FACTORIES";
+
String getId();
void setId(String id);