cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: Adding outbound serializing functionality
Date Fri, 20 May 2016 13:17:34 GMT
Repository: cxf
Updated Branches:
  refs/heads/master c29c334e4 -> bba546b4c


Adding outbound serializing functionality


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

Branch: refs/heads/master
Commit: bba546b4cdde6ff35f935a0bef30394fd4fc0e52
Parents: c29c334
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri May 20 11:44:12 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri May 20 14:01:19 2016 +0100

----------------------------------------------------------------------
 .../cxf/ws/security/wss4j/StaxSerializer.java   | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/bba546b4/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSerializer.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSerializer.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSerializer.java
index 9af3d2f..cc9045b 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSerializer.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/StaxSerializer.java
@@ -19,16 +19,20 @@
 package org.apache.cxf.ws.security.wss4j;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.StringReader;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 
 import org.apache.cxf.staxutils.StaxUtils;
@@ -61,6 +65,28 @@ public class StaxSerializer extends AbstractSerializer {
         String fragment = createContext(source, ctx);
         return deserialize(ctx, new InputSource(new StringReader(fragment)));
     }
+    
+    @Override
+    public byte[] serializeToByteArray(Element element) throws Exception {
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
+            StaxUtils.copy(element, writer);
+            writer.close();
+            return baos.toByteArray();
+        }
+    }
+    
+    @Override
+    public byte[] serializeToByteArray(NodeList content) throws Exception {
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
+            for (int i = 0; i < content.getLength(); i++) {
+                StaxUtils.copy(new DOMSource(content.item(i)), writer);
+            }
+            writer.close();
+            return baos.toByteArray();
+        }
+    }
 
     /**
      * @param ctx


Mime
View raw message