java - Spring WS: Add custom SOAP header -
what's goal?
i'm rather new spring ws, got wsdl (and along xsds, ofcourse) , want add custom header elements soap response. i've been searching web, tried various code pieces, it's without luck... nothing seems work .
what's problem?
the response soap message has body spring calls payload , soap client (soapui) receives response rather well. here comes: how should add new (custom) soap headers response message?
what's response xml expected?
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:header> <aud:headerinfo xmlns:bd="http://www.myws.com/"> <bd:id>123</bd:id> <bd:type>text</bd:type> </aud:headerinfo> </soap-env:header> <soap-env:body> <ne:myws xmlns:ne="http://www.iways.com/"> <ne:info> <ne:name>john</ne:name> <ne:designation>ita</ne:designation> <ne:mobile>9841011113</ne:mobile> </ne:info> </ne:myws>
my payload
@payloadroot(localpart = "mywsrequest", namespace = target_namespace) public @responsepayload mywsresponse getinfo(@requestpayload mywsrequest request) { mywsresponse response = new mywsresponse(); person person = personservice_i.getaccountdetails(request.getid()); response.setpersondetails(person); return response; }
any side info?
i use xsd generates load of classes based upon xsds don't know how add custom headers response message,
you implement endpointinterceptoradapter , following:
public final class myendpointinterceptoradapter extends endpointinterceptoradapter { @override public boolean handleresponse(messagecontext messagecontext_, object endpoint_) throws ioexception { webservicemessage _webservicemessage = messagecontext_.getresponse(); soapmessage _soapmessage = (soapmessage) _webservicemessage; if (_soapmessage != null) { soapenvelope _soapenvelope = _soapmessage.getenvelope(); // create qname object qname _myqname = .... // adding quname header _soapenvelope.getheader().addheaderelement(myqname ); } } }
and in spring configuration file, add interceptor:
<sws:interceptors> <ref bean="myendpointinterceptoradapter"/> </sws:interceptors>
Comments
Post a Comment