cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r777189 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/staxutils/ rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/ rt/core/src/main/java/or...
Date Thu, 21 May 2009 17:29:02 GMT
Author: dkulp
Date: Thu May 21 17:28:57 2009
New Revision: 777189

URL: http://svn.apache.org/viewvc?rev=777189&view=rev
Log:
Add sync blocks when using the XMLInput/OutputFactories since the Sun
stax parsers aren't thread safe.

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
    cxf/trunk/rt/databinding/aegis/src/main/generated/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Thu May
21 17:28:57 2009
@@ -147,7 +147,10 @@
 
     public static XMLStreamWriter createXMLStreamWriter(Writer out) {
         try {
-            return getXMLOutputFactory().createXMLStreamWriter(out);
+            XMLOutputFactory factory = getXMLOutputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamWriter(out);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Cant' create XMLStreamWriter", e);
         }
@@ -163,7 +166,10 @@
         }
 
         try {
-            return getXMLOutputFactory().createXMLStreamWriter(out, encoding);
+            XMLOutputFactory factory = getXMLOutputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamWriter(out, encoding);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Cant' create XMLStreamWriter", e);
         }
@@ -171,7 +177,10 @@
     
     public static XMLStreamWriter createXMLStreamWriter(Result r) {
         try {
-            return getXMLOutputFactory().createXMLStreamWriter(r);
+            XMLOutputFactory factory = getXMLOutputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamWriter(r);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Cant' create XMLStreamWriter", e);
         }
@@ -179,7 +188,10 @@
 
     public static XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter
filter) {
         try {
-            return getXMLInputFactory().createFilteredReader(reader, filter);
+            XMLInputFactory factory = getXMLInputFactory();
+            synchronized (factory) {
+                return factory.createFilteredReader(reader, filter);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Cant' create XMLStreamReader", e);
         }
@@ -846,7 +858,10 @@
         }
 
         try {
-            return getXMLInputFactory().createXMLStreamReader(in, encoding);
+            XMLInputFactory factory = getXMLInputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamReader(in, encoding);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Couldn't parse stream.", e);
         }
@@ -858,14 +873,20 @@
      */
     public static XMLStreamReader createXMLStreamReader(InputStream in) {
         try {
-            return getXMLInputFactory().createXMLStreamReader(in);
+            XMLInputFactory factory = getXMLInputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamReader(in);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Couldn't parse stream.", e);
         }
     }
     public static XMLStreamReader createXMLStreamReader(String systemId, InputStream in)
{
         try {
-            return getXMLInputFactory().createXMLStreamReader(systemId, in);
+            XMLInputFactory factory = getXMLInputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamReader(systemId, in);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Couldn't parse stream.", e);
         }
@@ -893,8 +914,10 @@
                     return new W3CDOMStreamReader(el);
                 }
             }
-            
-            return getXMLInputFactory().createXMLStreamReader(source);
+            XMLInputFactory factory = getXMLInputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamReader(source);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Couldn't parse stream.", e);
         }
@@ -907,7 +930,10 @@
     public static XMLStreamReader createXMLStreamReader(Reader reader) {
 
         try {
-            return getXMLInputFactory().createXMLStreamReader(reader);
+            XMLInputFactory factory = getXMLInputFactory();
+            synchronized (factory) {
+                return factory.createXMLStreamReader(reader);
+            }
         } catch (XMLStreamException e) {
             throw new RuntimeException("Couldn't parse stream.", e);
         }

Modified: cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
Thu May 21 17:28:57 2009
@@ -113,8 +113,10 @@
         if ("POST".equals(method) || "PUT".equals(method)) {
             XMLInputFactory inputFactory = StaxInInterceptor.getXMLInputFactory(message);
             try {
-                XMLStreamReader reader = 
-                    inputFactory.createXMLStreamReader(message.getContent(InputStream.class));
+                XMLStreamReader reader;
+                synchronized (inputFactory) {
+                    reader = inputFactory.createXMLStreamReader(message.getContent(InputStream.class));
+                }
                 doc = StaxUtils.read(reader);
             } catch (XMLStreamException e) {
                 throw new Fault(e);

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
Thu May 21 17:28:57 2009
@@ -129,21 +129,16 @@
         } else if (!message.containsKey(ORIGINAL_XML_WRITER)) {
             //as the SOAPMessage already has everything in place, we do not need XMLStreamWriter
to write
             //anything for us, so we just set XMLStreamWriter's output to a dummy output
stream.         
-            try {
-                XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
-                message.put(ORIGINAL_XML_WRITER, origWriter);
-                
-                XMLStreamWriter dummyWriter = StaxUtils.getXMLOutputFactory()
-                    .createXMLStreamWriter(new OutputStream() {
-                        public void write(int b) throws IOException {
-                        }
-                        public void write(byte b[], int off, int len) throws IOException
{
-                        }                        
-                    });
-                message.setContent(XMLStreamWriter.class, dummyWriter);
-            } catch (XMLStreamException e) {
-                // do nothing
-            }   
+            XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
+            message.put(ORIGINAL_XML_WRITER, origWriter);
+            
+            XMLStreamWriter dummyWriter = StaxUtils.createXMLStreamWriter(new OutputStream()
{
+                    public void write(int b) throws IOException {
+                    }
+                    public void write(byte b[], int off, int len) throws IOException {
+                    }                        
+                });
+            message.setContent(XMLStreamWriter.class, dummyWriter);
         }
         
         // Add a final interceptor to write the message

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java Thu
May 21 17:28:57 2009
@@ -78,7 +78,10 @@
 
         XMLStreamReader reader;
         try {
-            reader = getXMLInputFactory(message).createXMLStreamReader(is, encoding);
+            XMLInputFactory factory = getXMLInputFactory(message);
+            synchronized (factory) {
+                reader = factory.createXMLStreamReader(is, encoding);
+            }
         } catch (XMLStreamException e) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC",
                                                                    LOG,

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java Thu
May 21 17:28:57 2009
@@ -64,7 +64,10 @@
         String encoding = getEncoding(message);
         
         try {
-            writer = getXMLOutputFactory(message).createXMLStreamWriter(os, encoding);
+            XMLOutputFactory factory = getXMLOutputFactory(message);
+            synchronized (factory) {
+                writer = factory.createXMLStreamWriter(os, encoding);
+            }
             if (Boolean.TRUE.equals(message.getContextualProperty(FORCE_START_DOCUMENT)))
{
                 writer.writeStartDocument(encoding, "1.0");
                 message.removeContent(OutputStream.class);

Modified: cxf/trunk/rt/databinding/aegis/src/main/generated/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/generated/org/apache/cxf/aegis/util/jdom/StaxBuilder.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/generated/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/generated/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
Thu May 21 17:28:57 2009
@@ -60,7 +60,6 @@
 import java.util.Iterator;
 import java.util.Map;
 
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -124,7 +123,6 @@
     /** The factory for creating new JDOM objects */
     private JDOMFactory factory;
 
-    private XMLInputFactory xifactory;
 
     private Map additionalNamespaces;
     // This is set to 'true' when we are reading the middle of a stream,
@@ -135,17 +133,12 @@
      * Default constructor.
      */
     public StaxBuilder() {
-        xifactory = StaxUtils.getXMLInputFactory();
     }
 
     public StaxBuilder(Map namespaces) {
-        xifactory = StaxUtils.getXMLInputFactory();
         this.additionalNamespaces = namespaces;
     }
 
-    public StaxBuilder(XMLInputFactory xifactory) {
-        this.xifactory = xifactory;
-    }
 
     public Map getAdditionalNamespaces() {
         return additionalNamespaces;
@@ -193,12 +186,12 @@
 
     public Document build(InputStream is) throws XMLStreamException {
         isReadingMidStream = false;
-        return buildInternal(xifactory.createXMLStreamReader(is));
+        return buildInternal(StaxUtils.createXMLStreamReader(is));
     }
 
     public Document build(Reader reader) throws XMLStreamException {
         isReadingMidStream = false;
-        return buildInternal(xifactory.createXMLStreamReader(reader));
+        return buildInternal(StaxUtils.createXMLStreamReader(reader));
     }
     
     private Document buildInternal(XMLStreamReader r) throws XMLStreamException {

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java?rev=777189&r1=777188&r2=777189&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
Thu May 21 17:28:57 2009
@@ -25,6 +25,7 @@
 
 
 
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.endpoint.Endpoint;
@@ -62,8 +63,10 @@
             String encoding = (String)message.get(Message.ENCODING);
 
             XMLStreamReader xsr;
-            xsr = StaxInInterceptor.getXMLInputFactory(message).
-                createXMLStreamReader(bos.getInputStream(), encoding);
+            XMLInputFactory factory = StaxInInterceptor.getXMLInputFactory(message);
+            synchronized (factory) {
+                xsr = factory.createXMLStreamReader(bos.getInputStream(), encoding);
+            }
             
             // move to the soap body            
             while (true) {                



Mime
View raw message