ODE-716: Fixed soap header processing
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/SoapHeader2Test.java b/axis2-war/src/test/java/org/apache/ode/axis2/SoapHeader2Test.java
index ff89168..5873fce 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/SoapHeader2Test.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/SoapHeader2Test.java
@@ -23,25 +23,23 @@
 import org.slf4j.LoggerFactory;
 import org.apache.ode.axis2.Axis2TestBase;
 import org.apache.ode.axis2.JettyWrapper;
-import org.apache.ode.axis2.httpbinding.HttpBindingTest;
 import org.apache.ode.utils.DOMUtils;
 import static org.testng.AssertJUnit.assertTrue;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
+import org.w3c.dom.Element;
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.jetty.handler.AbstractHandler;
-import org.mortbay.jetty.Handler;
+
 import org.mortbay.jetty.Request;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
 import javax.servlet.ServletException;
-import java.util.concurrent.CountDownLatch;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import java.io.IOException;
-import java.io.StringReader;
+
 
 /**
  * <p/>
@@ -112,11 +110,27 @@
         try {
             String response = sendRequestFile("http://localhost:8888/processes/hello/hello/process/client",
                     bundleName, "testRequest.soap");
-            if (log.isDebugEnabled()) log.debug(response);
+            log.debug(response);
             assertTrue("Soap headers missing in: " + response, response.contains("TestSoapHeader2 passed"));
         } finally {
             server.undeployProcess(bundleName);
         }
     }
 
+    @Test
+    public void testSoapHeaders3() throws Exception {
+        String bundleName = "TestSoapHeader3";
+        // deploy the required service
+        if (!server.isDeployed(bundleName)) server.deployProcess(bundleName);
+        try {
+            String response = server.sendRequestFile("http://localhost:8888/processes/hello_world_header_wsdl",
+                    bundleName, "testRequest.soap");
+            log.debug(response);
+            assertTrue(response!=null);
+            Element resEle = DOMUtils.stringToDOM(response);
+            assertTrue(DOMUtils.findChildByName(resEle, new QName("http://www.example.org/cid","conversationId","cid"),true) != null);
+        } finally {
+            server.undeployProcess(bundleName);
+        }
+    }
 }
diff --git a/axis2-war/src/test/resources/TestSoapHeader3/HelloWorld.bpel b/axis2-war/src/test/resources/TestSoapHeader3/HelloWorld.bpel
new file mode 100644
index 0000000..3ccf0d1
--- /dev/null
+++ b/axis2-war/src/test/resources/TestSoapHeader3/HelloWorld.bpel
@@ -0,0 +1,73 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<process name="HelloWorldHeaderWSDL"
+    targetNamespace="http://www.example.org/bpel/examples" 
+    xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
+    xmlns:tns="http://www.example.org/bpel/examples"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:intf="http://www.example.org/bpel/examples/wsdl"
+    queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
+    expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0" xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
+
+  <import location="HelloWorld.wsdl"
+     namespace="http://www.example.org/bpel/examples/wsdl"
+     importType="http://schemas.xmlsoap.org/wsdl/" />
+
+   <partnerLinks>
+      <partnerLink name="helloPartnerLink" 
+         partnerLinkType="intf:HelloPartnerLinkType" 
+         myRole="me" />
+   </partnerLinks>
+
+   <variables>
+     <variable name="myVar" messageType="intf:HelloMessage"/>
+     <variable name="mesgVar" type="xsd:string"/>
+     <variable name="conversationId" type="xsd:string"/>
+   </variables>
+
+   <sequence>
+       <receive
+          name="start"
+          partnerLink="helloPartnerLink"
+          portType="intf:HelloPortType"
+          operation="hello"
+          variable="myVar"
+          createInstance="yes"/>
+
+      <assign name="assignHelloMesg">
+          <copy>
+              <from variable="myVar" part="TestPart"/>
+             <to variable="mesgVar"/>
+          </copy>
+          <copy>
+                <from variable="myVar" part="conversationId"/>
+                <to variable="conversationId" />
+        </copy>
+          <copy>
+              <from>concat($mesgVar,' World', ' conversationId=', $conversationId)</from>
+              <to variable="myVar" part="TestPart"/>
+          </copy>
+      </assign>
+       <reply name="end"  
+              partnerLink="helloPartnerLink"
+              portType="intf:HelloPortType" 
+              operation="hello"
+              variable="myVar"/>
+   </sequence>
+</process>
diff --git a/axis2-war/src/test/resources/TestSoapHeader3/HelloWorld.wsdl b/axis2-war/src/test/resources/TestSoapHeader3/HelloWorld.wsdl
new file mode 100644
index 0000000..809f0ef
--- /dev/null
+++ b/axis2-war/src/test/resources/TestSoapHeader3/HelloWorld.wsdl
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<wsdl:definitions
+        targetNamespace="http://www.example.org/bpel/examples/wsdl"
+        xmlns="http://schemas.xmlsoap.org/wsdl/"
+        xmlns:tns="http://www.example.org/bpel/examples/wsdl"
+        xmlns:types="http://www.example.org/cid"
+        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+        xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype">
+
+    <wsdl:types>
+        <xsd:schema targetNamespace="http://www.example.org/cid">
+            <xsd:element name="conversationId" type="xsd:string" />
+        </xsd:schema>
+    </wsdl:types>
+
+    <wsdl:message name="HelloMessage">
+        <wsdl:part name="TestPart" type="xsd:string"/>
+        <wsdl:part name="conversationId" element="types:conversationId" />
+    </wsdl:message>
+
+    <wsdl:portType name="HelloPortType">
+        <wsdl:operation name="hello">
+            <wsdl:input message="tns:HelloMessage" name="TestIn"/>
+            <wsdl:output message="tns:HelloMessage" name="TestOut"/>
+        </wsdl:operation>
+    </wsdl:portType>
+
+    <wsdl:binding name="HelloSoapBinding" type="tns:HelloPortType">
+        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
+        <wsdl:operation name="hello">
+            <soap:operation soapAction="" style="rpc"/>
+            <wsdl:input>
+                <soap:body
+                        namespace="http://www.example.org/bpel/examples/wsdl"
+                        use="literal" parts="TestPart" />
+                <soap:header message="tns:HelloMessage"
+                         part="conversationId" use="literal"/>
+           </wsdl:input>
+            <wsdl:output>
+                <soap:body
+                        namespace="http://www.example.org/bpel/examples/wsdl"
+                        use="literal" parts="TestPart" />
+                <soap:header message="tns:HelloMessage"
+                         part="conversationId" use="literal"/>
+            </wsdl:output>
+       </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="HelloService">
+        <wsdl:port name="HelloPort" binding="tns:HelloSoapBinding">
+            <soap:address location="http://localhost:8080/ode/processes/hello_world_header_wsdl"/>
+        </wsdl:port>
+    </wsdl:service>
+
+    <plnk:partnerLinkType name="HelloPartnerLinkType">
+        <plnk:role name="me" portType="tns:HelloPortType"/>
+        <plnk:role name="you" portType="tns:HelloPortType"/>
+    </plnk:partnerLinkType>
+</wsdl:definitions>
diff --git a/axis2-war/src/test/resources/TestSoapHeader3/deploy.xml b/axis2-war/src/test/resources/TestSoapHeader3/deploy.xml
new file mode 100644
index 0000000..56b3a40
--- /dev/null
+++ b/axis2-war/src/test/resources/TestSoapHeader3/deploy.xml
@@ -0,0 +1,30 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
+        xmlns:bpl="http://www.example.org/bpel/examples" 
+        xmlns:intf="http://www.example.org/bpel/examples/wsdl">
+
+
+        <process name="bpl:HelloWorldHeaderWSDL">
+                <active>true</active>
+                <provide partnerLink="helloPartnerLink">
+                    <service name="intf:HelloService" port="HelloPort"/>
+                </provide>
+        </process>
+</deploy>
diff --git a/axis2-war/src/test/resources/TestSoapHeader3/testRequest.soap b/axis2-war/src/test/resources/TestSoapHeader3/testRequest.soap
new file mode 100644
index 0000000..8d26bd7
--- /dev/null
+++ b/axis2-war/src/test/resources/TestSoapHeader3/testRequest.soap
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cid="http://www.example.org/cid" xmlns:wsdl="http://www.example.org/bpel/examples/wsdl">
+   <soapenv:Header>
+      <cid:conversationId>1</cid:conversationId>
+   </soapenv:Header>
+   <soapenv:Body>
+      <wsdl:hello>
+         <TestPart>hello</TestPart>
+      </wsdl:hello>
+   </soapenv:Body>
+</soapenv:Envelope>
diff --git a/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java b/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
index 38cd9a5..eb077ff 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
@@ -259,7 +259,8 @@
         for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext();) {
             OMNode node = i.next();
             i.remove();
-            soaphdr.addChild(node);
+            if(node.getType() == OMNode.ELEMENT_NODE)
+                soaphdr.addChild(node);
         }
     }
 
@@ -466,7 +467,7 @@
             Message hdrMsg = _def.getMessage(headerDef.getMessage());
             for (Object o : hdrMsg.getParts().values()) {
                 Part p = (Part) o;
-                if (p.getElementName().equals(elmtName) && p.getName().equals(headerDef.getPart()))
+                if (p.getElementName() != null && p.getElementName().equals(elmtName) && p.getName().equals(headerDef.getPart()))
                     return p.getName();
             }
         }
diff --git a/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java b/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java
index 36639bf..c5cef89 100644
--- a/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java
+++ b/axis2/src/test/java/org/apache/ode/axis2/SoapMessageConverterTest.java
@@ -29,10 +29,10 @@
 
 import junit.framework.TestCase;
 
-import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
-import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.ode.axis2.util.SoapMessageConverter;
@@ -159,7 +159,7 @@
 
         XMLStreamReader sr = XMLInputFactory.newInstance().createXMLStreamReader(
                 getClass().getResourceAsStream("/HelloWorldRequest.soap"));
-        StAXSOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(new SOAP11Factory(), sr);
+        SOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getMetaFactory(), sr);
         SOAPEnvelope se = builder.getSOAPEnvelope();
 
         Element msg = DOMUtils.stringToDOM("<message/>");