[#ftl attributes={"generated.type":"blueprint"}]
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           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">

    <!-- 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.authorizationType == "JAAS"]
                <ref component-id="jaasLoginInterceptor" />
                [#if properties.restrictByRoles]
                    <ref component-id="simpleAuthorizingInterceptor" />
                [/#if]
                <ref component-id="resolveProfileNameInterceptor" />
                <ref component-id="resolveLoginInterceptor"/>
                [#if properties.displayServiceSchema]
                    <!-- ref component-id="isSchemaDisplayInterceptor" / -->
                [#else]
                    <ref component-id="disableWSDLGetInterceptor" />
                    <ref component-id="postAuthWsdlGetInterceptor" />
                [/#if]
            [/#if]
            <ref component-id="validator"/>
        </camelcxf:inInterceptors>
    </camelcxf:cxfEndpoint>

    <bean id="validator" class="ru.entaxy.platform.services.runtime.interceptor.SOAPValidateInterceptor">
        <property name="schemaValidationEnabled" value="[=properties.schemaValidationEnabled?c]"/>
    </bean>

    [#if properties.authorizationType == "JAAS"]
        <bean id="jaasLoginInterceptor" class="org.apache.cxf.interceptor.security.JAASLoginInterceptor">
            <property name="contextName" value="[=properties.authorizationRealm]" />
            <property name="roleClassifier" value="RolePrincipal"/>
            <property name="roleClassifierType" value="classname"/>
            <property name="allowAnonymous" value="false"/>
            <property name="allowNamedPrincipals" value="true"/>
        </bean>
        <bean id="resolveProfileNameInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.ResolveProfileNameInterceptor">
        </bean>
        <bean id="resolveLoginInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.ResolveLoginInterceptor" />
        [#if properties.restrictByRoles]
            <bean id="simpleAuthorizingInterceptor" class="org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor">
                <property name="methodRolesMap">
                    <map>
                        <!-- NOT IMPLEMENTED YET -->
                        <!-- no wildcard support, names need to match exactly -->
                        <!-- entry key="addNumbers" value="ROLE_USER ROLE_ADMIN"/>
                        <entry key="divideNumbers" value="ROLE_ADMIN"/ -->
                    </map>
                </property>
                <!-- its possible to define global roles that apply to all WSDL operations not listed above -->
                <property name="globalRoles" value="[=properties.globalRoles]"/>
            </bean>
        [/#if]
        [#if properties.displayServiceSchema]
            <!-- bean id="isSchemaDisplayInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.IsSchemaDisplayInterceptor">
        <property name="isDisplayServiceSchema" value="[=displayServiceSchema?c]"/>
    </bean -->
        [#else]
            <bean id="postAuthWsdlGetInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.PostAuthWSDLGetInterceptor">
            </bean>
            <bean id="disableWSDLGetInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.DisableWSDLGetInterceptor">
            </bean>
        [/#if]
    [/#if]

    [#import "templates:object-commons/common-utils.ftl" as utils]
    <camelContext id="[=objectId]" xmlns="http://camel.apache.org/schema/blueprint">

        <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" />
            <removeProperties pattern="NTX.+|ENTAXY.+"/>
            <removeHeaders pattern="NTX.+|ENTAXY.+"/>
        </route>

    </camelContext>

</blueprint>
