cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject [1/3] cxf git commit: [CXF-6319] Fix regression by storing namespace declarations from Body and Envelope element and later updating the SAAJ model with them
Date Mon, 30 Mar 2015 07:01:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 523dbfde1 -> 401def618


[CXF-6319] Fix regression by storing namespace declarations from Body and Envelope element
and later updating the SAAJ model with them


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

Branch: refs/heads/2.7.x-fixes
Commit: 5b5e74280b7d3b473d82490521c6bc1404611c05
Parents: 523dbfd
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Thu Mar 26 22:34:44 2015 +0100
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Mon Mar 30 08:40:25 2015 +0200

----------------------------------------------------------------------
 .../interceptor/ReadHeadersInterceptor.java     | 47 +++++++++++++++++---
 .../binding/soap/saaj/SAAJInInterceptor.java    | 13 ++++++
 2 files changed, 55 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5b5e7428/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 da79bf6..ee768d9 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
@@ -21,7 +21,10 @@ package org.apache.cxf.binding.soap.interceptor;
 
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
@@ -29,6 +32,7 @@ import javax.xml.stream.XMLEventFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.events.Namespace;
 import javax.xml.stream.events.XMLEvent;
 
 import org.w3c.dom.Attr;
@@ -63,6 +67,8 @@ import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 
 public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
+    
+    public static final String ADDITIONAL_ENVELOPE_BODY_NS = "additional.env.body.ns";
     /**
      * 
      */
@@ -186,6 +192,8 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                     doc = processor.process(filteredReader);
                     if (doc != null) {
                         message.setContent(Node.class, doc);
+                    } else {
+                        message.put(ADDITIONAL_ENVELOPE_BODY_NS, processor.getEnvelopeAndBodyNamespaces());
                     }
                 }
 
@@ -273,14 +281,22 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor
{
      */
     private static class HeadersProcessor {
         private static final XMLEventFactory FACTORY = XMLEventFactory.newInstance();
-        private final QName soapVersionHeader;
+        private final String ns;
+        private final String header;
+        private final String body;
+        private final String envelope;
         private final List<XMLEvent> events = new ArrayList<XMLEvent>(8);
+        private Map<String, String> namespaces;
         private StreamToDOMContext context;
         private Document doc;
         private Node parent;
+        private QName lastStartElementQName;
 
         public HeadersProcessor(SoapVersion version) {
-            this.soapVersionHeader = version.getHeader();
+            this.header = version.getHeader().getLocalPart();
+            this.ns = version.getEnvelope().getNamespaceURI();
+            this.envelope = version.getEnvelope().getLocalPart();
+            this.body = version.getBody().getLocalPart();
         }
 
         public Document process(XMLStreamReader reader) throws XMLStreamException {
@@ -343,9 +359,9 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
 
         private void addEvent(XMLEvent event) {
             if (event.isStartElement()) {
-                QName qName = event.asStartElement().getName();
-                if (soapVersionHeader.getLocalPart().equals(qName.getLocalPart())
-                    && soapVersionHeader.getNamespaceURI().equals(qName.getNamespaceURI()))
{
+                lastStartElementQName = event.asStartElement().getName();
+                if (header.equals(lastStartElementQName.getLocalPart())
+                    && ns.equals(lastStartElementQName.getNamespaceURI())) {
                     // process all events recorded so far
                     context = new StreamToDOMContext(true, false, false);
                     doc = DOMUtils.createDocument();
@@ -361,8 +377,29 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                     events.add(event);
                 }
             } else {
+                if (event.isNamespace()) {
+                    final String lastEl = lastStartElementQName.getLocalPart();
+                    if ((body.equals(lastEl) || envelope.equals(lastEl))
+                        && ns.equals(lastStartElementQName.getNamespaceURI())) {
+                        if (namespaces == null) {
+                            namespaces = new HashMap<String, String>();
+                        }
+                        Namespace nsEvent = (Namespace)event;
+                        //just put in the map, in case of duplicates in env and body,
+                        //body one will always come afterwards, so we're fine
+                        namespaces.put(nsEvent.getPrefix(), nsEvent.getNamespaceURI());
+                    }
+                }
                 events.add(event);
             }
         }
+        
+        public Map<String, String> getEnvelopeAndBodyNamespaces() {
+            if (namespaces == null) {
+                return Collections.emptyMap();
+            } else {
+                return Collections.unmodifiableMap(namespaces);
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/5b5e7428/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 0cca461..17d22ed 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
@@ -25,11 +25,14 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.ResourceBundle;
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
@@ -184,6 +187,16 @@ public class SAAJInInterceptor extends AbstractSoapInterceptor {
             Document node = (Document) message.getContent(Node.class);
             if (node != part && node != null) {
                 StaxUtils.copy(node, new SAAJStreamWriter(part));
+            } else {
+                SOAPBody body = soapMessage.getSOAPBody();
+                @SuppressWarnings("unchecked")
+                Map<String, String> additionalNsMap = (Map<String, String>)message
+                    .get(ReadHeadersInterceptor.ADDITIONAL_ENVELOPE_BODY_NS);
+                if (additionalNsMap != null) {
+                    for (Entry<String, String> e : additionalNsMap.entrySet()) {
+                        body.addNamespaceDeclaration(e.getKey(), e.getValue());
+                    }
+                }
             }
             message.setContent(Node.class, soapMessage.getSOAPPart());
 


Mime
View raw message