java - Spring-ws how to add an attribute to soap action in request body -


i'm using spring-ws consume following wsdl: https://pz.gov.pl/pz-services/signatureverification?wsdl i've generated java classes in tutorial: https://spring.io/guides/gs/consuming-web-service/

documentation of wsdl file specifies, request has have attributes callid, , requesttimestamp set in following example:

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tpus="http://verification.zp.epuap.gov.pl"> <soapenv:header/> <soapenv:body> <tpus:verifysignature callid="6347177294896046332" requesttimestamp="2014-06-30t12:01:30.048+02:00"> <tpus:doc>pd94bwwgdmvyc2e+</tpus:doc> <tpus:attachments> <tpus:attachment> <tpus:content>pd94bwwgdmvyc2+</tpus:content> <tpus:name>podpis.xml</tpus:name> </tpus:attachment> </tpus:attachments> </tpus:verifysignature> </soapenv:body> </soapenv:envelope>

my request looks this:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:header/> <soap-env:body             xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:id="id-82ba5532c">             <ns3:verifysignature                 xmlns:ns3="http://verification.zp.epuap.gov.pl"                 xmlns="">                 <doc>pd94bwwgdmvyc2e+</doc>                 <attachments>                     <attachment>                         <content>pd94bwwgdmvyc2+</content>                         <name>podpis.xml</name>                     </attachment>                 </attachments>             </ns3:verifysignature>         </soap-env:body>     </soap-env:envelope> 

so can see lack callid , requesttimestamp attributes. how can add them if code send request looks this?

public class trustedprofilevalidator extends webservicegatewaysupport { private static final logger tplogger = logger.getlogger(trustedprofilevalidator.class);  /**  * trusted profile validator constructor  */ public trustedprofilevalidator() {     tplogger.info("trusted profile validator service."); }  public verifysignatureresponse validate(byte[] documentinbyte64, arrayofattachment arrayofattachments) {     tplogger.info("checking trusted profile validation");     verifysignature request = new verifysignature();     request.setdoc(documentinbyte64);     request.setattachments(arrayofattachments);      return (verifysignatureresponse) getwebservicetemplate().marshalsendandreceive(             "https://int.pz.gov.pl/pz-services/signatureverification", request,             new soapactioncallback("verifysignature")); } 

}

it seems little bit strange because sample provided doesn't reagard soap-action; can see in sample there parameters added soap body , these parameters not mapped in ws schema

in case if documentation says soap action string must have these parameters can still use used must pass attributes soapactioncallback: example can following

wstemplate.marshalsendandreceive("wsuri", yourequestobj, new soapactioncallback("verifysignature callid=\""+callid+"\"  requesttimestamp=\""+requesttimestamp+"\"")); 

in way spring ws write soap action adding 2 attributes

but assume it's soap-body content modified; in case can use:

  • org.springframework.ws.client.core.webservicetemplate
  • sendsourceandreceive method of webservicetemplate
  • your custom sourceextractor

for example can use xml template (done using velocity) , called "requesttemplate.vm"

<?xml version="1.0" encoding="utf-8" ?>  <tpus:verifysignature callid="${callid}" requesttimestamp="${timestamp}" xmlns:tpus="http://verification.zp.epuap.gov.pl">          <tpus:doc>${doc}</tpus:doc>              <tpus:attachments>                  <tpus:attachment>                     <tpus:content>${doccontent}</tpus:content>                       <tpus:name>${docname}</tpus:name>                  </tpus:attachment>              </tpus:attachments>      </tpus:verifysignature> 

then in code can this:

map<string, object> params = new hashmap<string, object>(5); params.put("callid", "mycallid"); params.put("timestamp", "thetimestamp"); params.put("doc", "thedoc"); params.put("docname", "thedocname"); params.put("doccontent", "thedoccontent"); string xmlrequest = velocityengineutils.mergetemplateintostring(velocityengine, "requesttemplate.vm", "utf-8", params).replaceall("[\n\r]", ""); streamsource requestmessage = new streamsource(new stringreader(xmlrequest)); wstemplate.sendsourceandreceive("wsurl", requestmessage,new new soapactioncallback("verifysignature"),new customsourceextractor()); 

where customsourceextractor can read soap response

i did this

public class viesourceextractor implements sourceextractor<yourobj> { @override public list<yourobj> extractdata(source src) throws ioexception, transformerexception { xmlstreamreader reader = null; try { reader = staxutils.getxmlstreamreader(src); //read xml , create obj return yourresult; } catch (exception e) { throw new transformerexception(e); } { if (reader != null) { try { reader.close(); } catch (xmlstreamexception e) { logger.error("error " + e.getmessage(), e); } } } } } 

i hope can you

angelo


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -