<!--
	~  Licensed to the Apache Software Foundation (ASF) under one
	~  or more contributor license agreements.  See the NOTICE file
	~  distributed with this work for additional information
	~  regarding copyright ownership.  The ASF licenses this file
	~  to you under the Apache License, Version 2.0 (the
	~  "License"); you may not use this file except in compliance
	~  with the License.  You may obtain a copy of the License at
	~
	~   http://www.apache.org/licenses/LICENSE-2.0
	~
	~  Unless required by applicable law or agreed to in writing,
	~  software distributed under the License is distributed on an
	~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
	~  KIND, either express or implied.  See the License for the
	~  specific language governing permissions and limitations
	~  under the License.
-->

<!-- Exigence BF-010 -->

<definitions xmlns="http://ws.apache.org/ns/synapse">

	<!-- La configuration spring a ete separee en deux car synapse
		relit toute la configuration synapse a chaque instanciation d'un
		mediateur spring. Pour eviter les exception du a l'export repete
		des mbeans, les fichiers de configuration spring ont ete separes
	-->
	<localEntry key="springconfig"
		src="file:./repository/conf/spring-config.xml" />

	<localEntry key="springconfig-without-mbeans"
		src="file:./repository/conf/spring-config-without-mbeans.xml" />

    <localEntry key="schema-agoraMessage"
        src="file:./xsd/agoraMessage.xsd"/>

	<!-- Sequence de traitement des erreurs -->
	<sequence name="faultHandler">
		<makefault>
			<code value="tns:Receiver"
				xmlns:tns="http://www.w3.org/2003/05/soap-envelope" />
			<reason expression="get-property('ERROR_MESSAGE')" />
		</makefault>

		<property name="RESPONSE" value="true" />
		<send />
	</sequence>

	<!-- Sequence de traitement sortante -->
	<sequence name="frontal-out" onError="faultHandler">
		<!-- mediateur de log Exigence BF-022 -->
		<log level="simple" />

        <!-- mediateur de validation de message -->
        <validate>
            <schema key="schema-agoraMessage" />
            <on-fail>
                <makefault>
                    <code
                        xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
                        value="tns:Receiver" />
                    <reason expression="get-property('ERROR_MESSAGE')" />
                </makefault>
                <property name="RESPONSE" value="true" />
                <send />
            </on-fail>
        </validate>
        
		<!-- mediateur de transformation -->
		<spring:spring bean="AgoraToSoapMediator"
			key="springconfig-without-mbeans"
			xmlns:spring="http://ws.apache.org/ns/synapse/spring" />
		<send />
	</sequence>

	<!-- Filtre toutes les adresses non prises en charge par un proxy
		et renvoie une erreur Soap fault -->
	<filter source="get-property('To')" regex=".*/.*">
		<makefault>
			<code value="tns:Receiver"
				xmlns:tns="http://www.w3.org/2003/05/soap-envelope" />
			<reason value="Le service demande n'est pas deploye" />
		</makefault>
		<log level="full" />
		<property name="RESPONSE" value="true" />
		<header name="To" action="remove" />
		<send />
	</filter>

	<!-- Endpoint representant le socle technique -->
	<!-- Routage Exigence BF-025-->
	<endpoint name="stj2ee">
		<!-- A configurer avec l'url du bouchon ou du socle technique J2EE -->
		<address uri="http://127.0.0.1:7896/Multi-Mock-1.0/Service?STJ2ee"
			format="pox">
			<!-- When an endpoint fail (ex : timeout) it is deactivated for the given period in second -->
			<suspendDurationOnFailure>30</suspendDurationOnFailure>
			<timeout>
				<!-- Duration in second before timeout is triggered -->
				<duration>5</duration>
				<action>fault</action>
			</timeout>
		</address>
	</endpoint>

	<localEntry key="schema-R5WSService"
		src="file:wsdl/wsdlAgoraTest.wsdl.xsd" />

	<sequence name="sequence-R5WSService" onError="faultHandler">
		<!-- mediateur de log Exigence BF-022 -->
		<log level="simple" />

		<!-- mediateur de statut de service -->
		<spring:spring bean="serviceMediateur" key="springconfig"
			xmlns:spring="http://ws.apache.org/ns/synapse/spring" />

		<!-- mediateur de validation de message -->
		<validate>
			<schema key="schema-R5WSService" />
			<on-fail>
				<makefault>
					<code
						xmlns:tns="http://www.w3.org/2003/05/soap-envelope"
						value="tns:Receiver" />
					<reason expression="get-property('ERROR_MESSAGE')" />
				</makefault>
				<property name="RESPONSE" value="true" />
				<send />
			</on-fail>
		</validate>

		<!-- plugin agora de mediation -->
		<spring:spring bean="AgoraPluginMediator"
			key="springconfig-without-mbeans"
			xmlns:spring="http://ws.apache.org/ns/synapse/spring" />

		<!-- mediateur de transformation -->
		<spring:spring bean="SoapToAgoraMediator"
			key="springconfig-without-mbeans"
			xmlns:spring="http://ws.apache.org/ns/synapse/spring" />
        <property name="FORCE_HTTP_1.0" value="true" scope="axis2-client"/>
		<send>
			<endpoint key="stj2ee" />
		</send>
	</sequence>

	<proxy name="R5WSService">
		<target inSequence="sequence-R5WSService"
			outSequence="frontal-out" />
		<publishWSDL uri="file:wsdl/wsdlAgoraTest.wsdl" />
	</proxy>

</definitions>
