Skip to content
Advertisement

SOAPHandler handleFault

Can any one explain me when SOAPHandler‘s handleFault(SOAPMessageContext context) method is called ?

My Handler class is :

public class WebServiceHandler implements SOAPHandler<SOAPMessageContext> {

    private void dumpSOAPMessage(SOAPMessage msg) {
        if (msg == null) {
            System.out.println("SOAP Message is null");
            return;
        }
        System.out.println("");
        System.out.println("--------------------");
        System.out.println("DUMP OF SOAP MESSAGE");
        System.out.println("--------------------");
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            msg.writeTo(baos);
            System.out.println(baos.toString(getMessageEncoding(msg)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        try {
            dumpSOAPMessage(((SOAPMessageContext) context).getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        // TODO Auto-generated method stub
        System.out.println("Inside handle fault:: " + context);
        return true;
    }

    @Override
    public void close(MessageContext context) {
        // TODO Auto-generated method stub

    }

    @Override
    public Set<QName> getHeaders() {
        Set<QName> set = new HashSet<QName>();
        return set;
       }
}

Can any one explain when handleMessage and handleFault method is called ?

Advertisement

Answer

According to : http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv/handlers.html#wp222524

handleMessage :

The Handler.handleMessage() method is called to intercept a SOAP message request before and after it is processed by the back-end component

and

handleFault :

Implement this method to handle processing of any SOAP faults generated by the handleMessage() method, as well as faults generated by the back-end component.

Advertisement