Search code examples
spring-integrationspring-ws

Unable to throw CustomException from fault-Message Resolver


I am calling 2 different web services using two webservice outbound gateways in my Spring integration gateway flow. I have implemented 2 fault Resolver , in each gateway to resolve SOAP faults and want to create custom application exception and throw from resolver to my exception handler.

My FaultResolver is getting called whenever we receieve the SOAP fault from service call. But I am not been able to throw custom excetion from my resolver as its only allowing me to throw IOException.

Due to this I am throwing a Runtime Exception with message from my resolver and catching this Runtime Exception in my Exception Handler. Is it correct practice to throw a runtime exception and catching in Handler or is ther any other better way to handle this scenario or any other implementation to handle SOAP Fault and throw custom Exception.


Solution

  • The best way to determine if your solution is good or not, just try to find some out-of-the-box implementation on the matter. One of them is:

    public class SimpleFaultMessageResolver implements FaultMessageResolver {
    
        public void resolveFault(WebServiceMessage message) {
            if (message instanceof FaultAwareWebServiceMessage) {
                throw new WebServiceFaultException((FaultAwareWebServiceMessage) message);
            }
            else {
                throw new WebServiceFaultException("Message has unknown fault: " + message);
            }
        }
    }
    

    where WebServiceFaultException is exactly RuntimeException.

    So, I think you are fine to go ahead.