java - Unable to set SOAP Header while calling Web Service through Camel using dataFormat as POJO -
i using camel in our project , requesting webservices, dataformat pojo. able request when soap message did not contain soap headers, when had headers, unable set those. looked @ documentation not able understand , have several questions.
i want create message below:
<soapenv:envelope`enter code here` xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <soapenv:header> <platformmsgs:documentinfo xmlns:platformmsgs="urn:messages_2015_1.platform.webservices.netsuite.com"> <platformmsgs:nsid>webservices_3479023</platformmsgs:nsid> </platformmsgs:documentinfo> </soapenv:header> <soapenv:body> <addlistresponse xmlns=""> <platformmsgs:writeresponselist xmlns:platformmsgs="urn:messages_2015_1.platform.webservices.netsuite.com"> <platformcore:status issuccess="true" xmlns:platformcore="urn:core_2015_1.platform.webservices.netsuite.com"/> <platformmsgs:writeresponse> <platformcore:status issuccess="false" xmlns:platformcore="urn:core_2015_1.platform.webservices.netsuite.com"> <platformcore:statusdetail type="error"> <platformcore:code>dup_entity</platformcore:code> <platformcore:message>this entity exists.</platformcore:message> </platformcore:statusdetail> </platformcore:status> </platformmsgs:writeresponse> </platformmsgs:writeresponselist> </addlistresponse>`enter code here` </soapenv:body> </soapenv:envelope>
i able send message if there body, can give me code snippet including header section? dataformat pojo.
when using cxf endpoint dataformat pojo, body in camel exchange object object of org.apache.cxf.message.messagecontentslist
. extension of java.util.arraylist<object>
, contains parts of soap message in order defined in wsdl , corresponding method in webservice class. element 0 there body.
so, 1 way java create processor class implementing org.apache.camel.processor
interface , in process
method set soap header. like:
@override public void process(exchange camelexchange) throws exception { messagecontentslist messagebody = (messagecontentslist) camelexchange.getin().getbody(); documentinfo docinfoheader = new documentinfo(); ... set docinfoheader properties ... messagebody.add(docinfoheader); }
(sample not tested. idea, how handle that...)
other answer on similar question can find here: setting custom soap header-to pojo message in camel cxf
it describes how use camel exchange headers soap headers.
i'm not sure 100% way work , 1 better... guess, depends on wsdl use.
upd: second choice use pure cxf solution using cxfmessagesoapheaderoutinterceptor
custom implementation. may like:
public class mycxfinterceptor extends cxfmessagesoapheaderoutinterceptor { @override public void handlemessage( org.apache.cxf.binding.soap.soapmessage message) { org.apache.cxf.binding.soap.soapheader mycustomheader = new org.apache.cxf.binding.soap.soapheader(new qname( {custom name space}, {custom local name}), {custom content object})); mycustomheader.setmustunderstand(true); message.getheaders().add(mycustomheader); }
and set interceptor in camel cxf endpoint :
<cxfendpoint ...> <outinterceptors> <spring:bean class="mycxfinterceptor"/> </outinterceptors> ...
Comments
Post a Comment