cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r964854 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/wsdl/ common/common/src/main/java/org/apache/cxf/staxutils/ integration/jbi/src/main/java/org/apache/cxf/jbi/se/ rt/bindings/soap/src/main/java/org/apache/cxf/bindi...
Date Fri, 16 Jul 2010 16:42:28 GMT
Author: dkulp
Date: Fri Jul 16 16:42:27 2010
New Revision: 964854

URL: http://svn.apache.org/viewvc?rev=964854&view=rev
Log:
Merged revisions 964853 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r964853 | dkulp | 2010-07-16 12:40:05 -0400 (Fri, 16 Jul 2010) | 3 lines
  
  Change as much XML parsing/processing to go through StaxUtils as is
  possible to make updating anything related to XML processing easier
  since it would all be in one place.
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/branches/2.2.x-fixes/integration/jbi/src/main/java/org/apache/cxf/jbi/se/CXFServiceUnit.java
    cxf/branches/2.2.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
    cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java
    cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIMessageHelper.java
    cxf/branches/2.2.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/SoapFaultFactory.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 16 16:42:27 2010
@@ -1 +1 @@
-/cxf/trunk:964618,964818,964822
+/cxf/trunk:964618,964818,964822,964853

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Fri Jul 16 16:42:27 2010
@@ -46,12 +46,9 @@ import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamSource;
@@ -266,25 +263,6 @@ public final class EndpointReferenceUtil
         // Utility class - never constructed
     }
     
-    private static Transformer getTransformer() throws EndpointUtilsException {
-        //To Support IBM JDK 
-        //If use the default transformFactory ,org.apache.xalan.processor.TransformerFactoryImpl
\
-        //when transform stuff will lost attributes 
-        if (System.getProperty("java.vendor").indexOf("IBM") > -1) {
-            System.setProperty("javax.xml.transform.TransformerFactory", 
-                               "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
-        }
-        
-        try {
-            return TransformerFactory.newInstance().newTransformer();
-        } catch (TransformerConfigurationException tce) {
-            throw new EndpointUtilsException(new Message("COULD_NOT_CREATE_TRANSFORMER",
LOG),
-                                                         tce);
-        }
-        
-    }
-    
-    
     /**
      * Sets the service and port name of the provided endpoint reference. 
      * @param ref the endpoint reference.
@@ -586,8 +564,7 @@ public final class EndpointReferenceUtil
                     if (doTransform) {
                         DOMResult domResult = new DOMResult();
                         domResult.setSystemId(source.getSystemId());
-                        
-                        getTransformer().transform(source, domResult);
+                        node = StaxUtils.read(source);
     
                         node = domResult.getNode();
                     }
@@ -609,7 +586,7 @@ public final class EndpointReferenceUtil
                         anyList.add(node);
                     }
                 }
-            } catch (TransformerException te) {
+            } catch (XMLStreamException te) {
                 throw new EndpointUtilsException(new Message("COULD_NOT_POPULATE_EPR", LOG),
                                                  te);
             }

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Fri Jul 16 16:42:27 2010
@@ -360,6 +360,18 @@ public final class StaxUtils {
         }
         return false;
     }
+    public static void copy(Source source, OutputStream os) throws XMLStreamException {
+        XMLStreamWriter writer = createXMLStreamWriter(os);
+        try {
+            copy(source, writer);
+        } finally {
+            try {
+                writer.flush();
+            } catch (XMLStreamException ex) {
+                //ignore
+            }
+        }
+    }
     public static void copy(Source source, XMLStreamWriter writer) throws XMLStreamException
{
         if (source instanceof SAXSource) {
             SAXSource ss = (SAXSource)source;
@@ -783,6 +795,42 @@ public final class StaxUtils {
         }        
     }
 
+    public static Document read(Source s) throws XMLStreamException {
+        XMLStreamReader reader = createXMLStreamReader(s);
+        try {
+            return read(reader);
+        } finally {
+            try {
+                reader.close();
+            } catch (Exception ex) {
+                //ignore
+            }
+        }
+    }
+    public static Document read(InputStream s) throws XMLStreamException {
+        XMLStreamReader reader = createXMLStreamReader(s);
+        try {
+            return read(reader);
+        } finally {
+            try {
+                reader.close();
+            } catch (Exception ex) {
+                //ignore
+            }
+        }
+    }
+    public static Document read(InputSource s) throws XMLStreamException {
+        XMLStreamReader reader = createXMLStreamReader(s);
+        try {
+            return read(reader);
+        } finally {
+            try {
+                reader.close();
+            } catch (Exception ex) {
+                //ignore
+            }
+        }
+    }
     public static Document read(XMLStreamReader reader) throws XMLStreamException {
         return read(reader, false);
     }
@@ -801,7 +849,8 @@ public final class StaxUtils {
     
     public static Document read(DocumentBuilder builder, XMLStreamReader reader, boolean
repairing) 
         throws XMLStreamException {
-        Document doc = builder.newDocument();
+        
+        Document doc = builder == null ? DOMUtils.createDocument() : builder.newDocument();
         if (reader.getLocation().getSystemId() != null) {
             try {
                 doc.setDocumentURI(new String(reader.getLocation().getSystemId()));
@@ -886,7 +935,10 @@ public final class StaxUtils {
         if (e.getParentNode() instanceof Element) {
             return isDeclared((Element)e.getParentNode(), namespaceURI, prefix);
         }
-
+        if (StringUtils.isEmpty(prefix) && StringUtils.isEmpty(namespaceURI)) {
+            //A document that probably doesn't have any namespace qualifies elements
+            return true;
+        }
         return false;
     }
     public static void readDocElements(Node parent, XMLStreamReader reader, boolean repairing)


Modified: cxf/branches/2.2.x-fixes/integration/jbi/src/main/java/org/apache/cxf/jbi/se/CXFServiceUnit.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/integration/jbi/src/main/java/org/apache/cxf/jbi/se/CXFServiceUnit.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/integration/jbi/src/main/java/org/apache/cxf/jbi/se/CXFServiceUnit.java
(original)
+++ cxf/branches/2.2.x-fixes/integration/jbi/src/main/java/org/apache/cxf/jbi/se/CXFServiceUnit.java
Fri Jul 16 16:42:27 2010
@@ -33,13 +33,13 @@ import javax.jbi.messaging.MessagingExce
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.jws.WebService;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import org.xml.sax.InputSource;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.common.i18n.Message;
@@ -48,6 +48,7 @@ import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.jaxws.EndpointImpl;
 import org.apache.cxf.jaxws.EndpointUtils;
 import org.apache.cxf.jbi.ServiceConsumer;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.transport.ConduitInitiatorManager;
 import org.apache.cxf.transport.jbi.JBITransportFactory;
 
@@ -228,12 +229,10 @@ public class CXFServiceUnit {
                 Class<?> clz = classes.iterator().next();
                 ws = clz.getAnnotation(WebService.class);
             }
-            if (ws != null) { 
-                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                factory.setNamespaceAware(true);
-                DocumentBuilder builder = factory.newDocumentBuilder();
-                doc = builder.parse(ws.wsdlLocation());
-                
+            if (ws != null) {
+                InputSource in = new InputSource(ws.wsdlLocation());
+                StaxUtils.createXMLStreamReader(in);
+                doc = StaxUtils.read(in);
             } else { 
                 LOG.severe(new Message("SU.COULDNOT.GET.ANNOTATION", LOG).toString());
             }

Modified: cxf/branches/2.2.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/Soap11FaultOutInterceptor.java
Fri Jul 16 16:42:27 2010
@@ -23,8 +23,6 @@ import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Document;
@@ -35,6 +33,7 @@ import org.apache.cxf.binding.soap.Soap1
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -101,26 +100,20 @@ public class Soap11FaultOutInterceptor e
                         sb.append(ste.getClassName() + "!" + ste.getMethodName() + "!" +
ste.getFileName()  
                                 + "!" + ste.getLineNumber() + "\n");
                     }
-                    try {
-                        Element detail = fault.getDetail(); 
-                        if (detail == null) {
-                            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-                            factory.setNamespaceAware(true);
-                            Document doc = factory.newDocumentBuilder().newDocument();
-                            Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE,
Fault.STACKTRACE);
-                            stackTrace.setTextContent(sb.toString());
-                            detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
-                            fault.setDetail(detail);
-                            detail.appendChild(stackTrace);
-                        } else {
-                            Element stackTrace = detail.getOwnerDocument().createElementNS(
-                                    Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
-                            stackTrace.setTextContent(sb.toString());
-                            detail.appendChild(stackTrace);
-                        }                    
-                    } catch (ParserConfigurationException pe) {
-                        // move on...
-                    }
+                    Element detail = fault.getDetail(); 
+                    if (detail == null) {
+                        Document doc = XMLUtils.newDocument();
+                        Element stackTrace = doc.createElementNS(Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
+                        stackTrace.setTextContent(sb.toString());
+                        detail = doc.createElementNS(Soap11.SOAP_NAMESPACE, "detail");
+                        fault.setDetail(detail);
+                        detail.appendChild(stackTrace);
+                    } else {
+                        Element stackTrace = detail.getOwnerDocument().createElementNS(
+                                Soap11.SOAP_NAMESPACE, Fault.STACKTRACE);
+                        stackTrace.setTextContent(sb.toString());
+                        detail.appendChild(stackTrace);
+                    }                    
                 }
     
                 if (fault.hasDetails()) {

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
Fri Jul 16 16:42:27 2010
@@ -19,20 +19,17 @@
 
 package org.apache.cxf.bus.extension;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
-import org.xml.sax.SAXException;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class ExtensionFragmentParser {
 
@@ -45,15 +42,8 @@ public class ExtensionFragmentParser {
     List<Extension> getExtensions(InputStream is) {
         Document document = null;
         try {
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            factory.setNamespaceAware(true);
-            DocumentBuilder parser = factory.newDocumentBuilder();
-            document = parser.parse(is);
-        } catch (ParserConfigurationException ex) {
-            throw new ExtensionException(ex);
-        } catch (SAXException ex) {
-            throw new ExtensionException(ex);
-        } catch (IOException ex) {
+            document = StaxUtils.read(is);
+        } catch (XMLStreamException ex) {
             throw new ExtensionException(ex);
         }
         

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java
Fri Jul 16 16:42:27 2010
@@ -24,16 +24,16 @@ import java.util.Collection;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
-import org.xml.sax.InputSource;
-
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.databinding.DataReader;
@@ -42,6 +42,8 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.staxutils.StaxSource;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class NodeDataReader implements DataReader<Node> {
     private static final Logger LOG = LogUtils.getL7dLogger(NodeDataReader.class);
@@ -52,16 +54,8 @@ public class NodeDataReader implements D
 
     public Object read(QName name, Node input, Class type) {
         if (SAXSource.class.isAssignableFrom(type)) {
-            try {
-                CachedOutputStream out = new CachedOutputStream();
-                DOMUtils.writeXml(input, out);
-                
-                return new SAXSource(new InputSource(out.getInputStream()));
-            } catch (IOException e) {
-                throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-            } catch (TransformerException e) {
-                throw new Fault(new Message("COULD_NOT_READ_XML_STREAM", LOG), e);
-            }
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader((Element)input);
+            return new StaxSource(reader);
         } else if (StreamSource.class.isAssignableFrom(type)) {
             try {
                 CachedOutputStream out = new CachedOutputStream();                

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/xml/DocumentType.java
Fri Jul 16 16:42:27 2010
@@ -18,9 +18,6 @@
  */
 package org.apache.cxf.aegis.type.xml;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
@@ -43,21 +40,7 @@ import org.apache.cxf.staxutils.StaxUtil
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
  */
 public class DocumentType extends Type {
-    private DocumentBuilder builder;
-
     public DocumentType() {
-        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setNamespaceAware(true);
-        try {
-            builder = factory.newDocumentBuilder();
-        } catch (ParserConfigurationException e) {
-            throw new DatabindingException("Couldn't load document builder.", e);
-        }
-        setWriteOuter(false);
-    }
-
-    public DocumentType(DocumentBuilder builder) {
-        this.builder = builder;
         setWriteOuter(false);
     }
 
@@ -67,7 +50,7 @@ public class DocumentType extends Type {
             XMLStreamReader reader = ((ElementReader)mreader).getXMLStreamReader();
             // we need to eat the surrounding element.
             reader.nextTag();
-            Object tree = StaxUtils.read(builder, new FragmentStreamReader(reader), true);
+            Object tree = StaxUtils.read(null, new FragmentStreamReader(reader), true);
             reader.nextTag(); // eat the end tag.
             return tree;
         } catch (XMLStreamException e) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
Fri Jul 16 16:42:27 2010
@@ -33,19 +33,17 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.w3c.dom.Document;
 
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
+import org.apache.cxf.staxutils.StaxUtils;
 
 @Provider
 @Produces({"application/xml", "application/*+xml", "text/xml" })
@@ -69,20 +67,21 @@ public class SourceProvider implements 
         if (DOMSource.class.isAssignableFrom(source) || Document.class.isAssignableFrom(source))
{
             
             boolean docRequired = Document.class.isAssignableFrom(source);
-            
-            Document doc = null;
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder builder;
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
             try {
-                builder = factory.newDocumentBuilder();
-                doc = builder.parse(is);
+                Document doc = StaxUtils.read(reader);
+                return docRequired ? doc : new DOMSource(doc);
             } catch (Exception e) {
                 IOException ioex = new IOException("Problem creating a Source object");
                 ioex.setStackTrace(e.getStackTrace());
                 throw ioex;
+            } finally {
+                try {
+                    reader.close();
+                } catch (XMLStreamException e) {
+                    //ignore
+                }
             }
-    
-            return docRequired ? doc : new DOMSource(doc);
         } else if (StreamSource.class.isAssignableFrom(source)
                    || Source.class.isAssignableFrom(source)) {
             return new StreamSource(is);
@@ -96,14 +95,26 @@ public class SourceProvider implements 
     public void writeTo(Source source, Class<?> clazz, Type genericType, Annotation[]
annotations,  
         MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
         throws IOException {
-        StreamResult result = new StreamResult(os);
-        TransformerFactory tf = TransformerFactory.newInstance();
+        
+        String encoding = "utf-8"; //FIXME
+        
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(source);
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, encoding);
         try {
-            Transformer t = tf.newTransformer();
-            t.transform(source, result);
-        } catch (TransformerException te) {
-            te.printStackTrace();
-            throw new WebApplicationException(te);
+            StaxUtils.copy(reader, writer);
+        } catch (XMLStreamException e) {
+            throw new WebApplicationException(e);
+        } finally {
+            try {
+                reader.close();
+            } catch (XMLStreamException e) {
+                //ignore
+            }
+            try {
+                writer.flush();
+            } catch (XMLStreamException e) {
+                //ignore
+            }
         }
     }
     

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
Fri Jul 16 16:42:27 2010
@@ -35,9 +35,7 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.LogicalMessage;
 import javax.xml.ws.Service;
@@ -49,7 +47,6 @@ import org.w3c.dom.Node;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
@@ -148,8 +145,7 @@ public class LogicalMessageImpl implemen
             if (obj instanceof StreamSource) {
                 try {
                     CachedOutputStream cos = new CachedOutputStream();
-                    Transformer transformer = XMLUtils.newTransformer();
-                    transformer.transform(obj, new StreamResult(cos));
+                    StaxUtils.copy(obj, cos);
 
                     obj = new StreamSource(cos.getInputStream());
                     message.setContent(Source.class, new StreamSource(cos.getInputStream()));
@@ -164,9 +160,7 @@ public class LogicalMessageImpl implemen
             } else {
                 try {
                     CachedOutputStream cos = new CachedOutputStream();
-                    Transformer transformer = XMLUtils.newTransformer();
-
-                    transformer.transform(obj, new StreamResult(cos));
+                    StaxUtils.copy(obj, cos);
                     InputStream in = cos.getInputStream();
                     SOAPMessage msg = initSOAPMessage(in);
                     source = new DOMSource(((SOAPMessage)msg).getSOAPBody().getFirstChild());

Modified: cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java
Fri Jul 16 16:42:27 2010
@@ -32,8 +32,6 @@ import javax.jbi.messaging.ExchangeStatu
 import javax.jbi.messaging.Fault;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.dom.DOMSource;
 
 import org.w3c.dom.Document;
@@ -42,6 +40,7 @@ import org.apache.cxf.common.logging.Log
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class JBIDestinationOutputStream extends CachedOutputStream {
 
@@ -85,11 +84,10 @@ public class JBIDestinationOutputStream 
                 InputStream bais = getInputStream();
                 LOG.finest(new org.apache.cxf.common.i18n.Message(
                     "BUILDING.DOCUMENT", LOG).toString());
-                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-                docBuilderFactory.setNamespaceAware(true);
-                DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
-                Document doc = builder.parse(bais);
-            
+                Document doc = StaxUtils.read(bais);
+                bais.close();
+                
+                
                 MessageExchange xchng = inMessage.get(MessageExchange.class);
                 LOG.fine(new org.apache.cxf.common.i18n.Message(
                     "CREATE.NORMALIZED.MESSAGE", LOG).toString());

Modified: cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIMessageHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIMessageHelper.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIMessageHelper.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIMessageHelper.java
Fri Jul 16 16:42:27 2010
@@ -19,37 +19,37 @@
 
 package org.apache.cxf.transport.jbi;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
 
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Source;
 
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public final class JBIMessageHelper {
 
-
-    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
-
     private JBIMessageHelper() {
         // complete
     }
 
-    public static InputStream convertMessageToInputStream(Source src) throws IOException,
-        TransformerConfigurationException, TransformerException {
-
-        final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
+    public static InputStream convertMessageToInputStream(Source src) throws IOException
{
 
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        StreamResult result = new StreamResult(baos);
-        transformer.transform(src, result);
-        
-        return new ByteArrayInputStream(baos.toByteArray());
+        CachedOutputStream cos = new CachedOutputStream();
+        try {
+            StaxUtils.copy(src, cos);
+            return cos.getInputStream();
+        } catch (XMLStreamException e) {
+            IOException ioe = new IOException(e.getMessage());
+            ioe.initCause(e);
+            throw ioe;
+        } finally {
+            try {
+                cos.close();
+            } catch (Exception ex) {
+                //ignore
+            }
+        }
     }
 }

Modified: cxf/branches/2.2.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/SoapFaultFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/SoapFaultFactory.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/SoapFaultFactory.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/SoapFaultFactory.java
Fri Jul 16 16:42:27 2010
@@ -24,7 +24,6 @@ import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
-import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -37,6 +36,7 @@ import org.apache.cxf.binding.soap.SoapV
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.ws.rm.BindingFaultFactory;
 import org.apache.cxf.ws.rm.Identifier;
@@ -98,9 +98,7 @@ public class SoapFaultFactory implements
     }
     
     void setDetail(SoapFault fault, Object detail) throws Exception {
-        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setNamespaceAware(true);
-        Document doc = factory.newDocumentBuilder().newDocument();
+        Document doc = DOMUtils.createDocument();
         Element elem = null;
         
         JAXBContext ctx = JAXBContext.newInstance(

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=964854&r1=964853&r2=964854&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Jul 16 16:42:27 2010
@@ -800,7 +800,10 @@ public class JAXRSClientServerBookTest e
             assertEquals(200, result);
             String resp = put.getResponseBodyAsString();
             InputStream expected = getClass().getResourceAsStream("resources/update_book.txt");
-            assertTrue(resp.indexOf(getStringFromInputStream(expected)) >= 0);
+            String s = getStringFromInputStream(expected);
+            //System.out.println(resp);
+            //System.out.println(s);            
+            assertTrue(resp.indexOf(s) >= 0);
         } finally {
             // Release current connection to the connection pool once you are
             // done



Mime
View raw message