cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r538231 [1/2] - in /incubator/cxf/trunk: ./ api/src/main/java/org/apache/cxf/headers/ common/common/src/main/java/org/apache/cxf/staxutils/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/ rt/bindings/soap/src/main/java/org/apach...
Date Tue, 15 May 2007 15:52:39 GMT
Author: dkulp
Date: Tue May 15 08:52:36 2007
New Revision: 538231

URL: http://svn.apache.org/viewvc?view=rev&rev=538231
Log:
Merged revisions 537245-538004,538006-538191,538194-538215 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/branches/headerwork

........
  r537245 | dkulp | 2007-05-11 13:45:32 -0400 (Fri, 11 May 2007) | 2 lines
  
  Create a branch to do some header refactoring
........
  r537250 | dkulp | 2007-05-11 13:59:35 -0400 (Fri, 11 May 2007) | 2 lines
  
  Start of header refactor
........
  r537815 | ajaypaibir | 2007-05-14 09:12:03 -0400 (Mon, 14 May 2007) | 1 line
  
  Applying Patch from ulhas related to header work.
........
  r537843 | ajaypaibir | 2007-05-14 09:51:17 -0400 (Mon, 14 May 2007) | 1 line
  
  Applying another patch from ulhas related to header work.
........
  r537890 | eglynn | 2007-05-14 11:48:29 -0400 (Mon, 14 May 2007) | 3 lines
  
  Modified WS-A unit tests to reflect changes to header processing logic in the code.
........
  r537893 | ajaypaibir | 2007-05-14 11:55:38 -0400 (Mon, 14 May 2007) | 1 line
  
  Applying another patch from ulhas related to header work.
........
  r538103 | eglynn | 2007-05-15 05:24:10 -0400 (Tue, 15 May 2007) | 3 lines
  
  Reverted modification to WS-A system test that resulted in config not being picked up.
........
  r538108 | eglynn | 2007-05-15 05:48:10 -0400 (Tue, 15 May 2007) | 3 lines
  
  Minor cleanup in MAPCodecTest.
........
  r538130 | eglynn | 2007-05-15 06:50:47 -0400 (Tue, 15 May 2007) | 3 lines
  
  Some more header-related fixes from Ulhas.
........
  r538131 | eglynn | 2007-05-15 06:53:23 -0400 (Tue, 15 May 2007) | 3 lines
  
  Reverting more unnecessary changes to WS-A system test config. 
........

Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/headers/
      - copied from r537893, incubator/cxf/branches/headerwork/api/src/main/java/org/apache/cxf/headers/
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/headers/Header.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/api/src/main/java/org/apache/cxf/headers/Header.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/headers/HeaderManager.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/api/src/main/java/org/apache/cxf/headers/HeaderManager.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/headers/HeaderProcessor.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/api/src/main/java/org/apache/cxf/headers/HeaderProcessor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/headers/
      - copied from r537893, incubator/cxf/branches/headerwork/rt/core/src/main/java/org/apache/cxf/headers/
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/headers/HeaderManagerImpl.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/rt/core/src/main/java/org/apache/cxf/headers/HeaderManagerImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/
      - copied from r537893, incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/outofband/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/header/
      - copied from r537893, incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/outofband/header/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/header/OOBHdrServiceImpl.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/outofband/header/OOBHdrServiceImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/header/OOBHeaderTest.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/outofband/header/OOBHeaderTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/header/Server.java
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/outofband/header/Server.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/header/cxf.xml
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/systests/src/test/java/org/apache/cxf/systest/outofband/header/cxf.xml
    incubator/cxf/trunk/testutils/src/main/resources/wsdl/oob_headertype.xsd
      - copied unchanged from r537893, incubator/cxf/branches/headerwork/testutils/src/main/resources/wsdl/oob_headertype.xsd
Modified:
    incubator/cxf/trunk/   (props changed)
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/SoapOutInterceptorTest.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
    incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
    incubator/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptor.java
    incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptorTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addressing/HeaderVerifier.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addressing/MAPTestBase.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addressing/Server.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addressing/cxf.xml
    incubator/cxf/trunk/testutils/pom.xml

Propchange: incubator/cxf/trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue May 15 08:52:36 2007
@@ -1 +1 @@
-/incubator/cxf/branches/headerwork:1-537244
+/incubator/cxf/branches/headerwork:1-538215

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Tue May 15 08:52:36 2007
@@ -23,6 +23,8 @@
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.Writer;
+//import java.util.HashMap;
+//import java.util.Map;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.NamespaceContext;
@@ -235,6 +237,10 @@
         XMLStreamReader reader = createXMLStreamReader(doc);
         copy(reader, writer);
     }
+    public static void copy(Element node, XMLStreamWriter writer) throws XMLStreamException {
+        XMLStreamReader reader = createXMLStreamReader(node);
+        copy(reader, writer);
+    }
     
     /**
      * Copies the reader to the writer. The start and end document methods must
@@ -288,6 +294,8 @@
             prefix = "";
         }
 
+        
+//        System.out.println("STAXUTILS:writeStartElement : node name : " + local +  " namespace URI" + uri);
         boolean writeElementNS = false;
         if (uri != null) {
             String boundPrefix = writer.getPrefix(uri);
@@ -338,8 +346,8 @@
             } else {
                 writer.writeNamespace(prefix, uri);
             }
-        }
-
+        }        
+        
         // Write out attributes
         for (int i = 0; i < reader.getAttributeCount(); i++) {
             String ns = reader.getAttributeNamespace(i);
@@ -411,6 +419,8 @@
         String ns = e.getNamespaceURI();
         String localName = e.getLocalName();
 
+       
+//        System.out.println("local name : " + localName + " URI: " + ns + " Prefix :" + prefix);
         if (prefix == null) {
             prefix = "";
         }
@@ -428,6 +438,8 @@
         if (ns == null || ns.length() == 0) {
             writer.writeStartElement(localName);
         } else {
+//            System.out.println("Calling writeStartElement for local name : " 
+//            + localName + " URI: " + ns + " Prefix :" + prefix);
             writer.writeStartElement(prefix, localName, ns);
         }
 
@@ -442,8 +454,10 @@
                 attrPrefix = name.substring(0, prefixIndex);
                 name = name.substring(prefixIndex + 1);
             }
-
+     
             if ("xmlns".equals(attrPrefix)) {
+//                System.out.println("WriteNamespace is called for prefix : " 
+//                + name + " namespace :" + attr.getNodeValue());
                 writer.writeNamespace(name, attr.getNodeValue());
                 if (name.equals(prefix) && attr.getNodeValue().equals(ns)) {
                     declareNamespace = false;
@@ -691,6 +705,9 @@
         }
     }
     
+    public static XMLStreamReader createXMLStreamReader(Element el) {
+        return new W3CDOMStreamReader(el);
+    }
     public static XMLStreamReader createXMLStreamReader(Document doc) {
         return new W3CDOMStreamReader(doc.getDocumentElement());
     }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java Tue May 15 08:52:36 2007
@@ -227,11 +227,11 @@
         }
         
         if (!Boolean.TRUE.equals(binding.getProperty(MESSAGE_PROCESSING_DISABLED))) {
-            sb.getInInterceptors().add(new ReadHeadersInterceptor());
+            sb.getInInterceptors().add(new ReadHeadersInterceptor(getBus()));
             sb.getInInterceptors().add(new MustUnderstandInterceptor());
             sb.getOutInterceptors().add(new SoapPreProtocolOutInterceptor());
-            sb.getOutInterceptors().add(new SoapOutInterceptor());
-            sb.getOutFaultInterceptors().add(new SoapOutInterceptor());
+            sb.getOutInterceptors().add(new SoapOutInterceptor(getBus()));
+            sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
 
             // REVISIT: The phase interceptor chain seems to freak out if this added
             // first. Not sure what the deal is at the moment, I suspect the
@@ -392,7 +392,7 @@
             // This will not work if we one of the endpoints disables message
             // processing. But, if you've disabled message processing, you 
             // probably aren't going to use this feature.
-            newMO.getBindingInterceptors().add(new ReadHeadersInterceptor());
+            newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus()));
 
             // Add in a default selection interceptor
             newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapMessage.java Tue May 15 08:52:36 2007
@@ -19,25 +19,17 @@
 
 package org.apache.cxf.binding.soap;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 
-import javax.xml.parsers.DocumentBuilder;
+import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.headers.Header;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.AbstractWrappedMessage;
 import org.apache.cxf.message.Message;
 
 public class SoapMessage extends AbstractWrappedMessage {
-    private static final DocumentBuilder BUILDER = DOMUtils.createDocumentBuilder();
-
-    
-    private Map<Class<?>, Object> headers = new HashMap<Class<?>, Object>(); 
-    
     private SoapVersion version = Soap11.getInstance();
 
     public SoapMessage(Message message) {
@@ -52,24 +44,34 @@
         this.version = v;
     }
     
-    public <T> boolean hasHeaders(Class<T> format) {
-        return headers.containsKey(format);
+    public List<Header> getHeaders() {
+        List<Header> heads = CastUtils.cast((List<?>)get(Header.HEADER_LIST));
+        if (heads == null) {
+            heads = new ArrayList<Header>();
+            put(Header.HEADER_LIST, heads);
+        }
+        return heads;
     }
     
-    public <T> T getHeaders(Class<T> format) {
-        T t = format.cast(headers.get(format));
-        if (t == null && Element.class.equals(format)) {
-            Document doc = BUILDER.newDocument();
-            Element header = doc.createElementNS(version.getNamespace(),
-                                                 version.getHeader().getLocalPart());
-            header.setPrefix(version.getPrefix());
-            setHeaders(Element.class, header);
-            t = format.cast(header);
+    public boolean hasHeader(QName qn) {
+        for (Header head : getHeaders()) {
+            if (head.getName().equals(qn)) {
+                return true;
+            }
         }
-        return t;
-    }  
-
-    public <T> void setHeaders(Class<T> format, T content) {
-        headers.put(format, content);
+        return false;
+    }
+    public Header getHeader(QName qn) {
+        for (Header head : getHeaders()) {
+            if (head.getName().equals(qn)) {
+                return head;
+            }
+        }
+        return null;
     }
+    
+    public boolean hasHeaders() {
+        return containsKey(Header.HEADER_LIST) && getHeaders().size() > 0;
+    }
+    
 }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java Tue May 15 08:52:36 2007
@@ -20,23 +20,21 @@
 package org.apache.cxf.binding.soap.interceptor;
 
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Element;
-
 import org.apache.cxf.binding.soap.HeaderUtil;
 import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapHeader;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.phase.Phase;
 
@@ -52,13 +50,14 @@
 
     public void handleMessage(SoapMessage soapMessage) {
         SoapVersion soapVersion = soapMessage.getVersion();              
-        Set<Element> mustUnderstandHeaders = new HashSet<Element>();
+        Set<Header> mustUnderstandHeaders = new HashSet<Header>();
         Set<URI> serviceRoles = new HashSet<URI>();
         Set<QName> notUnderstandQNames = new HashSet<QName>();
         Set<QName> mustUnderstandQNames = new HashSet<QName>();
 
         buildMustUnderstandHeaders(mustUnderstandHeaders, soapMessage, serviceRoles);
         initServiceSideInfo(mustUnderstandQNames, soapMessage, serviceRoles);
+        
         if (!checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandQNames)) {
             StringBuffer sb = new StringBuffer(300);
             int pos = 0;
@@ -95,29 +94,12 @@
         }
     }
 
-    private void buildMustUnderstandHeaders(Set<Element> mustUnderstandHeaders, SoapMessage soapMessage,
-                    Set<URI> serviceRoles) {
-        
-        Element headers = null;
-        if (soapMessage.hasHeaders(Element.class)) {
-            headers = soapMessage.getHeaders(Element.class);
-        }
-        List<Element> headerChilds = new ArrayList<Element>();
-        if (headers != null) {
-            for (int i = 0; i < headers.getChildNodes().getLength(); i++) {
-                if (headers.getChildNodes().item(i) instanceof Element) {
-                    headerChilds.add((Element) headers.getChildNodes().item(i));
-                }
-            }            
-        }
-        for (int i = 0; i < headerChilds.size(); i++) {
-            Element header = headerChilds.get(i);
-            String mustUnderstand = header.getAttributeNS(soapMessage.getVersion().getNamespace(),
-                            soapMessage.getVersion().getAttrNameMustUnderstand());
-
-            if (Boolean.valueOf(mustUnderstand) || "1".equals(mustUnderstand.trim())) {
-                String role = header.getAttributeNS(soapMessage.getVersion().getNamespace(), soapMessage
-                                .getVersion().getAttrNameRole());
+    private void buildMustUnderstandHeaders(Set<Header> mustUnderstandHeaders,
+                                            SoapMessage soapMessage,
+                                            Set<URI> serviceRoles) {
+        for (Header header : soapMessage.getHeaders()) {
+            if (header instanceof SoapHeader && ((SoapHeader)header).isMustUnderstand()) {
+                String role = ((SoapHeader)header).getActor();
                 if (role != null) {
                     role = role.trim();
                     if (role.equals(soapMessage.getVersion().getNextRole())
@@ -136,15 +118,15 @@
                     mustUnderstandHeaders.add(header);
                 }
             }
-
         }
     }
 
-    private boolean checkUnderstand(Set<Element> mustUnderstandHeaders, Set<QName> mustUnderstandQNames,
-                    Set<QName> notUnderstandQNames) {
+    private boolean checkUnderstand(Set<Header> mustUnderstandHeaders,
+                                    Set<QName> mustUnderstandQNames,
+                                    Set<QName> notUnderstandQNames) {
 
-        for (Element header : mustUnderstandHeaders) {
-            QName qname = new QName(header.getNamespaceURI(), header.getLocalName());
+        for (Header header : mustUnderstandHeaders) {
+            QName qname = header.getName();
             if (!mustUnderstandQNames.contains(qname)) {
                 notUnderstandQNames.add(qname);
             }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ReadHeadersInterceptor.java Tue May 15 08:52:36 2007
@@ -28,19 +28,26 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapHeader;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.SoapVersionFactory;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.headers.HeaderManager;
+import org.apache.cxf.headers.HeaderProcessor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.PartialXMLStreamReader;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -51,9 +58,11 @@
     private static final Logger LOG = Logger.getLogger(ReadHeadersInterceptor.class.getName());
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ReadHeadersInterceptor.class);
 
-    public ReadHeadersInterceptor() {
+    private Bus bus;
+    public ReadHeadersInterceptor(Bus b) {
         super();
         setPhase(Phase.READ);
+        bus = b;
     }
 
     public void handleMessage(SoapMessage message) {
@@ -90,13 +99,70 @@
                 message.setContent(Node.class, doc);
 
                 // Find header
+                // TODO - we could stream read the "known" headers and just DOM read the 
+                // unknown ones
                 Element element = doc.getDocumentElement();
                 QName header = soapVersion.getHeader();
                 NodeList headerEls = element.getElementsByTagNameNS(header.getNamespaceURI(), header
                     .getLocalPart());
                 for (int i = 0; i < headerEls.getLength(); i++) {
-                    Node node = headerEls.item(i);
-                    message.setHeaders(Element.class, (Element)node);
+                    Node currentHead  = headerEls.item(i);
+                    Node node = currentHead;
+                    NodeList heads = node.getChildNodes();
+                    int len = heads.getLength();
+                    for (int x = 0; x < len; x++) {
+                        node = (Node)heads.item(x);
+                        if (node.getNodeType() == Node.ELEMENT_NODE) {
+                            Element hel = (Element)node;
+                            // Need to add any attributes that are present on the parent element
+                            // which otherwise would be lost.
+                            if (currentHead.hasAttributes()) {
+                                NamedNodeMap nnp = currentHead.getAttributes();
+                                for (int ct = 0; ct < nnp.getLength(); ct++) {
+                                    Node attr = nnp.item(ct);
+                                    Node headerAttrNode = hel.hasAttributes() 
+                                            ?  hel.getAttributes().getNamedItemNS(
+                                                            attr.getNamespaceURI(), attr.getLocalName()) 
+                                            : null;
+                                    
+                                    if (headerAttrNode == null) {
+                                        Attr attribute = hel.getOwnerDocument().createAttributeNS(
+                                                attr.getNamespaceURI(), 
+                                                attr.getNodeName());
+                                        attribute.setNodeValue(attr.getNodeValue());
+                                        hel.setAttributeNodeNS(attribute);
+                                    }
+                                }
+                            }
+                            
+//                            System.out.println("READHEADERSINTERCEPTOR : node name : " 
+//                            + node.getLocalName() +  " namespace URI" + node.getNamespaceURI());
+                            HeaderProcessor p = bus.getExtension(HeaderManager.class)
+                                .getHeaderProcessor(hel.getNamespaceURI());
+
+                            Object obj;
+                            DataBinding dataBinding = null;
+                            if (p == null || p.getDataBinding() == null) {
+                                obj = node;
+                            } else {
+                                obj = p.getDataBinding().createReader(Node.class).read(node);
+                            }
+                            //TODO - add the interceptors
+                            
+                            SoapHeader shead = new SoapHeader(new QName(node.getNamespaceURI(),
+                                                                        node.getLocalName()),
+                                                               obj,
+                                                               dataBinding);
+                            String mu = hel.getAttributeNS(soapVersion.getNamespace(),
+                                                          soapVersion.getAttrNameMustUnderstand());
+                            String act = hel.getAttributeNS(soapVersion.getNamespace(),
+                                                            soapVersion.getAttrNameRole());
+                            
+                            shead.setActor(act);
+                            shead.setMustUnderstand(Boolean.valueOf(mu) || "1".equals(mu));
+                            message.getHeaders().add(shead);
+                        }                        
+                    }
                 }
 
                 // advance just past body.

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java Tue May 15 08:52:36 2007
@@ -22,14 +22,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.model.SoapHeaderInfo;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
 import org.apache.cxf.interceptor.BareInInterceptor;
@@ -82,15 +79,20 @@
             return;
         }
         
-        Element headerElement = message.getHeaders(Element.class);
         for (SoapHeaderInfo header : headers) {
             MessagePartInfo mpi = header.getPart();
-            Element param = findHeader(headerElement, mpi);
+            Header param = findHeader(message, mpi);
             
             int idx = mpi.getIndex();
             Object object = null;
             if (param != null) {
-                object = getNodeDataReader(message).read(mpi, param);
+                if (param.getDataBinding() == null) {
+                    Node source = (Node)param.getObject();
+                    object = getNodeDataReader(message).read(mpi, source);
+                } else {
+                    object = param.getObject();
+                }
+                
             }
             
             if (client) {
@@ -112,21 +114,7 @@
         }
     }
 
-    private Element findHeader(Element headerElement, MessagePartInfo mpi) {
-        NodeList nodeList = headerElement.getChildNodes();
-        Element param = null;
-        if (nodeList != null) {
-            QName name = mpi.getConcreteName();
-            for (int i = 0; i < nodeList.getLength(); i++) {
-                Node n = nodeList.item(i);
-                if (n.getNamespaceURI() != null 
-                        && n.getNamespaceURI().equals(name.getNamespaceURI())
-                        && n.getLocalName() != null
-                        && n.getLocalName().equals(name.getLocalPart())) {
-                    param = (Element) n;
-                }
-            }
-        }
-        return param;
+    private Header findHeader(SoapMessage message, MessagePartInfo mpi) {
+        return message.getHeader(mpi.getConcreteName());
     }
 }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapOutInterceptor.java Tue May 15 08:52:36 2007
@@ -29,12 +29,17 @@
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.model.SoapHeaderInfo;
 import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.headers.Header;
+import org.apache.cxf.headers.HeaderManager;
+import org.apache.cxf.headers.HeaderProcessor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
@@ -49,10 +54,12 @@
 
 public class SoapOutInterceptor extends AbstractSoapInterceptor {
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(SoapOutInterceptor.class);
-
-    public SoapOutInterceptor() {
+    private Bus bus;
+    
+    public SoapOutInterceptor(Bus b) {
         super();
         setPhase(Phase.WRITE);
+        bus = b;
     }
     
     public void handleMessage(SoapMessage message) {
@@ -65,12 +72,28 @@
                                   soapVersion.getNamespace());
             xtw.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
             
-            boolean preexistingHeaders = false;
-            if (message.hasHeaders(Element.class)) {
-                Element eleHeaders = message.getHeaders(Element.class);
-                preexistingHeaders = eleHeaders != null && eleHeaders.hasChildNodes();
-                if (preexistingHeaders) {
-                    StaxUtils.writeElement(eleHeaders, xtw, true, false);
+            boolean preexistingHeaders = message.hasHeaders();
+            if (preexistingHeaders) {
+                xtw.writeStartElement(soapVersion.getPrefix(), 
+                                      soapVersion.getHeader().getLocalPart(),
+                                      soapVersion.getNamespace());   
+                List<Header> hdrList = message.getHeaders();
+                for (Header header : hdrList) {
+                    DataBinding b = header.getDataBinding();
+                    if (b == null) {
+                        HeaderProcessor hp = bus.getExtension(HeaderManager.class)
+                                .getHeaderProcessor(header.getName().getNamespaceURI());
+                        if (hp != null) {
+                            b = hp.getDataBinding();
+                        }
+                    }
+                    if (b != null) {
+                        b.createWriter(XMLStreamWriter.class)
+                            .write(header.getObject(), xtw);
+                    } else {
+                        Element node = (Element)header.getObject();
+                        StaxUtils.copy(node, xtw);
+                    }
                 }
             }
             boolean endedHeader = handleHeaderPart(preexistingHeaders, message);

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java Tue May 15 08:52:36 2007
@@ -23,6 +23,7 @@
 import java.util.Collection;
 import java.util.ResourceBundle;
 
+import javax.xml.namespace.QName;
 import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPConstants;
@@ -36,11 +37,18 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapHeader;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
 import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.headers.Header;
+import org.apache.cxf.headers.HeaderManager;
+import org.apache.cxf.headers.HeaderProcessor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.phase.Phase;
@@ -86,9 +94,45 @@
             }
             
             //replace header element if necessary
-            if (message.hasHeaders(Element.class)) {
-                Element headerElements = soapMessage.getSOAPHeader();    
-                message.setHeaders(Element.class, headerElements);
+            if (message.hasHeaders()) {
+                NodeList headerEls = soapMessage.getSOAPHeader().getChildNodes();
+                int len = headerEls.getLength();
+                for (int i = 0; i < len; i++) {
+                    Node nd = headerEls.item(i);
+                    if (Node.ELEMENT_NODE == nd.getNodeType()) {
+                        Element hel = (Element)nd;
+                        HeaderProcessor p = BusFactory.getDefaultBus().getExtension(HeaderManager.class)
+                            .getHeaderProcessor(hel.getNamespaceURI());
+
+                        Object obj;
+                        DataBinding dataBinding = null;
+                        if (p == null || p.getDataBinding() == null) {
+                            obj = nd;
+                        } else {
+                            obj = p.getDataBinding().createReader(Node.class).read(nd);
+                        }
+                        //TODO - add the interceptors
+                        
+                        SoapHeader shead = new SoapHeader(new QName(nd.getNamespaceURI(),
+                                nd.getLocalName()),
+                                                           obj,
+                                                           dataBinding);
+                        String mu = hel.getAttributeNS(message.getVersion().getNamespace(),
+                                message.getVersion().getAttrNameMustUnderstand());
+                        String act = hel.getAttributeNS(message.getVersion().getNamespace(),
+                                message.getVersion().getAttrNameRole());
+                        
+                        shead.setActor(act);
+                        shead.setMustUnderstand(Boolean.valueOf(mu) || "1".equals(mu));
+                        Header oldHdr = message.getHeader(
+                                new QName(nd.getNamespaceURI(), nd.getLocalName()));
+                        if (oldHdr != null) {
+                            message.getHeaders().remove(oldHdr);
+                        } 
+                        message.getHeaders().add(shead);
+                        
+                    }
+                }
             }
             
             XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java Tue May 15 08:52:36 2007
@@ -29,6 +29,8 @@
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.attachment.AttachmentUtil;
 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
@@ -52,8 +54,10 @@
     public void setUp() throws Exception {
 
         super.setUp();
+        
+        Bus bus = BusFactory.getDefaultBus();
 
-        rhi = new ReadHeadersInterceptor();
+        rhi = new ReadHeadersInterceptor(bus);
         rhi.setPhase("phase1");
         chain.add(rhi);
 

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ReadHeaderInterceptorTest.java Tue May 15 08:52:36 2007
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.activation.DataHandler;
@@ -30,9 +31,11 @@
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.attachment.AttachmentUtil;
 import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.interceptor.StaxInInterceptor;
 import org.apache.cxf.message.Attachment;
 
@@ -44,7 +47,7 @@
     public void setUp() throws Exception {
         super.setUp();
 
-        rhi = new ReadHeadersInterceptor();
+        rhi = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
         rhi.setPhase("phase1");
         chain.add(rhi);
     }
@@ -56,7 +59,7 @@
         ByteArrayDataSource bads = new ByteArrayDataSource(in, "test/xml");
         soapMessage.setContent(InputStream.class, bads.getInputStream());
 
-        ReadHeadersInterceptor r = new ReadHeadersInterceptor();
+        ReadHeadersInterceptor r = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
         try {
             r.handleMessage(soapMessage);
             fail("Did not throw exception");
@@ -78,14 +81,23 @@
         XMLStreamReader xmlReader = soapMessage.getContent(XMLStreamReader.class);
         assertEquals("check the first entry of body", "itinerary", xmlReader.getLocalName());
         
-        Element eleHeaders = soapMessage.getHeaders(Element.class);
+        List<Header> eleHeaders = soapMessage.getHeaders();
+        
         List<Element> headerChilds = new ArrayList<Element>();
-        for (int i = 0; i < eleHeaders.getChildNodes().getLength(); i++) {
-            if (eleHeaders.getChildNodes().item(i) instanceof Element) {
-                Element element = (Element)eleHeaders.getChildNodes().item(i);
-                headerChilds.add(element);
+        Iterator<Header> iter = eleHeaders.iterator();
+        while (iter.hasNext()) {
+            Header hdr = iter.next();
+
+            if (hdr.getObject() instanceof Element) {
+                headerChilds.add((Element) hdr.getObject());
             }
         }
+//        for (int i = 0; i < eleHeaders.getChildNodes().getLength(); i++) {
+//            if (eleHeaders.getChildNodes().item(i) instanceof Element) {
+//                Element element = (Element)eleHeaders.getChildNodes().item(i);
+//                headerChilds.add(element);
+//            }
+//        }
 
         assertEquals(2, headerChilds.size());
         for (int i = 0; i < headerChilds.size(); i++) {

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/SoapOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/SoapOutInterceptorTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/SoapOutInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/SoapOutInterceptorTest.java Tue May 15 08:52:36 2007
@@ -28,8 +28,7 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
-import org.w3c.dom.Element;
-
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
 import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
 import org.apache.cxf.interceptor.StaxInInterceptor;
@@ -45,11 +44,11 @@
         sii.setPhase("phase1");
         chain.add(sii);
 
-        rhi = new ReadHeadersInterceptor();
+        rhi = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
         rhi.setPhase("phase2");
         chain.add(rhi);
 
-        soi = new SoapOutInterceptor();
+        soi = new SoapOutInterceptor(BusFactory.getDefaultBus());
         soi.setPhase("phase3");
         chain.add(soi);
     }
@@ -63,7 +62,7 @@
         
         soapMessage.getInterceptorChain().doIntercept(soapMessage);
         
-        assertNotNull(soapMessage.getHeaders(Element.class));
+        assertNotNull(soapMessage.getHeaders());
 
         Exception oe = (Exception)soapMessage.getContent(Exception.class);
         if (oe != null) {

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptorTest.java Tue May 15 08:52:36 2007
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.mail.util.ByteArrayDataSource;
@@ -29,10 +30,12 @@
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.TestBase;
 import org.apache.cxf.binding.soap.TestUtil;
 import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.interceptor.StaxInInterceptor;
 
 
@@ -45,7 +48,7 @@
     public void setUp() throws Exception {
         super.setUp();
 
-        rhi = new ReadHeadersInterceptor();
+        rhi = new ReadHeadersInterceptor(BusFactory.getDefaultBus());
         rhi.setPhase("phase1");
         chain.add(rhi);
 
@@ -71,14 +74,23 @@
         XMLStreamReader xmlReader = soapMessage.getContent(XMLStreamReader.class);
         assertEquals("check the first entry of body", "itinerary", xmlReader.getLocalName());
 
-        Element eleHeaders = soapMessage.getHeaders(Element.class);
+        List<Header> eleHeaders = soapMessage.getHeaders();
         List<Element> headerChilds = new ArrayList<Element>();
-        for (int i = 0; i < eleHeaders.getChildNodes().getLength(); i++) {
-            if (eleHeaders.getChildNodes().item(i) instanceof Element) {
-                Element element = (Element)eleHeaders.getChildNodes().item(i);
-                headerChilds.add(element);
+        Iterator<Header> iter = eleHeaders.iterator();
+        
+        while (iter.hasNext()) {
+            Header hdr = iter.next();
+
+            if (hdr.getObject() instanceof Element) {
+                headerChilds.add((Element) hdr.getObject());
             }
         }
+//        for (int i = 0; i < eleHeaders.getChildNodes().getLength(); i++) {
+//            if (eleHeaders.getChildNodes().item(i) instanceof Element) {
+//                Element element = (Element)eleHeaders.getChildNodes().item(i);
+//                headerChilds.add(element);
+//            }
+//        }
 
         assertEquals(2, headerChilds.size());
     }

Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml (original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml Tue May 15 08:52:36 2007
@@ -39,5 +39,7 @@
        	   interface="org.apache.cxf.transports.http.QueryHandlerRegistry"/> 
     <extension class="org.apache.cxf.endpoint.EndpointResolverRegistryImpl"
        	   interface="org.apache.cxf.endpoint.EndpointResolverRegistry"/>
+    <extension class="org.apache.cxf.headers.HeaderManagerImpl"
+       	   interface="org.apache.cxf.headers.HeaderManager"/>
            
 </extensions>

Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml (original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Tue May 15 08:52:36 2007
@@ -99,4 +99,7 @@
     <bean id="org.apache.cxf.endpoint.EndpointResolverRegistry" class="org.apache.cxf.endpoint.EndpointResolverRegistryImpl">
         <property name="bus" ref="cxf"/>
     </bean>
+    <bean id="org.apache.cxf.headers.HeaderManager" class="org.apache.cxf.headers.HeaderManagerImpl">
+        <property name="bus" ref="cxf"/>
+    </bean>
 </beans>

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java (original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java Tue May 15 08:52:36 2007
@@ -26,6 +26,7 @@
 
 import org.junit.After;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class AutomaticWorkQueueTest extends Assert {
@@ -326,6 +327,7 @@
     }
 
     @Test
+    @Ignore
     public void testShutdown() {
         workqueue = new AutomaticWorkQueueImpl(DEFAULT_MAX_QUEUE_SIZE, INITIAL_SIZE,
                                                INITIAL_SIZE, INITIAL_SIZE, 250);

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/soap/SOAPMessageContextImpl.java Tue May 15 08:52:36 2007
@@ -19,22 +19,20 @@
 
 package org.apache.cxf.jaxws.handler.soap;
 
-import java.util.ArrayList;
-import java.util.Collection;
+
+import java.util.List;
 import java.util.Set;
 
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPMessageContext;
 
-import org.w3c.dom.Element;
-
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.XMLMessage;
@@ -80,25 +78,29 @@
 
     // TODO: handle the boolean parameter
     public Object[] getHeaders(QName name, JAXBContext context, boolean allRoles) {
-        Element headerElements = getWrappedSoapMessage().getHeaders(Element.class);
+//        Element headerElements = getWrappedSoapMessage().getHeaders(Element.class);
+        List<Header> headerElements = getWrappedSoapMessage().getHeaders();
         if (headerElements == null) {
             return null;
         }
-        Collection<Object> objects = new ArrayList<Object>();
-        for (int i = 0; i < headerElements.getChildNodes().getLength(); i++) {
-            if (headerElements.getChildNodes().item(i) instanceof Element) {
-                Element e = (Element)headerElements.getChildNodes().item(i);
-                if (name.equals(e.getNamespaceURI())) {
-                    try {
-                        objects.add(context.createUnmarshaller().unmarshal(e));
-                    } catch (JAXBException ex) {
-                        // do something
-                    }
-                }
-            }
-        }
-        Object[] headerObjects = new Object[objects.size()];
-        return objects.toArray(headerObjects);
+        
+        
+//        Collection<Object> objects = new ArrayList<Object>();
+//        for (int i = 0; i < headerElements.getChildNodes().getLength(); i++) {
+//            if (headerElements.getChildNodes().item(i) instanceof Element) {
+//                Element e = (Element)headerElements.getChildNodes().item(i);
+//                if (name.equals(e.getNamespaceURI())) {
+//                    try {
+//                        objects.add(context.createUnmarshaller().unmarshal(e));
+//                    } catch (JAXBException ex) {
+//                        // do something
+//                    }
+//                }
+//            }
+//        }
+//        Object[] headerObjects = new Object[objects.size()];
+//        return objects.toArray(headerObjects);
+        return headerElements.toArray();
     }
 
     public Set<String> getRoles() {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java Tue May 15 08:52:36 2007
@@ -21,6 +21,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -30,8 +31,10 @@
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.handler.MessageContext;
 
+import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
@@ -194,6 +197,18 @@
         //get the context response code and setback to out message
         if (ctx.containsKey(MessageContext.HTTP_RESPONSE_CODE)) {
             exchange.getOutMessage().put(Message.RESPONSE_CODE, ctx.get(MessageContext.HTTP_RESPONSE_CODE));
+        }
+        
+        // Guard against wrong type associated with header list.
+        // Need to copy header only if the message is going out.
+        if (ctx.containsKey(Header.HEADER_LIST) 
+                && ctx.get(Header.HEADER_LIST) instanceof List<?> 
+                && exchange.getOutMessage() instanceof SoapMessage) {
+            SoapMessage sm = (SoapMessage) exchange.getOutMessage();
+            Iterator iter = ((List) ctx.get(Header.HEADER_LIST)).iterator();
+            while (iter.hasNext()) {
+                sm.getHeaders().add((Header) iter.next());
+            }
         }
     }
    

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptorTest.java Tue May 15 08:52:36 2007
@@ -58,6 +58,7 @@
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.SoapVersionFactory;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.io.AbstractCachedOutputStream;
@@ -193,8 +194,7 @@
                         // change mustUnderstand to false
                         SOAPMessage message = smc.getMessage();
                         SOAPHeader soapHeader = message.getSOAPHeader();
-                        Iterator it = soapHeader.getChildElements();
-                        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)it.next();
+                        Element headerElementNew = (Element)soapHeader.getChildNodes().item(0);
 
                         SoapVersion soapVersion = Soap11.getInstance();
                         headerElementNew.setAttributeNS(soapVersion.getNamespace(),
@@ -231,8 +231,13 @@
         XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
         message.setContent(XMLStreamReader.class, reader);
         Object[] headerInfo = preparemSOAPHeader();
-        message.setHeaders(Element.class, (Element) headerInfo[1]);
-        message.setContent(Node.class, (Document) headerInfo[0]);
+        
+        message.setContent(Node.class, headerInfo[0]);
+        
+        Node node = ((Element) headerInfo[1]).getChildNodes().item(0);
+        
+        message.getHeaders().add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node));
+        
         control.replay();
 
         SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
@@ -241,9 +246,10 @@
 
         // Verify SOAPMessage header
         SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);
-        SOAPHeader soapHeader = soapMessageNew.getSOAPHeader();
-        Iterator itNew = soapHeader.getChildElements();
-        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)itNew.next();
+        NodeList headerEls = soapMessageNew.getSOAPHeader().getChildNodes();
+
+        Element headerElementNew = (Element)headerEls.item(0);
+        
         SoapVersion soapVersion = Soap11.getInstance();
         assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
 
@@ -253,11 +259,22 @@
         assertEquals("sendReceiveData", qn.getLocalPart());
         
         // Verify Header Element
-        Element element = message.getHeaders(Element.class);      
-        NodeList headerNodeList = element.getElementsByTagNameNS(
-            "http://apache.org/hello_world_rpclit/types", "header1");
-        Element headerElementNew1 = (Element)headerNodeList.item(0);
-        assertEquals("false", headerElementNew1.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
+        Iterator<Header> iter = message.getHeaders().iterator();
+        Element requiredHeader = null;
+        while (iter.hasNext()) {
+            Header localHdr = iter.next();
+            if (localHdr.getObject() instanceof Element) {
+                Element elem = (Element) localHdr.getObject();
+                if (elem.getNamespaceURI().equals("http://apache.org/hello_world_rpclit/types")
+                        && elem.getLocalName().equals("header1")) {
+                    requiredHeader = (Element) localHdr.getObject();
+                    break;                
+                }
+            }
+        }
+        
+        assertNotNull("Should have found header1", requiredHeader);
+        assertEquals("false", requiredHeader.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
     }
 
     public void testChangeSOAPHeaderOutBound() throws Exception {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/support/ContextPropertiesMappingTest.java Tue May 15 08:52:36 2007
@@ -18,9 +18,11 @@
  */
 package org.apache.cxf.jaxws.support;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
 import javax.activation.DataHandler;
@@ -32,6 +34,7 @@
 import junit.framework.TestCase;
 
 import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
@@ -119,6 +122,7 @@
     public void testUpdateWebServiceContext() {
         Exchange xchng = new ExchangeImpl();
         Message outMsg = new MessageImpl();
+        List<Header> hdrList = new ArrayList<Header>();
         xchng.setOutMessage(outMsg);
         
         responseContext.put(MessageContext.HTTP_RESPONSE_CODE, RESPONSE_CODE);
@@ -128,6 +132,14 @@
         EasyMock.expectLastCall().andReturn(true);
         ctx.get(MessageContext.HTTP_RESPONSE_CODE);
         EasyMock.expectLastCall().andReturn(RESPONSE_CODE);
+        
+        ctx.containsKey(Header.HEADER_LIST);
+        EasyMock.expectLastCall().andReturn(true);
+        ctx.get(Header.HEADER_LIST);
+        EasyMock.expectLastCall().andReturn(hdrList);
+        ctx.get(Header.HEADER_LIST);
+        EasyMock.expectLastCall().andReturn(hdrList);
+        
         EasyMock.replay(ctx);
         
         ContextPropertiesMapping.updateWebServiceContext(xchng, ctx);

Modified: incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java (original)
+++ incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java Tue May 15 08:52:36 2007
@@ -19,10 +19,10 @@
 
 package org.apache.cxf.ws.addressing.soap;
 
-
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -37,16 +37,20 @@
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.SoapVersion;
 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
@@ -78,6 +82,7 @@
         Collections.synchronizedMap(new HashMap<String, Exchange>());
 
     private VersionTransformer transformer;
+    private HeaderFactory headerFactory;
     
     /**
      * Constructor.
@@ -141,13 +146,10 @@
             cacheExchange(message, maps);
             LOG.log(Level.INFO, "Outbound WS-Addressing headers");
             try {
-                Element header = message.getHeaders(Element.class);
+                List<Header> header = message.getHeaders();
                 discardMAPs(header, maps);
-                // add WSA namespace declaration to header, instead of
-                // repeating in each individual child node
-                header.setAttributeNS("http://www.w3.org/2000/xmlns/",
-                                      "xmlns:" + Names.WSA_NAMESPACE_PREFIX,
-                                      maps.getNamespaceURI());
+
+                Element hdr = getHeaderFactory().getHeader(message.getVersion());                
                 JAXBContext jaxbContext = 
                     VersionTransformer.getExposedJAXBContext(
                                                      maps.getNamespaceURI());
@@ -157,39 +159,58 @@
                                 maps.getMessageID(), 
                                 Names.WSA_MESSAGEID_NAME,
                                 AttributedURIType.class, 
-                                header, 
+                                hdr, 
                                 marshaller);
                 encodeAsExposed(maps.getNamespaceURI(),
                                 maps.getTo(), 
                                 Names.WSA_TO_NAME,
                                 AttributedURIType.class,  
-                                header, 
+                                hdr, 
                                 marshaller);
                 encodeAsExposed(maps.getNamespaceURI(),
                                 maps.getReplyTo(), 
                                 Names.WSA_REPLYTO_NAME, 
                                 EndpointReferenceType.class,
-                                header,
+                                hdr,
                                 marshaller);
                 encodeAsExposed(maps.getNamespaceURI(),
                                 maps.getFaultTo(), 
                                 Names.WSA_FAULTTO_NAME, 
                                 EndpointReferenceType.class,
-                                header,
+                                hdr,
                                 marshaller);
                 encodeAsExposed(maps.getNamespaceURI(),
                                 maps.getRelatesTo(),
                                 Names.WSA_RELATESTO_NAME,
                                 RelatesToType.class,
-                                header,
+                                hdr,
                                 marshaller);
                 encodeAsExposed(maps.getNamespaceURI(),
                                 maps.getAction(), 
                                 Names.WSA_ACTION_NAME,
                                 AttributedURIType.class, 
-                                header, 
+                                hdr, 
                                 marshaller);
-                encodeReferenceParameters(maps, header, marshaller);
+                encodeReferenceParameters(maps, hdr, marshaller);
+                
+                NodeList children = hdr.getChildNodes();
+                int len = children.getLength();
+                for (int i = 0; i < len; i++) {
+                    Node node = children.item(i);
+                    
+                    if (node instanceof Element) {
+                        ((Element) node).setAttributeNS("http://www.w3.org/2000/xmlns/",
+                                "xmlns:" + Names.WSA_NAMESPACE_PREFIX,
+                                maps.getNamespaceURI());
+                    }
+              
+                    Header holder = new Header(
+                            new QName(node.getNamespaceURI(), node.getLocalName()), 
+                            node);
+                    header.add(holder);
+                }
+                
+                
                 propogateAction(maps.getAction(), message);
                 applyMAPValidation(message);
             } catch (JAXBException je) {
@@ -216,8 +237,8 @@
                         } else {
                             jaxbEl = (JAXBElement) o;
                         }
-
                         marshaller.marshal(jaxbEl, header);
+                        
                         Element lastAdded = (Element)header.getLastChild();
                         addIsReferenceParameterMarkerAttribute(lastAdded);
                     } else {
@@ -278,24 +299,28 @@
         // expected header is missing 
         AddressingPropertiesImpl maps = null;
         try {
-            Element header = message.getHeaders(Element.class);
+            List<Header> header = message.getHeaders();
             if (header != null) {
                 LOG.log(Level.INFO, "Inbound WS-Addressing headers");
                 Unmarshaller unmarshaller = null;
                 Set<Element> referenceParameterHeaders = null;
-                NodeList headerElements = header.getChildNodes();
-                int headerCount = headerElements.getLength();
-                for (int i = 0; i < headerCount; i++) {
-                    if (headerElements.item(i) instanceof Element) {
-                        Element headerElement = (Element)headerElements.item(i);
+
+                Iterator<Header> iter = header.iterator();
+                while (iter.hasNext()) {
+                    Header hdr = iter.next();
+                    if (hdr.getObject() instanceof Element) {
+                        Element headerElement = (Element)hdr.getObject();
                         String headerURI = headerElement.getNamespaceURI();
-                        if (unmarshaller == null) {
-                            JAXBContext jaxbContext = 
-                                VersionTransformer.getExposedJAXBContext(headerURI);
-                            unmarshaller = 
-                                jaxbContext.createUnmarshaller();
-                        }
+                        // Need to check the uri before getting unmarshaller else
+                        // would get wrong unmarshaller and fail to process required
+                        // headers.
                         if (transformer.isSupported(headerURI)) {
+                            if (unmarshaller == null) {
+                                JAXBContext jaxbContext = 
+                                    VersionTransformer.getExposedJAXBContext(headerURI);
+                                unmarshaller = 
+                                    jaxbContext.createUnmarshaller();
+                            }
                             if (maps == null) {
                                 maps = new AddressingPropertiesImpl();
                                 maps.exposeAs(headerURI);
@@ -479,7 +504,15 @@
      * @param header the SOAP header
      * @param maps the current MAPs
      */
-    private void discardMAPs(Element header, AddressingProperties maps) {
+    private void discardMAPs(List<Header> header, AddressingProperties maps) {
+        Iterator<Header> iter = header.iterator();
+        while (iter.hasNext()) {
+            Header hdr = iter.next();
+            if (Names.WSA_NAMESPACE_NAME.equals(hdr.getName().getNamespaceURI())) {
+                iter.remove();
+            }
+        }
+        /*
         NodeList headerElements =
             header.getElementsByTagNameNS(maps.getNamespaceURI(), "*");        
         for (int i = 0; i < headerElements.getLength(); i++) {
@@ -487,7 +520,7 @@
             if (Names.WSA_NAMESPACE_NAME.equals(headerElement.getNamespaceURI())) {
                 header.removeChild(headerElement);
             }
-        }
+        } */
     }
 
     /**
@@ -599,8 +632,29 @@
             message.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
         } 
     }
+    
+    protected HeaderFactory getHeaderFactory() {
+        if (headerFactory == null) {
+            headerFactory = new HeaderFactory() {
+                public Element getHeader(SoapVersion soapversion) {
+                    Document doc = DOMUtils.createDocument();
+                    return doc.createElementNS(soapversion.getHeader().getNamespaceURI(),
+                            soapversion.getHeader().getLocalPart());
+                }
+            };
+        }
+        return headerFactory;
+    }
+    
+    protected void setHeaderFactory(HeaderFactory factory) {
+        headerFactory = factory;
+    }
 
+    public interface HeaderFactory {
+        Element getHeader(SoapVersion soapversion);
+    }
 }
+
 
 
 

Modified: incubator/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java?view=diff&rev=538231&r1=538230&r2=538231
==============================================================================
--- incubator/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java (original)
+++ incubator/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java Tue May 15 08:52:36 2007
@@ -39,6 +39,8 @@
 
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.SoapVersion;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -242,8 +244,13 @@
         message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
         String mapProperty = getMAPProperty(requestor, outbound);
         AddressingPropertiesImpl maps = getMAPs(requestor, outbound, exposeAs);
-        Element header = control.createMock(Element.class);
-        message.setHeaders(Element.class, header);
+        final Element header = control.createMock(Element.class);
+        codec.setHeaderFactory(new MAPCodec.HeaderFactory() {
+            public Element getHeader(SoapVersion version) {
+                return header;
+            }
+        });
+        List<Header> headers = message.getHeaders();
         JAXBContext jaxbContext = control.createMock(JAXBContext.class);
         ContextUtils.setJAXBContext(jaxbContext);
         VersionTransformer.Names200408.setJAXBContext(jaxbContext);
@@ -256,7 +263,7 @@
                         invalidMAP,
                         preExistingSOAPAction);
         } else {
-            setUpDecode(message, header, maps, mapProperty, requestor);
+            setUpDecode(message, headers, maps, mapProperty, requestor);
         }
         control.replay();
         return message;
@@ -270,16 +277,6 @@
                              boolean invalidMAP,
                              boolean preExistingSOAPAction) throws Exception { 
         message.put(mapProperty, maps);
-        NodeList headerElements = control.createMock(NodeList.class);
-        header.getElementsByTagNameNS(EasyMock.eq(maps.getNamespaceURI()),
-                                      EasyMock.eq("*"));
-        EasyMock.expectLastCall().andReturn(headerElements);
-        headerElements.getLength();
-        EasyMock.expectLastCall().andReturn(0);
-        header.setAttributeNS(EasyMock.eq("http://www.w3.org/2000/xmlns/"),
-                              EasyMock.eq("xmlns:" + Names.WSA_NAMESPACE_PREFIX),
-                              EasyMock.eq(maps.getNamespaceURI()));
-        EasyMock.expectLastCall();
         Marshaller marshaller = control.createMock(Marshaller.class);
         ContextUtils.getJAXBContext().createMarshaller();
         EasyMock.expectLastCall().andReturn(marshaller);
@@ -295,6 +292,26 @@
             marshaller.marshal(null, header);
             EasyMock.expectLastCall();
         }
+        
+        NodeList children = control.createMock(NodeList.class);
+        header.getChildNodes();
+        EasyMock.expectLastCall().andReturn(children);
+        children.getLength();
+        EasyMock.expectLastCall().andReturn(expectedMarshals).anyTimes();
+        for (int i = 0; i < expectedMarshals; i++) {
+            Element child = control.createMock(Element.class);
+            children.item(i);
+            EasyMock.expectLastCall().andReturn(child);
+            child.setAttributeNS(EasyMock.eq("http://www.w3.org/2000/xmlns/"),
+                                 EasyMock.eq("xmlns:" + Names.WSA_NAMESPACE_PREFIX),
+                                 EasyMock.eq(maps.getNamespaceURI()));
+            EasyMock.expectLastCall();
+            child.getNamespaceURI();
+            EasyMock.expectLastCall().andReturn(expectedNames[i].getNamespaceURI());
+            child.getLocalName();
+            EasyMock.expectLastCall().andReturn(expectedNames[i].getLocalPart());
+        }
+        
         mimeHeaders = new HashMap<String, List<String>>();
         message.put(MIME_HEADERS, mimeHeaders);
         if (preExistingSOAPAction) {
@@ -311,25 +328,20 @@
     }
     
     private void setUpDecode(SoapMessage message, 
-                             Element header,
+                             List<Header> headers,
                              AddressingPropertiesImpl maps,
                              String mapProperty,
                              boolean requestor) throws Exception {
         Unmarshaller unmarshaller = control.createMock(Unmarshaller.class);
         ContextUtils.getJAXBContext().createUnmarshaller();
         EasyMock.expectLastCall().andReturn(unmarshaller);
-        NodeList headerElements = control.createMock(NodeList.class);
-        header.getChildNodes();
-        EasyMock.expectLastCall().andReturn(headerElements);
         String uri = maps.getNamespaceURI();
         boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
         boolean exposedAs200408 = 
             VersionTransformer.Names200408.WSA_NAMESPACE_NAME.equals(uri);
         assertTrue("unexpected namescape URI: " + uri, 
                    exposedAsNative || exposedAs200408);
-        headerElements.getLength();
-        EasyMock.expectLastCall().andReturn(6);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_MESSAGEID_NAME,
                           exposedAsNative
@@ -337,7 +349,7 @@
                           : AttributedURI.class,
                           0,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_TO_NAME,
                           exposedAsNative
@@ -345,7 +357,7 @@
                           : AttributedURI.class,
                           1,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_REPLYTO_NAME,
                           exposedAsNative
@@ -353,7 +365,7 @@
                           : VersionTransformer.Names200408.EPR_TYPE,
                           2,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_FAULTTO_NAME,
                           exposedAsNative
@@ -361,7 +373,7 @@
                           : VersionTransformer.Names200408.EPR_TYPE,
                           3,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_RELATESTO_NAME,
                           exposedAsNative
@@ -369,7 +381,7 @@
                           : Relationship.class,
                           4,
                           unmarshaller);
-        setUpHeaderDecode(headerElements,
+        setUpHeaderDecode(headers,
                           uri,
                           Names.WSA_ACTION_NAME,
                           exposedAsNative
@@ -379,7 +391,7 @@
                           unmarshaller);
     }
 
-    private <T> void setUpHeaderDecode(NodeList headerElements,
+    private <T> void setUpHeaderDecode(List<Header> headers,
                                        String uri,
                                        String name,
                                        Class<T> clz,
@@ -387,8 +399,7 @@
                                        Unmarshaller unmarshaller) 
         throws Exception { 
         Element headerElement = control.createMock(Element.class);
-        headerElements.item(index);
-        EasyMock.expectLastCall().andReturn(headerElement).times(2);
+        headers.add(new Header(new QName(uri, name), headerElement));
         headerElement.getNamespaceURI();
         EasyMock.expectLastCall().andReturn(uri);
         headerElement.getLocalName();
@@ -525,7 +536,7 @@
         }
 
         public void appendTo(StringBuffer buffer) {
-            buffer.append("JAXBElements did not match");
+            buffer.append("JAXBElements did not match[" + expectedIndex + "]");
         }
         
         private boolean compare(Object a, Object b) {
@@ -635,6 +646,18 @@
                 assertSame("unexpected correlated exchange",
                            correlatedExchange,
                            message.getExchange());
+            }
+        }
+        if (outbound) {
+            int expectedMarshals = requestor 
+                                   ? expectedValues.length - 1
+                                   : expectedValues.length;
+            List<Header> headers = message.getHeaders();
+            assertTrue("expected holders added to header list",
+                       headers.size() >= expectedMarshals);
+            for (int i = 0; i < expectedMarshals; i++) {
+                assertTrue("expected " + expectedNames[i] + " added to headers",
+                           message.hasHeader(expectedNames[i]));
             }
         }
         assertTrue("unexpected MAPs",



Mime
View raw message