web services - how to send and receive soap messages in attribute name/value format? -
what needs set in web service soap messages sent , received in param attribute format? example, need send soap requests parameters in attribute name/value format:
<param name="controller_name">cpa central</param>
and receive them in similar attribute name/value format:
<attribute name="channel_number">1</attribute>
i've googled literally 14 hours , cannot find how it! appreciative if point me in right direction.
here's how ended doing it. seems ridiculous have intercept outgoing soap message , reformat it, rather creating in correct format begin with. if forced use magic black boxes jax-ws was, stuck auto-format provide apparently.
public class inneoquestlogicalhandler implements logicalhandler<logicalmessagecontext> { private static logger logger = logger.getlogger(inneoquestsoaphandler.class); @override public boolean handlemessage(logicalmessagecontext context) { boolean isresponse = (boolean)context.get(messagecontext.message_outbound_property); if(!isresponse){ logger.debug("inneoquestlogicalhandler.handlemessage(): soap request"); } else { logger.debug("inneoquestlogicalhandler.handlemessage(): soap response"); try { try { transform(context); } catch (transformerconfigurationexception ex) { java.util.logging.logger.getlogger(inneoquestlogicalhandler.class.getname()).log(level.severe, null, ex); } catch (soapexception ex) { java.util.logging.logger.getlogger(inneoquestlogicalhandler.class.getname()).log(level.severe, null, ex); } } catch (transformerexception ex) { java.util.logging.logger.getlogger(inneoquestlogicalhandler.class.getname()).log(level.severe, null, ex); } } return true; } private void transform(logicalmessagecontext context) throws transformerconfigurationexception, transformerexception, soapexception { logicalmessage msg = context.getmessage(); source source = msg.getpayload(); transformer xformer = transformerfactory.newinstance().newtransformer(); xformer.setoutputproperty("omit-xml-declaration", "yes"); domresult result = new domresult(); xformer.transform(source,result); document doc = (document) result.getnode(); transformnodelist(doc,doc.getchildnodes()); source = new domsource(doc); msg.setpayload(source); } private void transformnodelist(document doc, nodelist nodelist) { (int i=0; i< nodelist.getlength(); i++) { node childnode = nodelist.item(i); if (childnode.getnodename().equals("channel_number")) { element elem = (element)childnode; doc.renamenode(elem, elem.getnamespaceuri(), "attribute"); elem.setattribute("name", "channel_number"); } else if (childnode.getnodename().equals("count")) { element elem = (element)childnode; doc.renamenode(elem, elem.getnamespaceuri(), "response"); elem.setattribute("rows", elem.gettextcontent()); elem.settextcontent(""); elem.setattribute("type", "success"); } nodelist children = childnode.getchildnodes(); if (children != null) { transformnodelist(doc,children); } } }
Comments
Post a Comment