If requirement is to show the error in SoapFault from Webservice, you can use below code. Just pass the faultMessage to the method and it will return the SoapFault:
/**
* Soap Fault return in case of error
* @ chandan Dec 17, 2015
* @param faultMessage
* @throws SOAPFaultException
*/
private void throwSoapFault(String faultMessage) throws SOAPFaultException {
SOAPFault fa = null;
try{
fa = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createFault();
fa.setFaultCode(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Sender"));
fa.setFaultString(faultMessage);
throw new SOAPFaultException(fa);
}catch(Exception e2){
throw new SOAPFaultException(fa);
}
}
0 Comment(s)