Wednesday, January 6, 2010

Print the XML contents from an ADBBean

I wanted to print the xml contents of a custom object created by Axis2's wsdl2java. The object inherits from ADBBean, so you could use the following function to pull a reasonable approximation of the soap message out --

public static String debugAxisObject(org.apache.axis2.databinding.ADBBean b){
try {
org.apache.axis2.databinding.utils.writer.MTOMAwareOMBuilder omwriter=
new org.apache.axis2.databinding.utils.writer.MTOMAwareOMBuilder();

new javax.xml.namespace.QName("http://localhost/",
b.getClass().getSimpleName(), "ns1"),,

return omwriter.getOMElement().toStringWithConsume();
} catch (Exception e) {
return "error writing adbbean "+b.getClass().toString();

-- The QName is completely made up, so it will not match the 'real' soap message, but it will at least give you a decent idea of how your message is laid out. also, I have know idea how this behave if you use an actual MTOM attachment.