[jboss-svn-commits] JBL Code SVN: r29615 - labs/jbosstm/trunk/XTS/WSTX/classes11/com/arjuna/mw/wst11/common.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 15 05:12:39 EDT 2009


Author: adinn
Date: 2009-10-15 05:12:38 -0400 (Thu, 15 Oct 2009)
New Revision: 29615

Modified:
   labs/jbosstm/trunk/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java
Log:
corrected serialization/deserialization of context to/from service requests -- fixes JBTM-625

Modified: labs/jbosstm/trunk/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java	2009-10-15 07:16:23 UTC (rev 29614)
+++ labs/jbosstm/trunk/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java	2009-10-15 09:12:38 UTC (rev 29615)
@@ -21,13 +21,14 @@
 package com.arjuna.mw.wst11.common;
 
 import org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType;
-import org.w3c.dom.Element;
+import org.w3c.dom.*;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.soap.SOAPElement;
 
 /**
  * Helper class for serialising Coordination Contexts into SOAP headers.
@@ -48,7 +49,10 @@
             JAXBContext jaxbContext = JAXBContext.newInstance("org.oasis_open.docs.ws_tx.wscoor._2006._06");
             Unmarshaller unmarshaller;
             unmarshaller = jaxbContext.createUnmarshaller();
-            CoordinationContextType coordinationContextType = unmarshaller.unmarshal(headerElement.getFirstChild(), CoordinationContextType.class).getValue();
+            // the header element is a valid CoordinationContextType node so we can unpack it directly
+            // using JAXB. n.b. we will see a mustUnderstand=1 in the otherAttributes which we probably don't
+            // want but it will do no harm.
+            CoordinationContextType coordinationContextType = unmarshaller.unmarshal(headerElement, CoordinationContextType.class).getValue();
 
             return coordinationContextType;
         } catch (JAXBException jaxbe) {
@@ -65,11 +69,34 @@
     public static void serialise(final CoordinationContextType  coordinationContextType, Element headerElement)
         throws JAXBException
     {
+        // we would really like to just serialise the coordinationContextType direct. But the JAXB context will
+        // only generate a Node and we need to add a SOAPHeaderElement. So, we cheat by serialising the
+        // coordinationContextType into a header created by the caller, moving all its children into the
+        // header element and then deleting it.
         try {
             JAXBContext jaxbContext = JAXBContext.newInstance("org.oasis_open.docs.ws_tx.wscoor._2006._06");
             Marshaller marshaller;
             marshaller = jaxbContext.createMarshaller();
             marshaller.marshal(coordinationContextType, headerElement);
+            Node element = headerElement.getFirstChild();
+            NamedNodeMap map = element.getAttributes();
+            // we also need to copy namespace declarations into the parent
+            int l = map.getLength();
+            for (int i = 0; i < l; i++) {
+                Attr attr = (Attr)map.item(i);
+                if (attr.getPrefix().equals("xmlns")) {
+                    headerElement.setAttribute(attr.getName(),attr.getValue());
+                }
+            }
+            // copy the children
+            NodeList children = element.getChildNodes();
+            l = children.getLength();
+            for (int i = 0; i < l; i++) {
+                Node child = children.item(i);
+                element.removeChild(child);
+                headerElement.appendChild(child);
+            }
+            headerElement.removeChild(element);
         } catch (JAXBException jaxbe) {
         }
     }



More information about the jboss-svn-commits mailing list