web services - SOAPHandler handleMessage return custom fault -


i have custom soaphandler , handlemessage() follows :

public boolean handlemessage(soapmessagecontext context) {     // todo auto-generated method stub     /* step-1: extract credentials soap header */     boolean isoutbound = (boolean) context             .get(messagecontext.message_outbound_property);      log.info("in transporthandler.handlemessage(...) " + isoutbound);      if (!isoutbound) {          soapmessage soapmsg = context.getmessage();         try {             soaputil soaputil = new soaputil();             credentials credentials = soaputil.retrievecredentials(soapmsg);              /* validate credentials against directory */             securityutil securityutil = new securityutil();             securityutil.authenticateclient(credentials.getusername(),                     credentials.getpassword());          } catch (securityfault_exception e) {             // todo auto-generated catch block             log.error(                     "securityfault_exception in transporthandler.handlemessage(...)",                     e);             soapfault securityfault = null;             try {                 securityfault = soapmsg.getsoapbody().addfault();                 securityfault.setfaultstring(e.getmessage());                 throw new soapfaultexception(securityfault);             } catch (soapexception e1) {                 // todo auto-generated catch block                 log.error(                         "soapexception while handing securityfault_exception in transporthandler.handlemessage(...)",                         e1);             }          } catch (requestmessageformatfault_exception e) {             // todo auto-generated catch block             log.error(                     "requestmessageformatfault_exception in transporthandler.handlemessage(...)",                     e);             soapfault requestformatfault = null;             try {                 requestformatfault = soapmsg.getsoapbody().addfault();                 requestformatfault.setfaultstring(e.getfaultinfo().getcustommessage());                 throw new soapfaultexception(requestformatfault);             } catch (soapexception e1) {                 // todo auto-generated catch block                 log.error(                         "soapexception while handing requestmessageformatfault_exception in transporthandler.handlemessage(...)",                         e1);             }         }      }      log.info("returning transporthandler.handlemessage(...)");      return true; } 

for example, if doesn't add security header, following response :

<soapenv:envelope 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" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">    <soapenv:body>       <soapenv:fault>          <faultcode>soapenv:server</faultcode>          <faultstring>security header not present in soap request</faultstring>       </soapenv:fault>    </soapenv:body> </soapenv:envelope> 

now in handlemessage(...), have wrapped custom fault bad header shown :

catch (requestmessageformatfault_exception e) {                 // todo auto-generated catch block                 log.error(                         "requestmessageformatfault_exception in transporthandler.handlemessage(...)",                         e);                 soapfault requestformatfault = null;                 try {                     requestformatfault = soapmsg.getsoapbody().addfault();                     requestformatfault.setfaultstring(e.getfaultinfo().getcustommessage());                     throw new soapfaultexception(requestformatfault);                 } catch (soapexception e1) {                     // todo auto-generated catch block                     log.error(                             "soapexception while handing requestmessageformatfault_exception in transporthandler.handlemessage(...)",                             e1);                 }             } 

as per our org. standards, have below faults declared in wsdl(partially shown here) :

. . . <message name="requestmessageformatfault">         <part name="requestmessageformatfault" element="sch:requestmessageformatfault" />     </message>      <message name="securityfault">         <part name="securityfault" element="sch:securityfault" />     </message>     .     .     . <porttype name="transportinformationdelegate">         <operation name="gettransportinformation">             .             .             <fault name="requestmessageformatfault" message="tns:requestmessageformatfault"/>             <fault name="securityfault" message="tns:securityfault"/>         </operation>      </porttype>  <binding name="transportinformationportbinding" type="tns:transportinformationdelegate">         <soap:binding style="document"             transport="http://schemas.xmlsoap.org/soap/http" />         <operation name="gettransportinformation">             .             .             .             .             <fault name="requestmessageformatfault">                 <soap:fault name="requestmessageformatfault" use="literal"/>             </fault>             <fault name="securityfault">                 <soap:fault name="securityfault" use="literal"/>             </fault>         </operation> 

how shall ensure response has fault ? tried soapfault.adddetail(...) in vain.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -