Aleyna
Aleyna

Reputation: 1857

Spring-WS: Automatic wsdl fault generation/association

I am using DynamicWsdl11Definition in spring-ws to generate my wsdl spec. Eventually, I am getting a spec without wsdl faults attached to wsdl operations as I don't know how to associate particular wsdl/soap operations with particular wsdl faults automatically. How can I do that? Is there any way to associate wsdl faults with wsdl operations in the XSD schema?

Here is a portion from my XSD:

    <xs:element name="setContextRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="usageContext" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="setContextResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

Here is my exception:

    <xs:element name="InvalidSessionException">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="InvalidSessionException" nillable="true" type="fault:InvalidSession"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

Here is WSDL spec:

        <wsdl:operation name="setContext">
            <soap:operation soapAction=""/>
            <wsdl:input name="setContextRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="setContextResponse">
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>

My question is on how to associate teh fault with that operation eventually to end up with:

        <wsdl:operation name="setContext">
            <soap:operation soapAction=""/>
            <wsdl:input name="setContextRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="setContextResponse">
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="invalidSession" type="InvalidSession"/>
        </wsdl:operation>

Thanks.

ps: I'm setting requestSuffix, responseSuffix and faultSuffix, thus able to generate wsdl fault messages too.

Upvotes: 3

Views: 3987

Answers (3)

zoirs
zoirs

Reputation: 631

you should install the same names with different requestSuffix responseSuffix and faultSuffix:

    <xs:element name="setContextRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="usageContext" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="setContextResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="setContextException">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="InvalidSessionException" nillable="true" type="fault:InvalidSession"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

Upvotes: 0

Biju Kunjummen
Biju Kunjummen

Reputation: 49925

To your first question, on how to get the sws:dynamic-wsdl to generate fault element, the convention is to have the fault element ending with "Fault", so if you have a "MemberService", have a "MemberRequest", "MemberResponse" and "MemberFault" elements in your xsd and these will be put together by Spring-WS

<wsdl:portType name="MemberDetails">
  <wsdl:operation name="MemberDetails">
   <wsdl:input message="tns:MemberDetailsRequest" name="MemberDetailsRequest"></wsdl:input>
   <wsdl:output message="tns:MemberDetailsResponse" name="MemberDetailsResponse"></wsdl:output>
   <wsdl:fault message="tns:MemberDetailsFault" name="MemberDetailsFault"></wsdl:fault>
 </wsdl:operation>
</wsdl:portType>

On the second question, how to get Spring-WS to populate this fault element, I have written a custom SoapFaultExceptionResolver which looks out for exception of my specific type and populates the fault element tag by tag. A little hacky, but I did not see any other way.

Upvotes: 5

evandongen
evandongen

Reputation: 2065

I haven't looked in generation of inline faults by using the dynamic WSDL generation.

I've used EndpointExceptionResolver though. That will create a SOAP-FAULT message. You can define one like this:

@Bean
public EndpointExceptionResolver exceptionResolver() {
    SoapFaultDefinition defaultFault = new SoapFaultDefinition();
    defaultFault.setFaultCode(SoapFaultDefinition.SERVER);

    Properties mappings = new Properties();
    mappings.put("com.sun.xml.wss.impl.WssSoapFaultException", "CLIENT,Authentication failed");
    mappings.put("org.springframework.ws.soap.security.xwss.XwsSecurityValidationException", "CLIENT,Authentication failed");

    SoapFaultMappingExceptionResolver resolver = new SoapFaultMappingExceptionResolver();
    resolver.setDefaultFault(defaultFault);
    resolver.setExceptionMappings(mappings);

    return resolver;
}

You can inject this exception resolver into one of your interceptors.

Upvotes: 0

Related Questions