Spring returning custom soap faults

11,186

You need a EndpointExceptionResolver, see SpringWS manual about handling exceptions.

SpringWS comes with some built-in exception resolves, you can use those as a reference when implementing your own.

Share:
11,186
Admin
Author by

Admin

Updated on June 27, 2022

Comments

  • Admin
    Admin almost 2 years

    I am using spring webservices to expose my services as web services. I defined my Soap fault element like this

    <xsd:element name="systemFault">
            <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="faultCode" type="xsd:string" nillable="true"/>
                        <xsd:element name="faultMessage" type="xsd:string"/>
                    </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    

    and I am using this in my WSDL

    <wsdl:message name="msgSystemFault">
            <wsdl:part name="body" element="cred:SystemFault"/>
        </wsdl:message>
    

    and then use this in an operation

    <wsdl:operation name="opMyOp">
                <wsdl:documentation>
                    Creating an entity note.
                </wsdl:documentation>
                <wsdl:input message="tns:msgMyOpRequest"/>
                <wsdl:output message="tns:msgMyOpResponse"/>
                <wsdl:fault name="fault" message="tns:msgSystemFault"/>
            </wsdl:operation>
    

    But when I want to throw this fault in my endpoint, how can I do that??

  • skaffman
    skaffman over 13 years
    That doesn't seem to handle custom faults, just generic server faults.
  • Neeme Praks
    Neeme Praks over 13 years
    Why? Or what do you mean by "custom fault"? Just have a look at the source of SimpleSoapExceptionResolver and its superclasses: fisheye.springsource.org/browse/spring-ws/trunk/core/src/mai‌​n/… - you can see that there is nothing magical about it, you just implement the EndpointExceptionResolver interface and build your own custom fault. SpringWS even comes with several abstract classes that help to remove quite a lot of boilerplate code.