I know this answer is outdated, but maybe it works for someone else.
MessageDispatcher by default creates two Resolvers: SimpleSoapExceptionResolver and SoapFaultAnnotationExceptionResolver in this order, if you want to get a soap error using a special code and an error message, you must first declare the correct order to receive SoapFaultAnnotationExceptionResolver, and then SimpleSoapExceptionResolver.
Step 1. In the bean, the configuration file corresponding to:
<bean class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver"> <property name="order" value="1"/> </bean> <bean class="org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver"> <property name="order" value="2"/> </bean>
Step 2. Declare your exceptions as follows:
@SoapFault(faultCode = FaultCode.CUSTOM,locale="en",faultStringOrReason = "CUSTOM_MESSAGE",customFaultCode="YOUR_NAMESPACE + YOUR_CUSTOM_CODE") public class DeclaracionNotFoundException extends BusinessException { public DeclaracionNotFoundException(){ super(); } public DeclaracionNotFoundException(String message) { super(message); } }
Step 3
Raise your exception to your code usually
throws a new DeclaracionNotFoundException (); // With a default message from faultStringOrReason or throws a new DeclaracionNotFoundException ("Ops !!!"); // With another message
It works for me, and I got the following:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode xmlns:ns0="http://com.example">ns0:4</faultcode> <faultstring xml:lang="en">Ops !!!</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I defined faultCode = 4 and faultString = Ops !!!
Hi
source share