servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r992169 - /servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRMessageHelper.java
Date Fri, 03 Sep 2010 01:37:09 GMT
Author: ffang
Date: Fri Sep  3 01:37:09 2010
New Revision: 992169

URL: http://svn.apache.org/viewvc?rev=992169&view=rev
Log:
[SMX4-588]refactor NMRMessageHelper to use new api from cxf StaxUtis

Modified:
    servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRMessageHelper.java

Modified: servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRMessageHelper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRMessageHelper.java?rev=992169&r1=992168&r2=992169&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRMessageHelper.java
(original)
+++ servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRMessageHelper.java
Fri Sep  3 01:37:09 2010
@@ -19,37 +19,39 @@
 
 package org.apache.servicemix.cxf.transport.nmr;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+
+import javax.xml.stream.XMLStreamException;
 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 org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.staxutils.StaxUtils;
 
 
-public final class NMRMessageHelper {
 
+public final class NMRMessageHelper {
 
-    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
 
-    private NMRMessageHelper() {
+	private NMRMessageHelper() {
         // complete
     }
 
-    public static InputStream convertMessageToInputStream(Source src) throws IOException,
-        TransformerConfigurationException, TransformerException {
-
-        final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        StreamResult result = new StreamResult(baos);
-        transformer.transform(src, result);
-        
-        return new ByteArrayInputStream(baos.toByteArray());
+    public static InputStream convertMessageToInputStream(Source src) throws IOException
{
+    	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
+    		}
+    	}
     }
 }



Mime
View raw message