[#ftl attributes={"generated.type":"blueprint"}]
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
           xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
           xmlns:cxf="http://cxf.apache.org/blueprint/core"
           xmlns:[=objectId]="[=properties.serviceNamespace]"
           xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
             ">
<!-- xmlns:soap-type="http://www.entaxy.ru/ExchangeTypes/1.0" -->             
<!-- 

	factoryId: wsdl-based-soap-service-public
	factoryType: entaxy.runtime.service
	outputType: init 
	properties:
	[#list properties?keys as key]
		[=key]
	[/#list]
 -->

	<camelcxf:cxfEndpoint id="[=objectId]-cxf-endpoint"
                          address="/[=properties.address]"
                          endpointName="[=objectId]:[=properties.port]"
                          serviceName="[=objectId]:[=properties.serviceName]"
                          wsdlURL="entaxy-resource://[=properties.schemaUrl?replace(":", "/")]">
        <camelcxf:properties>
            <entry key="dataFormat" value="[=properties.dataFormat]"/>
            <entry key="mtom-enabled" value="[=properties.mtomEnabled?c]"/>
            <entry key="schema-validation-enabled" value="[=properties.schemaValidationEnabled?c]"/>
        </camelcxf:properties>
        <camelcxf:inInterceptors>
            [#if properties.displayServiceSchema]
            <ref component-id="isSchemaDisplayInterceptor"/>
            [/#if]
            <ref component-id="authInterceptor"/>
            <ref component-id="systemInterceptor"/>
            <ref component-id="validator"/>
            <ref component-id="resolveLoginInterceptor"/>
        </camelcxf:inInterceptors>
        <camelcxf:outFaultInterceptors>
            <ref component-id="handleOutFaultInterceptor"/>
        </camelcxf:outFaultInterceptors>
    </camelcxf:cxfEndpoint>

    [#if properties.displayServiceSchema]
    <bean id="isSchemaDisplayInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.IsSchemaDisplayInterceptor">
        <property name="isDisplayServiceSchema" value="[=displayServiceSchema?c]"/>
    </bean>
    [/#if]

    <bean id="handleOutFaultInterceptor"
          class="ru.entaxy.esb.system.core.common.error.handler.interceptor.HandleOutFaultInterceptor">
        <argument ref="soap-[=objectId]-context"/>
        <argument value="direct:error_from_cxf"/>
    </bean>

    <bean id="validator" class="ru.entaxy.esb.system.common.validator.ValidateInterceptor">
        <property name="schemaValidationEnabled" value="[=properties.schemaValidationEnabled?c]"/>
    </bean>
    <reference id="systemInterceptor" interface="org.apache.cxf.phase.PhaseInterceptor"
               filter="(type=system)"/>
    <reference id="authInterceptor" interface="org.apache.cxf.phase.PhaseInterceptor"
               filter="(type=authentication)"/>
    <bean id="resolveLoginInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.ResolveLoginInterceptor" />

	<bean id="[=objectId]-connector-registry" class="ru.entaxy.platform.services.runtime.impl.EntaxyServiceConnectorRegistry" activation="eager">
		<property name="profileNameHeaders">
			<list value-type="java.lang.String">
				<value>X-SystemName</value>
			</list>
		</property>
	</bean>

	<reference-list id="connectorList"
                    interface="ru.entaxy.platform.services.runtime.EntaxyServiceConnectorInfo"
                    filter="(service=[=objectId])" availability="optional">
        <reference-listener ref="[=objectId]-connector-registry"
                            bind-method="register" unbind-method="unregister"/>
    </reference-list>

    <camelContext id="soap-[=objectId]-context" xmlns="http://camel.apache.org/schema/blueprint"
                  errorHandlerRef="commonErrorHandler">

        <errorHandler id="commonErrorHandler" redeliveryPolicyRef="noRedelivery"
                      type="DeadLetterChannel" deadLetterUri="direct-vm:commonErrorEndpoint"/>
        <redeliveryPolicyProfile id="noRedelivery" disableRedelivery="true"/>

        <route id="error_from_cxf">
            <from uri="direct:error_from_cxf"/>
            <log message="cxf message: ${body}" loggingLevel="DEBUG"/>
            <log message="headers: ${headers}\n" loggingLevel="DEBUG"/>
            <to uri="direct-vm:cxfErrorEndpoint"/>
        </route>

        <route id="[=objectId]-cxf-endpoint" streamCache="true">
            <from uri="cxf:bean:[=objectId]-cxf-endpoint"/>
            <setHeader name="ENTAXY_EndpointName">
                <simple>[=objectId]</simple>
            </setHeader>
            
			[#include "templates:service-components/generateLoggingKey.ftl"]
            
            <to uri="direct:[=objectId]-operation-router" />
        </route>
        
    </camelContext>

</blueprint> 
