I am trying to implement custom soap faults like below:
@SoapFault(faultCode = FaultCode.CUSTOM, customFaultCode="{namespace}Server Error", faultStringOrReason="Error encountered when processing request message.")
public class SystemFault extends BusinessException{ }.
The soap fault thrown is of the below format:
<.SOAP-ENV:Fault>
<.faultcode xmlns:ns0="namespace">ns0:star:Server Error<./faultcode>
<.faultstring xml:lang="en">Error Encountered when processing the request.<./faultstring>
<./SOAP-ENV:Fault>
As you can see, fault code tag is appearing with a namespace declaration. Please let me know if there is anyway to avoid that. The format of soap fault client is expecting is:
<.soapenv:Fault xmlns:star="http://www.starstandard.org/STAR/5">
<.faultcode>star:Custom Fault Code<./faultcode>
<.faultstring>Custom Fault message<./faultstring>
<./soapenv:Fault>
I Checked AbstractSoapFaultDefinitionExceptionResolver.resolveExceptionInternal()
method and it is expecting QName
instance for fault code and not a string. Please let me know how to solve this.
This seems to be an old post but just wanna try to help out. I think you should not worry about fault code and faultdescription. There is actually a third field in the soapFault element whitch is named detail. This element has two subelements named code and description. Use this to carry the fault information.
Check this post: http://memorynotfound.com/spring-ws-add-detail-soapfault-exception-handling/
Hope this can help. Thanks
Looks like you almost there with your
customFaultCode
syntax!Let's revise that JavaDoc one more time:
So, I've just decided to see what is that
{@link QName#toString()}
:Where that
XMLConstants.NULL_NS_URI
is like:From here it looks like it would be enough for you to declare that like plain string:
Although if you want to move the
xmlns
declaration to the top-level you should consider to use more low-level API in your customAbstractSoapFaultDefinitionExceptionResolver
extension:And right, use your
customFaultCode
with raw prefix: