This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 2851ffc  Slight refactor of the StaxSerializer
2851ffc is described below

commit 2851ffc7f9980fb03b5bd498ee837749414c8664
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Mon Jan 27 11:54:24 2020 +0000

    Slight refactor of the StaxSerializer
---
 .../cxf/ws/security/wss4j/StaxSerializer.java      | 59 ++++++++++++----------
 .../cxf/ws/security/wss4j/WSS4JOutInterceptor.java |  1 +
 2 files changed, 32 insertions(+), 28 deletions(-)

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 ede4755..7d2428f 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
@@ -59,10 +59,36 @@ import static java.nio.charset.StandardCharsets.UTF_8;
  * Converts <code>String</code>s into <code>Node</code>s and visa versa using 
CXF's StaxUtils
  */
 public class StaxSerializer extends AbstractSerializer {
-    XMLInputFactory factory;
-    boolean validFactory;
+    private XMLInputFactory factory;
+    private boolean validFactory;
 
-    boolean addNamespaces(XMLStreamReader reader, Node ctx) {
+    /**
+     * @param source
+     * @param ctx
+     * @param secureValidation
+     * @return the Node resulting from the parse of the source
+     * @throws XMLEncryptionException
+     */
+    @Override
+    public Node deserialize(byte[] source, Node ctx, boolean secureValidation) 
throws XMLEncryptionException {
+        XMLStreamReader reader = createWstxReader(source, ctx);
+        if (reader != null) {
+            return deserialize(ctx, reader, false);
+        }
+        return deserialize(ctx, new InputSource(createStreamContext(source, 
ctx)));
+    }
+
+    @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();
+        }
+    }
+
+    private boolean addNamespaces(XMLStreamReader reader, Node ctx) {
         try {
             NamespaceContext nsctx = reader.getNamespaceContext();
             if (nsctx instanceof com.ctc.wstx.sr.InputElementStack) {
@@ -125,22 +151,8 @@ public class StaxSerializer extends AbstractSerializer {
         }
         return null;
     }
-    /**
-     * @param source
-     * @param ctx
-     * @param secureValidation
-     * @return the Node resulting from the parse of the source
-     * @throws XMLEncryptionException
-     */
-    public Node deserialize(byte[] source, Node ctx, boolean secureValidation) 
throws XMLEncryptionException {
-        XMLStreamReader reader = createWstxReader(source, ctx);
-        if (reader != null) {
-            return deserialize(ctx, reader, false);
-        }
-        return deserialize(ctx, new InputSource(createStreamContext(source, 
ctx)));
-    }
 
-    InputStream createStreamContext(byte[] source, Node ctx) throws 
XMLEncryptionException {
+    private InputStream createStreamContext(byte[] source, Node ctx) throws 
XMLEncryptionException {
         Vector<InputStream> v = new Vector<>(2); //NOPMD
 
         LoadingByteArrayOutputStream byteArrayOutputStream = new 
LoadingByteArrayOutputStream();
@@ -185,16 +197,6 @@ public class StaxSerializer extends AbstractSerializer {
         return new SequenceInputStream(v.elements());
     }
 
-    @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();
-        }
-    }
-
     /**
      * @param ctx
      * @param inputSource
@@ -205,6 +207,7 @@ public class StaxSerializer extends AbstractSerializer {
         XMLStreamReader reader = StaxUtils.createXMLStreamReader(inputSource);
         return deserialize(ctx, reader, true);
     }
+
     private Node deserialize(Node ctx, XMLStreamReader reader, boolean 
wrapped) throws XMLEncryptionException {
         Document contextDocument = null;
         if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
diff --git 
a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
 
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
index ba62aa9..c96c841 100644
--- 
a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
+++ 
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
@@ -165,6 +165,7 @@ public class WSS4JOutInterceptor extends 
AbstractWSS4JInterceptor {
             try {
                 WSSConfig config = WSSConfig.getNewInstance();
                 reqData.setWssConfig(config);
+                reqData.setEncryptionSerializer(new StaxSerializer());
 
                 /*
                  * Setup any custom actions first by processing the input 
properties

Reply via email to