cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r735782 - in /cxf/trunk/rt: bindings/soap/src/main/java/org/apache/cxf/binding/soap/ bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/
Date Mon, 19 Jan 2009 19:45:08 GMT
Author: dkulp
Date: Mon Jan 19 11:45:08 2009
New Revision: 735782

URL: http://svn.apache.org/viewvc?rev=735782&view=rev
Log:
[CXF-1993] Allow adding specific namespaces to soap:envolope

Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java?rev=735782&r1=735781&r2=735782&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java
Mon Jan 19 11:45:08 2009
@@ -21,6 +21,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 
@@ -52,7 +53,7 @@
         }
         return heads;
     }
-    
+       
     public boolean hasHeader(QName qn) {
         for (Header head : getHeaders()) {
             if (head.getName().equals(qn)) {
@@ -74,4 +75,13 @@
         return containsKey(Header.HEADER_LIST) && getHeaders().size() > 0;
     }
     
+    public Map<String, String> getEnvelopeNs() {
+        return CastUtils.cast((Map<? , ?>)get("soap.env.ns.map"));
+    }
+    
+    public boolean hasAdditionalEnvNs() {
+        Map<String, String> ns = getEnvelopeNs();
+        return ns != null && !ns.isEmpty();
+    } 
+    
 }

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java?rev=735782&r1=735781&r2=735782&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
Mon Jan 19 11:45:08 2009
@@ -22,6 +22,7 @@
 
 import java.io.OutputStream;
 import java.util.List;
+import java.util.Map;
 import java.util.ResourceBundle;
 
 import javax.xml.stream.XMLStreamException;
@@ -94,16 +95,35 @@
         final SoapVersion soapVersion = message.getVersion();
         try {            
             XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
-            xtw.setPrefix(soapVersion.getPrefix(), soapVersion.getNamespace());
-            xtw.writeStartElement(soapVersion.getPrefix(), 
-                                  soapVersion.getEnvelope().getLocalPart(),
-                                  soapVersion.getNamespace());
-            xtw.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
-            
+            String soapPrefix = soapVersion.getPrefix();
+            if (message.hasAdditionalEnvNs()) {
+                Map<String, String> nsMap = message.getEnvelopeNs();
+                for (Map.Entry<String, String> entry : nsMap.entrySet()) {
+                    if (soapVersion.getNamespace().equals(entry.getValue())) {
+                        soapPrefix = entry.getKey();
+                    }
+                }
+                xtw.setPrefix(soapPrefix, soapVersion.getNamespace());
+                xtw.writeStartElement(soapPrefix, 
+                                      soapVersion.getEnvelope().getLocalPart(),
+                                      soapVersion.getNamespace());
+                xtw.writeNamespace(soapPrefix, soapVersion.getNamespace());
+                for (Map.Entry<String, String> entry : nsMap.entrySet()) {
+                    if (!soapVersion.getNamespace().equals(entry.getValue())) {
+                        xtw.writeNamespace(entry.getKey(), entry.getValue());
+                    }
+                }                
+            } else {
+                xtw.setPrefix(soapPrefix, soapVersion.getNamespace());
+                xtw.writeStartElement(soapPrefix, 
+                                      soapVersion.getEnvelope().getLocalPart(),
+                                      soapVersion.getNamespace());
+                xtw.writeNamespace(soapPrefix, soapVersion.getNamespace());
+            }
             boolean preexistingHeaders = message.hasHeaders();
 
             if (preexistingHeaders) {
-                xtw.writeStartElement(soapVersion.getPrefix(), 
+                xtw.writeStartElement(soapPrefix, 
                                       soapVersion.getHeader().getLocalPart(),
                                       soapVersion.getNamespace());   
                 List<Header> hdrList = message.getHeaders();
@@ -111,7 +131,7 @@
                     XMLStreamWriter writer = xtw;
                     if (header instanceof SoapHeader) {
                         SoapHeader soapHeader = (SoapHeader)header;
-                        writer = new SOAPHeaderWriter(xtw, soapHeader, soapVersion);
+                        writer = new SOAPHeaderWriter(xtw, soapHeader, soapVersion, soapPrefix);
                     }
                     DataBinding b = header.getDataBinding();
                     if (b == null) {
@@ -132,12 +152,12 @@
                     }
                 }
             }
-            boolean endedHeader = handleHeaderPart(preexistingHeaders, message);
+            boolean endedHeader = handleHeaderPart(preexistingHeaders, message, soapPrefix);
             if (preexistingHeaders && !endedHeader) {
                 xtw.writeEndElement();
             }
 
-            xtw.writeStartElement(soapVersion.getPrefix(), 
+            xtw.writeStartElement(soapPrefix, 
                                   soapVersion.getBody().getLocalPart(),
                                   soapVersion.getNamespace());
             
@@ -148,7 +168,7 @@
         }
     }
     
-    private boolean handleHeaderPart(boolean preexistingHeaders, SoapMessage message) {
+    private boolean handleHeaderPart(boolean preexistingHeaders, SoapMessage message, String
soapPrefix) {
         //add MessagePart to soapHeader if necessary
         boolean endedHeader = false;
         Exchange exchange = message.getExchange();
@@ -194,7 +214,7 @@
                 objs.remove(part);
                 if (!(startedHeader || preexistingHeaders)) {
                     try {
-                        xtw.writeStartElement(soapVersion.getPrefix(), 
+                        xtw.writeStartElement(soapPrefix, 
                                               soapVersion.getHeader().getLocalPart(),
                                               soapVersion.getNamespace());
                     } catch (XMLStreamException e) {
@@ -260,14 +280,18 @@
     public static class SOAPHeaderWriter extends DelegatingXMLStreamWriter {
         final SoapHeader soapHeader;
         final SoapVersion soapVersion;
+        final String soapPrefix;
         boolean firstDone;
         
+        
         public SOAPHeaderWriter(XMLStreamWriter writer,
                                 SoapHeader header,
-                                SoapVersion version) {
+                                SoapVersion version,
+                                String pfx) {
             super(writer);
             soapHeader = header;
             soapVersion = version;
+            soapPrefix = pfx;
         }
         
         public void writeAttribute(String prefix, String uri, String local, String value)
@@ -292,13 +316,13 @@
             if (!firstDone) {
                 firstDone = true;
                 if (!StringUtils.isEmpty(soapHeader.getActor())) {
-                    super.writeAttribute(soapVersion.getPrefix(),
+                    super.writeAttribute(soapPrefix,
                                    soapVersion.getNamespace(),
                                    soapVersion.getAttrNameRole(),
                                    soapHeader.getActor());
                 }
                 if (soapHeader.isMustUnderstand()) {
-                    super.writeAttribute(soapVersion.getPrefix(),
+                    super.writeAttribute(soapPrefix,
                                    soapVersion.getNamespace(),
                                    soapVersion.getAttrNameMustUnderstand(),
                                    "true");                                        

Modified: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java?rev=735782&r1=735781&r2=735782&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java (original)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java Mon
Jan 19 11:45:08 2009
@@ -359,14 +359,25 @@
 
     private void addMustUnderstandAttribute(Element header,
                                             QName name,
-                                            SoapVersion version,
+                                            SoapMessage msg,
                                             AddressingPropertiesImpl maps) {
         if (maps.getMustUnderstand().contains(name)) {
             Element lastAdded = (Element)header.getLastChild();
+            String pfx = msg.getVersion().getPrefix();
+            if (msg.hasAdditionalEnvNs()) {
+                String ns = msg.getVersion().getNamespace();
+                Map<String, String> nsMap = msg.getEnvelopeNs();
+                for (Map.Entry<String, String> entry : nsMap.entrySet()) {
+                    if (ns.equals(entry.getValue())) {
+                        pfx = entry.getKey();
+                    }
+                }
+            }
+            
             Attr mustUnderstandAttr = 
                 lastAdded.getOwnerDocument().createAttributeNS(
-                    version.getNamespace(),
-                    version.getPrefix() + ":mustUnderstand");
+                    msg.getVersion().getNamespace(),
+                    pfx + ":mustUnderstand");
             mustUnderstandAttr.setTextContent("1");
             lastAdded.setAttributeNodeNS(mustUnderstandAttr);
         }
@@ -403,7 +414,7 @@
         }
         addMustUnderstandAttribute(header,
                                    name,
-                                   message.getVersion(),
+                                   message,
                                    maps);
     }
     



Mime
View raw message