cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject cxf git commit: [CXF-6867] Ensure Envelope and Body element prefixes are not changed when processing messages without headers
Date Wed, 13 Apr 2016 21:06:24 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 6566e5c6e -> 26edcd457


[CXF-6867] Ensure Envelope and Body element prefixes are not changed when processing messages
without headers


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

Branch: refs/heads/master
Commit: 26edcd457ea507075a4c82e2787f11f11a432876
Parents: 6566e5c
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Wed Apr 13 23:02:56 2016 +0200
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Wed Apr 13 23:02:56 2016 +0200

----------------------------------------------------------------------
 .../interceptor/ReadHeadersInterceptor.java     | 21 ++++++++++++++++++++
 .../binding/soap/saaj/SAAJInInterceptor.java    | 10 ++++++++++
 .../cxf/binding/soap/saaj/SAAJStreamWriter.java | 17 ++--------------
 .../apache/cxf/binding/soap/saaj/SAAJUtils.java | 17 ++++++++++++++++
 4 files changed, 50 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/26edcd45/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
index 269ef4d..6bfa3a3 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
@@ -70,6 +70,8 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
     
     public static final String ENVELOPE_EVENTS = "envelope.events";
     public static final String BODY_EVENTS = "body.events";
+    public static final String ENVELOPE_PREFIX = "envelope.prefix";
+    public static final String BODY_PREFIX = "body.prefix";
     /**
      * 
      */
@@ -205,6 +207,8 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                     } else {
                         message.put(ENVELOPE_EVENTS, processor.getEnvAttributeAndNamespaceEvents());
                         message.put(BODY_EVENTS, processor.getBodyAttributeAndNamespaceEvents());
+                        message.put(ENVELOPE_PREFIX, processor.getEnvelopePrefix());
+                        message.put(BODY_PREFIX, processor.getBodyPrefix());
                     }
                     if (addNC) {
                         // add the Body-level declarations
@@ -326,6 +330,8 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
         private Document doc;
         private Node parent;
         private QName lastStartElementQName;
+        private String envelopePrefix;
+        private String bodyPrefix;
 
         HeadersProcessor(SoapVersion version) {
             this.header = version.getHeader().getLocalPart();
@@ -409,6 +415,13 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                         throw new Fault(e);
                     }
                 } else {
+                    if (ns.equals(lastStartElementQName.getNamespaceURI())) {
+                        if (body.equals(lastStartElementQName.getLocalPart())) {
+                            bodyPrefix = lastStartElementQName.getPrefix();
+                        } else if (envelope.equals(lastStartElementQName.getLocalPart()))
{
+                            envelopePrefix = lastStartElementQName.getPrefix();
+                        }
+                    }
                     events.add(event);
                 }
             } else {
@@ -445,5 +458,13 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                 return Collections.unmodifiableList(envEvents);
             }
         }
+        
+        public String getEnvelopePrefix() {
+            return envelopePrefix;
+        }
+        
+        public String getBodyPrefix() {
+            return bodyPrefix;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/26edcd45/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
index 51afbf5..516bf89 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
@@ -193,6 +193,10 @@ public class SAAJInInterceptor extends AbstractSoapInterceptor {
                 StaxUtils.copy(node, new SAAJStreamWriter(part));
             } else {
                 SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
+                if (node == null) {
+                    adjustPrefixes(env, (String)message.get(ReadHeadersInterceptor.ENVELOPE_PREFIX),
+                                   (String)message.get(ReadHeadersInterceptor.BODY_PREFIX));
+                }
                 List<XMLEvent> events = (List<XMLEvent>)message.get(ReadHeadersInterceptor.ENVELOPE_EVENTS);
                 applyEvents(events, env);
                 SOAPBody body = soapMessage.getSOAPBody();
@@ -258,6 +262,12 @@ public class SAAJInInterceptor extends AbstractSoapInterceptor {
                     .getVersion().getSender());
         }
     }
+    
+    private static void adjustPrefixes(SOAPEnvelope env, String envPrefix, String bodyPrefix)
throws SOAPException {
+        SAAJUtils.adjustPrefix(env, envPrefix);
+        SAAJUtils.adjustPrefix(env.getBody(), bodyPrefix);
+        SAAJUtils.adjustPrefix(env.getHeader(), envPrefix);
+    }
 
     private static void applyEvents(List<XMLEvent> events, SOAPElement el) throws SOAPException
{
         if (events != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/26edcd45/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 f96a14d..14b5c2e 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
@@ -32,6 +32,8 @@ import org.w3c.dom.Node;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.staxutils.OverlayW3CDOMStreamWriter;
 
+import static org.apache.cxf.binding.soap.saaj.SAAJUtils.adjustPrefix;
+
 public final class SAAJStreamWriter extends OverlayW3CDOMStreamWriter {
     private final SOAPPart part;
 
@@ -44,21 +46,6 @@ public final class SAAJStreamWriter extends OverlayW3CDOMStreamWriter {
         this.part = part;
     }
 
-    private SOAPElement adjustPrefix(SOAPElement e, String prefix) {
-        if (prefix == null) {
-            prefix = "";
-        }
-        try {
-            String s = e.getPrefix();
-            if (!prefix.equals(s)) {
-                e.setPrefix(prefix);
-                e.removeNamespaceDeclaration(s);
-            }
-        } catch (Throwable t) {
-            //likely old old version of SAAJ, we'll just try our best
-        }
-        return e;
-    }
     protected void adjustOverlaidNode(Node nd2, String pfx) {
         String namespace = nd2.getNamespaceURI();
         try {

http://git-wip-us.apache.org/repos/asf/cxf/blob/26edcd45/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJUtils.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJUtils.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJUtils.java
index 78702a3..89cb7f7 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJUtils.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJUtils.java
@@ -21,6 +21,7 @@ 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.SOAPException;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPHeader;
@@ -66,4 +67,20 @@ public final class SAAJUtils {
         }
         
     }
+    
+    public static SOAPElement adjustPrefix(SOAPElement e, String prefix) {
+        if (prefix == null) {
+            prefix = "";
+        }
+        try {
+            String s = e.getPrefix();
+            if (!prefix.equals(s)) {
+                e.setPrefix(prefix);
+                e.removeNamespaceDeclaration(s);
+            }
+        } catch (Throwable t) {
+            //likely old old version of SAAJ, we'll just try our best
+        }
+        return e;
+    }
 }


Mime
View raw message