<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:oxm="http://www.springframework.org/schema/oxm"
       xmlns:sws="http://www.springframework.org/schema/web-services"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
       http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd">

    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>

    <bean id="messageReceiver" class="org.springframework.ws.soap.server.SoapMessageDispatcher"/>

    <bean id="schemaCollection" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
        <description>
            This bean wrap the messages.xsd (which imports types.xsd), and inlines them as a one.
        </description>
        <property name="xsds" value="/messages.xsd"/>
        <property name="inline" value="true"/>
    </bean>

    <!-- ===================== ENDPOINTS  ===================================== -->

    <!--
        The marshallingEndpoint and xpathEndpoint handle the same messages. So, you can only use one of them at the
        same time. This is done for illustration purposes only, typically you would not create two endpoints which
        handle the same messages.
    -->

    <bean id="marshallingEndpoint" class="org.springframework.ws.samples.airline.ws.MarshallingAirlineEndpoint">
        <description>
            This endpoint handles the Airline Web Service messages using JAXB2 marshalling.
        </description>
        <constructor-arg ref="airlineService"/>
    </bean>

    <!--
        <bean id="xpathEndpoint" class="org.springframework.ws.samples.airline.ws.XPathAirlineEndpoint">
            <description>
                This endpoint handles the Airline Web Service messages using XPath expressions and JAXB2 marshalling.
            </description>
            <constructor-arg ref="airlineService"/>
            <constructor-arg ref="marshaller"/>
        </bean>
    -->

    <bean id="getFrequentFlyerMileageEndpoint"
          class="org.springframework.ws.samples.airline.ws.GetFrequentFlyerMileageEndpoint">
        <description>
            This endpoint handles get frequent flyer mileage requests.
        </description>
        <constructor-arg ref="airlineService"/>
    </bean>

    <oxm:jaxb2-marshaller id="marshaller" contextPath="org.springframework.ws.samples.airline.schema"/>

    <!-- ===================== ENDPOINT MAPPINGS  ============================== -->

    <!--
        The endpoint mappings map from a request to an endpoint. Because we only want the security interception to
        occur for the GetFrequentFlyerMileageEndpoint, we define two mappings: one with the securityInterceptor, and
        a general one without it.
    -->

    <bean id="annotationMapping"
          class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
        <description>
            Detects @PayloadRoot annotations on @Endpoint bean methods. The MarshallingAirlineEndpoint
            has such annotations. It uses two interceptors: one that logs the message payload, and the other validates
            it accoring to the 'airline.xsd' schema file.
        </description>
        <property name="interceptors">
            <list>
                <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
                <bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
                    <property name="xsdSchemaCollection" ref="schemaCollection"/>
                    <property name="validateRequest" value="true"/>
                    <property name="validateResponse" value="true"/>
                </bean>
            </list>
        </property>
        <property name="order" value="1"/>
    </bean>

    <bean id="secureMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
        <description>
            This endpoint mapping is used for endpoints that are secured via WS-Security. It uses a
            securityInterceptor, defined in applicationContext-security.xml, to validate incoming messages.
        </description>
        <property name="mappings">
            <props>
                <prop key="{http://www.springframework.org/spring-ws/samples/airline/schemas/messages}GetFrequentFlyerMileageRequest">
                    getFrequentFlyerMileageEndpoint
                </prop>
            </props>
        </property>
        <property name="interceptors">
            <list>
                <bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor"/>
                <ref bean="wsSecurityInterceptor"/>
            </list>
        </property>
        <property name="order" value="2"/>
    </bean>


    <!-- ===================== ENDPOINT ADAPTERS  ============================== -->

    <!--
        Endpoint adapters adapt from the incoming message to a specific object or method signature. Because this
        example application uses three different endpoint programming models, we have to define three adapters. This
        is done for illustration purposes only, typically you would use one adapter, for instance the
        MarshallingMethodEndpointAdapter.
    -->


    <sws:marshalling-endpoints/>

    <sws:xpath-endpoints>
        <sws:namespace prefix="messages"
                       uri="http://www.springframework.org/spring-ws/samples/airline/schemas/messages"/>
    </sws:xpath-endpoints>

    <bean class="org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter">
        <description>
            This adapter allows for endpoints which implement the PayloadEndpoint interface. The Get
            FrequentFlyerMileageEndpoint implements this interface.
        </description>
    </bean>

    <!-- ===================== ENDPOINT EXCEPTION RESOLVER ===================== -->

    <!--
        Endpoint exception resolvers can handle exceptions as they occur in the Web service. We have two sorts of
        exceptions we want to handle: the business logic exceptions NoSeatAvailableException and NoSuchFlightException,
        which both have a @SoapFault annotation, and other exceptions, which don't have the annotation. Therefore, we
        have two exception resolvers here.
    -->

    <bean class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver">
        <description>
            This exception resolver maps exceptions with the @SoapFault annotation to SOAP Faults. The business logic
            exceptions NoSeatAvailableException and NoSuchFlightException have these.
        </description>
        <property name="order" value="1"/>
    </bean>

    <bean class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
        <description>
            This exception resolver maps other exceptions to SOAP Faults. Both UnmarshallingException and
            ValidationFailureException are mapped to a SOAP Fault with a "Client" fault code.
            All other exceptions are mapped to a "Server" error code, the default.
        </description>
        <property name="defaultFault" value="SERVER"/>
        <property name="exceptionMappings">
            <props>
                <prop key="org.springframework.oxm.UnmarshallingFailureException">CLIENT,Invalid request</prop>
                <prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop>
            </props>
        </property>
        <property name="order" value="2"/>
    </bean>

</beans>
