cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [22/36] cxf git commit: [CXF-7020]explicity create woodstox event factory as fallback if XMLEventFactory.newInstance fail
Date Thu, 25 Aug 2016 01:48:09 GMT
[CXF-7020]explicity create woodstox event factory as fallback if XMLEventFactory.newInstance
fail


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e9578859
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e9578859
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e9578859

Branch: refs/heads/master-jaxrs-2.1
Commit: e95788590cd036ecbda0283f493845feb5e11ba4
Parents: 39a5690
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Wed Aug 24 17:15:39 2016 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Wed Aug 24 17:15:39 2016 +0800

----------------------------------------------------------------------
 .../org/apache/cxf/staxutils/StaxUtils.java     |  6 +++++
 .../apache/cxf/staxutils/WoodstoxHelper.java    |  6 +++++
 .../interceptor/ReadHeadersInterceptor.java     | 25 +++++++++++++-------
 3 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e9578859/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
----------------------------------------------------------------------
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 0d2398d..4af5ddf 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
@@ -45,6 +45,7 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.Location;
 import javax.xml.stream.StreamFilter;
+import javax.xml.stream.XMLEventFactory;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLResolver;
@@ -352,6 +353,11 @@ public final class StaxUtils {
     private static XMLInputFactory createWoodstoxFactory() {
         return WoodstoxHelper.createInputFactory();
     }
+    
+    public static XMLEventFactory createWoodstoxEventFactory() {
+        return WoodstoxHelper.createEventFactory();
+    }
+    
     private static boolean setRestrictionProperties(XMLInputFactory factory) {
         //For now, we can only support Woodstox 4.2.x and newer as none of the other
         //stax parsers support these settings

http://git-wip-us.apache.org/repos/asf/cxf/blob/e9578859/core/src/main/java/org/apache/cxf/staxutils/WoodstoxHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/staxutils/WoodstoxHelper.java b/core/src/main/java/org/apache/cxf/staxutils/WoodstoxHelper.java
index 73f4852..8b901bc 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/WoodstoxHelper.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/WoodstoxHelper.java
@@ -19,9 +19,11 @@
 
 package org.apache.cxf.staxutils;
 
+import javax.xml.stream.XMLEventFactory;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
+import com.ctc.wstx.stax.WstxEventFactory;
 import com.ctc.wstx.stax.WstxInputFactory;
 import org.codehaus.stax2.XMLStreamReader2;
 
@@ -36,6 +38,10 @@ final class WoodstoxHelper {
     public static XMLInputFactory createInputFactory() {
         return new WstxInputFactory();
     }
+    
+    public static XMLEventFactory createEventFactory() {
+        return new WstxEventFactory();
+    }
 
     public static void setProperty(XMLStreamReader reader, String p, Object v) {
         ((XMLStreamReader2)reader).setProperty(p, v);

http://git-wip-us.apache.org/repos/asf/cxf/blob/e9578859/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
index 6bfa3a3..16e3310 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
@@ -318,7 +318,7 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
      * out while parsing the stream).
      */
     private static class HeadersProcessor {
-        private static final XMLEventFactory FACTORY = XMLEventFactory.newInstance();
+        private static XMLEventFactory eventFactory;
         private final String ns;
         private final String header;
         private final String body;
@@ -332,6 +332,15 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
         private QName lastStartElementQName;
         private String envelopePrefix;
         private String bodyPrefix;
+        
+        static {
+            try {
+                eventFactory = XMLEventFactory.newInstance();
+            } catch (Throwable t) {
+                //explicity create woodstox event factory as last try
+                eventFactory = StaxUtils.createWoodstoxEventFactory();
+            }
+        }
 
         HeadersProcessor(SoapVersion version) {
             this.header = version.getHeader().getLocalPart();
@@ -348,14 +357,14 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor
{
                 switch (event) {
                 case XMLStreamConstants.START_ELEMENT:
                     read++;
-                    addEvent(FACTORY.createStartElement(new QName(reader.getNamespaceURI(),
reader
+                    addEvent(eventFactory.createStartElement(new QName(reader.getNamespaceURI(),
reader
                                                             .getLocalName(), reader.getPrefix()),
null, null));
                     for (int i = 0; i < reader.getNamespaceCount(); i++) {
-                        addEvent(FACTORY.createNamespace(reader.getNamespacePrefix(i),
+                        addEvent(eventFactory.createNamespace(reader.getNamespacePrefix(i),
                                                          reader.getNamespaceURI(i)));
                     }
                     for (int i = 0; i < reader.getAttributeCount(); i++) {
-                        addEvent(FACTORY.createAttribute(reader.getAttributePrefix(i),
+                        addEvent(eventFactory.createAttribute(reader.getAttributePrefix(i),
                                                          reader.getAttributeNamespace(i),
                                                          reader.getAttributeLocalName(i),
                                                          reader.getAttributeValue(i)));
@@ -367,7 +376,7 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                     break;
                 case XMLStreamConstants.END_ELEMENT:
                     if (read > 0) {
-                        addEvent(FACTORY.createEndElement(new QName(reader.getNamespaceURI(),
reader
+                        addEvent(eventFactory.createEndElement(new QName(reader.getNamespaceURI(),
reader
                                                               .getLocalName(), reader.getPrefix()),
null));
                     }
                     read--;
@@ -375,14 +384,14 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor
{
                 case XMLStreamConstants.CHARACTERS:
                     String s = reader.getText();
                     if (s != null) {
-                        addEvent(FACTORY.createCharacters(s));
+                        addEvent(eventFactory.createCharacters(s));
                     }
                     break;
                 case XMLStreamConstants.COMMENT:
-                    addEvent(FACTORY.createComment(reader.getText()));
+                    addEvent(eventFactory.createComment(reader.getText()));
                     break;
                 case XMLStreamConstants.CDATA:
-                    addEvent(FACTORY.createCData(reader.getText()));
+                    addEvent(eventFactory.createCData(reader.getText()));
                     break;
                 case XMLStreamConstants.START_DOCUMENT:
                 case XMLStreamConstants.END_DOCUMENT:


Mime
View raw message