[jboss-svn-commits] JBL Code SVN: r32744 - labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/XTS/WSTX/classes11/com/arjuna/mw/wst11/common.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed May 5 08:40:55 EDT 2010
Author: adinn
Date: 2010-05-05 08:40:54 -0400 (Wed, 05 May 2010)
New Revision: 32744
Modified:
labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java
Log:
corrected serialization and deserialization to avoid double wrapping the coordination context in a CoordinationContext element -- backport of fix for JBTM-625
Modified: labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java 2010-05-05 12:35:11 UTC (rev 32743)
+++ labs/jbosstm/branches/JBOSSTS_4_6_1_GA_CP/XTS/WSTX/classes11/com/arjuna/mw/wst11/common/CoordinationContextHelper.java 2010-05-05 12:40:54 UTC (rev 32744)
@@ -21,7 +21,7 @@
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;
@@ -48,7 +48,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) {
@@ -66,10 +69,33 @@
throws JAXBException
{
try {
+ // 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.
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