cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject cxf git commit: Updates to get the transformation stuff to workaround all the bugs/junk in SAAJ for the faults
Date Fri, 20 May 2016 15:31:46 GMT
Repository: cxf
Updated Branches:
  refs/heads/master bba546b4c -> e8ea9e74c


Updates to get the transformation stuff to workaround all the bugs/junk in SAAJ for the faults


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

Branch: refs/heads/master
Commit: e8ea9e74c09d3313d6353d9914f361105b06128e
Parents: bba546b
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri May 20 11:31:00 2016 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri May 20 11:31:00 2016 -0400

----------------------------------------------------------------------
 .../staxutils/OverlayW3CDOMStreamWriter.java    |  6 ++
 .../cxf/staxutils/W3CDOMStreamWriter.java       |  4 +
 .../cxf/binding/soap/saaj/SAAJStreamWriter.java | 78 ++++++++++++++------
 .../cxf/ws/security/wss4j/StaxSerializer.java   | 60 +++++++++++----
 .../ws/security/wss4j/WSS4JInInterceptor.java   |  2 +-
 .../ws/security/wss4j/WSS4JFaultCodeTest.java   |  2 +
 6 files changed, 115 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ea9e74/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java b/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
index d30bf4f..475973a 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/OverlayW3CDOMStreamWriter.java
@@ -25,6 +25,7 @@ import java.util.List;
 import javax.xml.stream.XMLStreamException;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.Text;
@@ -53,6 +54,11 @@ public class OverlayW3CDOMStreamWriter extends W3CDOMStreamWriter {
     public OverlayW3CDOMStreamWriter(Document doc, Element e) {
         super(doc, e);
     }
+    public OverlayW3CDOMStreamWriter(Document doc, DocumentFragment frag) {
+        super(doc, frag);
+        isOverlaid = false;
+    }
+
 
     @Override
     protected void createAndAddElement(String prefix, String local, String namespace) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ea9e74/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java b/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
index 6903c4c..353da70 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
@@ -60,6 +60,10 @@ public class W3CDOMStreamWriter implements XMLStreamWriter {
         this.document = frag.getOwnerDocument();
         currentNode = frag;
     }
+    public W3CDOMStreamWriter(Document document, DocumentFragment frag) {
+        this.document = document;
+        currentNode = frag;
+    }
 
     public W3CDOMStreamWriter(Element e) {
         this.document = e.getOwnerDocument();

http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ea9e74/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
index 393a553..185079b 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
@@ -21,11 +21,13 @@ package org.apache.cxf.binding.soap.saaj;
 import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPPart;
 
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
@@ -36,7 +38,10 @@ import static org.apache.cxf.binding.soap.saaj.SAAJUtils.adjustPrefix;
 
 public final class SAAJStreamWriter extends OverlayW3CDOMStreamWriter {
     private final SOAPPart part;
-
+    private final SOAPEnvelope envelope;
+    private String uri;
+    
+    
     public SAAJStreamWriter(SOAPPart part) {
         super(part);
         this.part = part;
@@ -44,20 +49,47 @@ public final class SAAJStreamWriter extends OverlayW3CDOMStreamWriter
{
         if (nd == null) {
             isOverlaid = false;
         }
+        envelope = null;
     }
     public SAAJStreamWriter(SOAPPart part, Element current) {
         super(part, current);
         this.part = part;
+        envelope = null;
     }
-
+    public SAAJStreamWriter(SOAPEnvelope env, DocumentFragment frag) {
+        super(env.getOwnerDocument(), frag);
+        this.part = null;
+        this.envelope = env;
+        isOverlaid = false;
+    }
+    public SAAJStreamWriter(SOAPEnvelope env, Element cur) {
+        super(env.getOwnerDocument(), cur);
+        this.part = null;
+        this.envelope = env;
+        isOverlaid = false;
+    }
+    
+    private String getEnvelopeURI() throws SOAPException {
+        if (uri == null) {
+            uri = getEnvelope().getElementName().getURI();
+        }
+        return uri;
+    }
+    private SOAPEnvelope getEnvelope() throws SOAPException {
+        if (envelope == null) {
+            return part.getEnvelope();
+        }
+        return envelope;
+    }
+    
     protected void adjustOverlaidNode(Node nd2, String pfx) {
         String namespace = nd2.getNamespaceURI();
         try {
             if (namespace != null 
-                && namespace.equals(part.getEnvelope().getElementName().getURI()))
{
+                && namespace.equals(getEnvelopeURI())) {
                 adjustPrefix((SOAPElement)nd2, pfx);
                 if ("Envelope".equals(nd2.getLocalName())) {
-                    adjustPrefix(part.getEnvelope().getHeader(), pfx);
+                    adjustPrefix(getEnvelope().getHeader(), pfx);
                 }
             }
         } catch (SOAPException e) {
@@ -67,37 +99,41 @@ public final class SAAJStreamWriter extends OverlayW3CDOMStreamWriter
{
     }
     
     protected void createAndAddElement(String prefix, String local, String namespace) {
+        if (part == null) {
+            super.createAndAddElement(prefix, local, namespace);
+            return;
+        }
         try {
             if (namespace != null 
-                && namespace.equals(part.getEnvelope().getElementName().getURI()))
{
+                && namespace.equals(getEnvelopeURI())) {
                 if ("Envelope".equals(local)) {
-                    setChild(adjustPrefix(part.getEnvelope(), prefix), false);
-                    adjustPrefix(part.getEnvelope().getHeader(), prefix);
-                    adjustPrefix(part.getEnvelope().getBody(), prefix);
-                    part.getEnvelope().removeChild(part.getEnvelope().getHeader());
-                    part.getEnvelope().removeChild(part.getEnvelope().getBody());
+                    setChild(adjustPrefix(getEnvelope(), prefix), false);
+                    adjustPrefix(getEnvelope().getHeader(), prefix);
+                    adjustPrefix(getEnvelope().getBody(), prefix);
+                    getEnvelope().removeChild(getEnvelope().getHeader());
+                    getEnvelope().removeChild(getEnvelope().getBody());
                     return;
                 } else if ("Body".equals(local)) {
-                    if (part.getEnvelope().getBody() == null) {
-                        part.getEnvelope().addBody();
+                    if (getEnvelope().getBody() == null) {
+                        getEnvelope().addBody();
                     }
-                    setChild(adjustPrefix(part.getEnvelope().getBody(), prefix), false);
+                    setChild(adjustPrefix(getEnvelope().getBody(), prefix), false);
                     return;
                 } else if ("Header".equals(local)) {
-                    if (part.getEnvelope().getHeader() == null) {
-                        part.getEnvelope().addHeader();
+                    if (getEnvelope().getHeader() == null) {
+                        getEnvelope().addHeader();
                     }
-                    setChild(adjustPrefix(part.getEnvelope().getHeader(), prefix), false);
+                    setChild(adjustPrefix(getEnvelope().getHeader(), prefix), false);
                     return;
                 } else if ("Fault".equals(local)) {
-                    SOAPFault f = part.getEnvelope().getBody().getFault();
+                    SOAPFault f = getEnvelope().getBody().getFault();
                     if (f == null) {
-                        Element el = part.createElementNS(namespace, 
+                        Element el = getDocument().createElementNS(namespace, 
                                              StringUtils.isEmpty(prefix) ? local : prefix
+ ":" + local);
-                        part.getEnvelope().getBody().appendChild(el);
-                        f = part.getEnvelope().getBody().getFault();
+                        getEnvelope().getBody().appendChild(el);
+                        f = getEnvelope().getBody().getFault();
                         if (f == null) {
-                            f = part.getEnvelope().getBody().addFault();
+                            f = getEnvelope().getBody().addFault();
                         }
                     }
                     setChild(adjustPrefix(f, prefix), false);

http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ea9e74/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 cc9045b..cf74c01 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
@@ -22,6 +22,8 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.StringReader;
 
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
@@ -35,6 +37,7 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.binding.soap.saaj.SAAJStreamWriter;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.xml.security.encryption.AbstractSerializer;
 import org.apache.xml.security.encryption.XMLEncryptionException;
@@ -105,26 +108,53 @@ public class StaxSerializer extends AbstractSerializer {
         
         XMLStreamReader reader = StaxUtils.createXMLStreamReader(inputSource);
         
-        // Import to a dummy fragment
-        DocumentFragment dummyFragment = contextDocument.createDocumentFragment();
-        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(new DOMResult(dummyFragment));
-        
+        XMLStreamWriter writer = null;
         try {
+            if (ctx instanceof SOAPElement) {
+                SOAPElement el = (SOAPElement)ctx;
+                while (el != null && !(el instanceof SOAPEnvelope)) {
+                    el = el.getParentElement();
+                }
+                //cannot load into fragment due to a ClassCastException iwthin SAAJ addChildElement

+                //which only checks for Document as parent, not DocumentFragment
+                Element element = ctx.getOwnerDocument().createElementNS("dummy", "dummy");
+                writer = new SAAJStreamWriter((SOAPEnvelope)el, element);
+                StaxUtils.copy(reader, writer);
+                
+                DocumentFragment result = contextDocument.createDocumentFragment();
+                Node child = element.getFirstChild().getFirstChild();
+                if (child != null && child.getNextSibling() == null) {
+                    return child;
+                }
+                while (child != null) {
+                    Node nextChild = child.getNextSibling();
+                    result.appendChild(child);
+                    child = nextChild;
+                }
+                
+                return result;
+            }
+            // Import to a dummy fragment
+            DocumentFragment dummyFragment = contextDocument.createDocumentFragment();
+            writer = StaxUtils.createXMLStreamWriter(new DOMResult(dummyFragment));
             StaxUtils.copy(reader, writer);
+            
+            // Remove the "dummy" wrapper
+            DocumentFragment result = contextDocument.createDocumentFragment();
+            Node child = dummyFragment.getFirstChild().getFirstChild();
+            if (child != null && child.getNextSibling() == null) {
+                return child;
+            }
+            while (child != null) {
+                Node nextChild = child.getNextSibling();
+                result.appendChild(child);
+                child = nextChild;
+            }
+            
+            return result;
         } catch (XMLStreamException ex) {
             throw new XMLEncryptionException(ex);
         }
-        
-        // Remove the "dummy" wrapper
-        DocumentFragment result = contextDocument.createDocumentFragment();
-        Node child = dummyFragment.getFirstChild().getFirstChild();
-        while (child != null) {
-            Node nextChild = child.getNextSibling();
-            result.appendChild(child);
-            child = nextChild;
-        }
-        
-        return result;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ea9e74/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
index b506853..bd90c04 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
@@ -196,7 +196,7 @@ public class WSS4JInInterceptor extends AbstractWSS4JInterceptor {
             config = engine.getWssConfig();
         }
         reqData.setWssConfig(config);
-        // reqData.setEncryptionSerializer(new StaxSerializer());
+        reqData.setEncryptionSerializer(new StaxSerializer());
         
         // Add Audience Restrictions for SAML
         configureAudienceRestriction(msg, reqData);

http://git-wip-us.apache.org/repos/asf/cxf/blob/e8ea9e74/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JFaultCodeTest.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JFaultCodeTest.java
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JFaultCodeTest.java
index 1393ef8..9414679 100644
--- a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JFaultCodeTest.java
+++ b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/WSS4JFaultCodeTest.java
@@ -265,6 +265,8 @@ public class WSS4JFaultCodeTest extends AbstractSecurityTest {
         
         try {
             inHandler.handleMessage(inmsg);
+            StaxUtils.print(saajMsg.getSOAPPart());
+            
             fail("Expected failure on a SOAP Fault");
         } catch (SoapFault fault) {
             fault.printStackTrace();


Mime
View raw message