cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject [2/3] cxf git commit: [CXF-6319] Improving fix to keep track of both namespaces and attributes
Date Mon, 30 Mar 2015 07:01:33 GMT
[CXF-6319] Improving fix to keep track of both namespaces and attributes


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

Branch: refs/heads/2.7.x-fixes
Commit: 80a884c5c9c2adb048d792936512dd1f58e0bec1
Parents: 5b5e742
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Fri Mar 27 13:05:21 2015 +0100
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Mon Mar 30 08:40:50 2015 +0200

----------------------------------------------------------------------
 .../interceptor/ReadHeadersInterceptor.java     | 47 ++++++++++++--------
 .../binding/soap/saaj/SAAJInInterceptor.java    | 33 +++++++++-----
 2 files changed, 51 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/80a884c5/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 ee768d9..f8c2c66 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
@@ -22,9 +22,7 @@ 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;
@@ -32,7 +30,6 @@ 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;
@@ -68,7 +65,8 @@ import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
     
-    public static final String ADDITIONAL_ENVELOPE_BODY_NS = "additional.env.body.ns";
+    public static final String ENVELOPE_EVENTS = "envelope.events";
+    public static final String BODY_EVENTS = "body.events";
     /**
      * 
      */
@@ -193,7 +191,8 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
                     if (doc != null) {
                         message.setContent(Node.class, doc);
                     } else {
-                        message.put(ADDITIONAL_ENVELOPE_BODY_NS, processor.getEnvelopeAndBodyNamespaces());
+                        message.put(ENVELOPE_EVENTS, processor.getEnvAttributeAndNamespaceEvents());
+                        message.put(BODY_EVENTS, processor.getBodyAttributeAndNamespaceEvents());
                     }
                 }
 
@@ -286,7 +285,8 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor {
         private final String body;
         private final String envelope;
         private final List<XMLEvent> events = new ArrayList<XMLEvent>(8);
-        private Map<String, String> namespaces;
+        private List<XMLEvent> envEvents;
+        private List<XMLEvent> bodyEvents;
         private StreamToDOMContext context;
         private Document doc;
         private Node parent;
@@ -377,28 +377,37 @@ public class ReadHeadersInterceptor extends AbstractSoapInterceptor
{
                     events.add(event);
                 }
             } else {
-                if (event.isNamespace()) {
+                if (event.isNamespace() || event.isAttribute()) {
                     final String lastEl = lastStartElementQName.getLocalPart();
-                    if ((body.equals(lastEl) || envelope.equals(lastEl))
-                        && ns.equals(lastStartElementQName.getNamespaceURI())) {
-                        if (namespaces == null) {
-                            namespaces = new HashMap<String, String>();
+                    if (body.equals(lastEl) && ns.equals(lastStartElementQName.getNamespaceURI()))
{
+                        if (bodyEvents == null) {
+                            bodyEvents = new ArrayList<XMLEvent>();
                         }
-                        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());
+                        bodyEvents.add(event);
+                    } else if (envelope.equals(lastEl) && ns.equals(lastStartElementQName.getNamespaceURI()))
{
+                        if (envEvents == null) {
+                            envEvents = new ArrayList<XMLEvent>();
+                        }
+                        envEvents.add(event);
                     }
                 }
                 events.add(event);
             }
         }
         
-        public Map<String, String> getEnvelopeAndBodyNamespaces() {
-            if (namespaces == null) {
-                return Collections.emptyMap();
+        public List<XMLEvent> getBodyAttributeAndNamespaceEvents() {
+            if (bodyEvents == null) {
+                return Collections.emptyList();
+            } else {
+                return Collections.unmodifiableList(bodyEvents);
+            }
+        }
+        
+        public List<XMLEvent> getEnvAttributeAndNamespaceEvents() {
+            if (envEvents == null) {
+                return Collections.emptyList();
             } else {
-                return Collections.unmodifiableMap(namespaces);
+                return Collections.unmodifiableList(envEvents);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/80a884c5/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 17d22ed..e8bc8ec 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,14 +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.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
@@ -40,6 +40,9 @@ import javax.xml.soap.SOAPPart;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Namespace;
+import javax.xml.stream.events.XMLEvent;
 import javax.xml.transform.dom.DOMSource;
 
 import org.w3c.dom.Document;
@@ -162,6 +165,7 @@ public class SAAJInInterceptor extends AbstractSoapInterceptor {
     
     
     
+    @SuppressWarnings("unchecked")
     public void handleMessage(SoapMessage message) throws Fault {
         if (isGET(message)) {
             return;
@@ -188,15 +192,12 @@ public class SAAJInInterceptor extends AbstractSoapInterceptor {
             if (node != part && node != null) {
                 StaxUtils.copy(node, new SAAJStreamWriter(part));
             } else {
+                SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
+                List<XMLEvent> events = (List<XMLEvent>)message.get(ReadHeadersInterceptor.ENVELOPE_EVENTS);
+                applyEvents(events, env);
                 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());
-                    }
-                }
+                events = (List<XMLEvent>)message.get(ReadHeadersInterceptor.BODY_EVENTS);
+                applyEvents(events, body);
             }
             message.setContent(Node.class, soapMessage.getSOAPPart());
 
@@ -253,6 +254,18 @@ public class SAAJInInterceptor extends AbstractSoapInterceptor {
         }
     }
 
+    private static void applyEvents(List<XMLEvent> events, SOAPElement el) throws SOAPException
{
+        if (events != null) {
+            for (XMLEvent ev : events) {
+                if (ev.isNamespace()) {
+                    el.addNamespaceDeclaration(((Namespace)ev).getPrefix(), ((Namespace)ev).getNamespaceURI());
+                } else if (ev.isAttribute()) {
+                    el.addAttribute(((Attribute)ev).getName(), ((Attribute)ev).getValue());
+                }
+            }
+        }
+    }
+
     public static void replaceHeaders(SOAPMessage soapMessage, SoapMessage message) throws
SOAPException {
         SOAPHeader header = SAAJUtils.getHeader(soapMessage);
         if (header == null) {


Mime
View raw message