<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~~~~~~licensing~~~~~~
  uniform-service
  ==========
  Copyright (C) 2020 - 2024 EmDev LLC
  ==========
  You may not use this file except in accordance with the License Terms of the Copyright
  Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
  rights to the Software and any copies are the property of the Copyright Holder. Unless
  it is explicitly allowed the Copyright Holder, the User is prohibited from using the
  Software for commercial purposes to provide services to third parties.
  
  The Copyright Holder hereby declares that the Software is provided on an "AS IS".
  Under no circumstances does the Copyright Holder guarantee or promise that the
  Software provided by him will be suitable or not suitable for the specific purposes
  of the User, that the Software will meet all commercial and personal subjective
  expectations of the User, that the Software will work properly, without technical
  errors, quickly and uninterruptedly.
  
  Under no circumstances shall the Copyright Holder or its Affiliates is not liable
  to the User for any direct or indirect losses of the User, his expenses or actual
  damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
  or damage to data, property, etc.
  ~~~~~~/licensing~~~~~~
  -->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf" xmlns:cxf="http://cxf.apache.org/blueprint/core" xmlns:uniform-passive-service="http://www.entaxy.ru/connector/universal/esb/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"><manifest xmlns="http://karaf.apache.org/xmlns/deployer/blueprint/v1.0.0">Manifest-Version: 1.0
   Bundle-ManifestVersion: 2
   DynamicImport-Package: *
   Entaxy-Bundle: true
   Entaxy-Runtime: true
   Entaxy-Generated-Object-Configuration: eyJvYmplY3RJZCI6InVuaWZvcm0tcGFzc2l2ZS1zZXJ2aWNlIiwiZmFjdG9yeUlkIjoidW5pZm9ybS1iYXNlZC1zb2FwLXNlcnZpY2UtcHJvdGVjdGVkIiwidHlwZSI6ImVudGF4eS5ydW50aW1lLnNlcnZpY2UiLCJ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-Name: entaxy.runtime.service.uniform-passive-service
   Entaxy-Generated: true
   Bundle-Version: 1.0.0
   Entaxy-Generated-Object: uniform-passive-service:entaxy.runtime.service:public
   Entaxy-Main-Object: uniform-passive-service:entaxy.runtime.service:public
   Provide-Capability: entaxy.runtime.service;factory:String="uniform-based-soap-service-protected";routeContainerType:String="OBJECT";displayName:String="";scope:String="public";name:String="uniform-passive-service";resources:List&lt;String&gt;="schemas:uniform-service/soap-passive.wsdl;runtime,object-resources:entaxy.runtime.service.uniform-passive-service/operationRouter.xml;DESIGN";label:String="service,soap,uniform";objectId:String="uniform-passive-service";isRouteContainer:String="true"
   Bundle-SymbolicName: entaxy.runtime.service.uniform-passive-service

</manifest>
   <!--
       BEGIN secure vaults lookup components
   -->
   <bean activation="eager" class="ru.entaxy.platform.services.runtime.impl.EntaxyServiceConnectorRegistry" id="uniform-passive-service-in-connector-registry">
      <property name="profileNameHeaders">
         <list value-type="java.lang.String">
            <value>X-SystemName</value>
         </list>
      </property>
   </bean>
   <reference-list availability="optional" filter="(service=uniform-service-in)" interface="ru.entaxy.platform.services.runtime.EntaxyServiceConnectorInfo">
      <reference-listener bind-method="register" ref="uniform-passive-service-in-connector-registry" unbind-method="unregister"/>
   </reference-list>
   <bean activation="eager" class="ru.entaxy.platform.services.runtime.impl.EntaxyServiceConnectorRegistry" id="uniform-passive-service-out-connector-registry">
      <property name="profileNameHeaders">
         <list value-type="java.lang.String">
            <value>X-SystemName</value>
         </list>
      </property>
   </bean>
   <reference-list availability="optional" filter="(service=uniform-service-out)" id="connectorOutList" interface="ru.entaxy.platform.services.runtime.EntaxyServiceConnectorInfo">
      <reference-listener bind-method="register" ref="uniform-passive-service-out-connector-registry" unbind-method="unregister"/>
   </reference-list>
   <!--
	BEGIN secure vaults lookup components
-->
   <bean activation="eager" class="ru.entaxy.security.vault.runtime.lookup.CmPropertiesDefaultsLookup" id="vaults.data.provider">
      <property name="bundleContext" ref="blueprintBundleContext"/>
   </bean>
   <cm:property-placeholder xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.4.0" defaults-ref="vaults.data.provider" id="vaults.lookup.placholder" persistent-id="entaxy.secrets" placeholder-prefix="$ENTAXY_SECRETS{" placeholder-suffix="}" update-strategy="reload">
   </cm:property-placeholder>
   <bean activation="eager" class="ru.entaxy.security.vault.runtime.camel.EntaxyVaultAccessorFunction" id="vaults.data.provider.camel">
   </bean>
   <!-- xmlns:soap-type="http://www.entaxy.ru/ExchangeTypes/1.0" -->
   <!--

	factoryId: wsdl-based-soap-service-public
	factoryType: entaxy.runtime.service
	outputType: init
	properties:
		globalRoles
		__errorHandler
		mtomEnabled
		schemaValidationEnabled
		__globalOptions
		##vaults
		authorizationType
		operationRouter
		restrictByRoles
		errorHandlerType
		generateLoggingKey
		serviceFullName
		address
		dataFormat
		_serviceMetadata
		serviceName
		displayServiceSchema
		deadLetterUri
		schemaUrl
		##publish
		port
		connectorDispatchingBeans
		authorizationRealm
		serviceNamespace
 -->
   <camelcxf:cxfEndpoint address="/uniform-exchange" endpointName="uniform-passive-service:esbExchangeSOAP" id="uniform-passive-service-cxf-endpoint" serviceName="uniform-passive-service:esbExchange" wsdlURL="entaxy-resource://schemas/uniform-service/soap-passive.wsdl">
      <camelcxf:properties>
         <entry key="dataFormat" value="PAYLOAD"/>
         <entry key="mtom-enabled" value="false"/>
         <entry key="schema-validation-enabled" value="false"/>
      </camelcxf:properties>
      <camelcxf:inInterceptors>
         <ref component-id="jaasLoginInterceptor"/>
         <ref component-id="simpleAuthorizingInterceptor"/>
         <ref component-id="resolveProfileNameInterceptor"/>
         <ref component-id="resolveLoginInterceptor"/>
         <!-- ref component-id="isSchemaDisplayInterceptor" / -->
         <ref component-id="validator"/>
      </camelcxf:inInterceptors>
   </camelcxf:cxfEndpoint>
   <bean class="ru.entaxy.platform.services.runtime.interceptor.SOAPValidateInterceptor" id="validator">
      <property name="schemaValidationEnabled" value="false"/>
   </bean>
   <bean class="org.apache.cxf.interceptor.security.JAASLoginInterceptor" id="jaasLoginInterceptor">
      <property name="contextName" value="karaf"/>
      <property name="roleClassifier" value="RolePrincipal"/>
      <property name="roleClassifierType" value="classname"/>
      <property name="allowAnonymous" value="false"/>
      <property name="allowNamedPrincipals" value="true"/>
   </bean>
   <bean class="ru.entaxy.platform.services.runtime.interceptor.ResolveProfileNameInterceptor" id="resolveProfileNameInterceptor">
        </bean>
   <bean class="ru.entaxy.platform.services.runtime.interceptor.ResolveLoginInterceptor" id="resolveLoginInterceptor"/>
   <bean class="org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor" id="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="*"/>
   </bean>
   <!-- bean id="isSchemaDisplayInterceptor" class="ru.entaxy.platform.services.runtime.interceptor.IsSchemaDisplayInterceptor">
        <property name="isDisplayServiceSchema" value="true"/>
    </bean -->
   <camelContext xmlns="http://camel.apache.org/schema/blueprint" errorHandlerRef="DefaultErrorHandler" id="uniform-passive-service">
      <globalOptions>
         <globalOption key="CamelLogEipName" value="entaxy.runtime.service.uniform-passive-service"/>
      </globalOptions>
      <propertyPlaceholder id="propertiesForCamel">
         <propertiesFunction ref="vaults.data.provider.camel"/>
      </propertyPlaceholder>
      <errorHandler id="NoErrorHandler" type="NoErrorHandler"/>
      <errorHandler id="DefaultErrorHandler" redeliveryPolicyRef="redeliveryPolicyProfileBean" type="DefaultErrorHandler"/>
      <errorHandler deadLetterUri="log:myLog" id="DeadLetterChannel" redeliveryPolicyRef="redeliveryPolicyProfileBean" type="DeadLetterChannel"/>
      <redeliveryPolicyProfile id="redeliveryPolicyProfileBean"/>
      <route id="uniform-passive-service-cxf-endpoint" streamCache="true">
         <from uri="cxf:bean:uniform-passive-service-cxf-endpoint"/>
         <setHeader name="ENTAXY_EndpointName">
            <simple>uniform-passive-service</simple>
         </setHeader>
         <setProperty name="service">
            <constant>uniform-passive-service</constant>
         </setProperty>
         <setProperty name="operation">
            <simple>${headers.CamelHttpMethod}</simple>
         </setProperty>
         <setProperty name="objectId">
            <simple>${headers.ENTAXY_MessageUUID}</simple>
         </setProperty>
         <setProperty name="receiver">
            <simple>${headers.ENTAXY_Destination}</simple>
         </setProperty>
         <setProperty name="sender">
            <simple>${headers.X-User}</simple>
         </setProperty>
         <to uri="direct-vm:fill-logging-key"/>
         <to uri="direct:uniform-passive-service-operation-router"/>
         <removeProperties excludePattern="Camel*" pattern="NTX.+|ENTAXY.+"/>
      </route>
      <route>
         <from uri="direct:uniform-passive-service-operation-router"/>
         <choice>
            <when>
               <simple>${headers.operationName} == 'PutPackets'</simple>
               <log loggingLevel="DEBUG" message="${headers.NTX_loggingKey} Called operation: ${headers.operationName} with message-type: ${header.message-type}"/>
               <log loggingLevel="DEBUG" message="${headers.NTX_loggingKey} Sending to connector: in"/>
               <log loggingLevel="TRACE" message="${headers.NTX_loggingKey} Body: ${body}"/>
               <to uri="bean:uniform-passive-service-in-connector-registry?method=inConnectorFind"/>
               <choice>
                  <when>
                     <simple>${headers.NTX_targetConnector} != null</simple>
                     <setProperty name="NTX_TMP_targetConnector">
                        <simple>${headers.NTX_targetConnector}</simple>
                     </setProperty>
                     <removeHeader headerName="NTX_targetConnector"/>
                     <toD uri="${exchangeProperty.NTX_TMP_targetConnector}"/>
                  </when>
                  <otherwise>
                     <log loggingLevel="ERROR" message="${headers.NTX_loggingKey} Connector not found: service=uniform-service; profile=${headers[X-SystemName]}; direction=in"/>
                     <throwException exceptionType="ru.entaxy.platform.services.runtime.exceptions.ConnectorNotFound" message="Connector not found: service=uniform-service; profile=${headers[X-SystemName]}; direction=in"/>
                  </otherwise>
               </choice>
            </when>
            <when>
               <simple>${headers.operationName} == 'ConfirmGettingPackets'</simple>
               <log loggingLevel="DEBUG" message="${headers.NTX_loggingKey} Called operation: ${headers.operationName}"/>
               <log loggingLevel="DEBUG" message="${headers.NTX_loggingKey} Sending to connector: out"/>
               <to uri="bean:uniform-passive-service-out-connector-registry?method=outConnectorFind"/>
               <choice>
                  <when>
                     <simple>${headers.NTX_targetConnector} != null</simple>
                     <setProperty name="NTX_TMP_targetConnector">
                        <simple>${headers.NTX_targetConnector}</simple>
                     </setProperty>
                     <removeHeader headerName="NTX_targetConnector"/>
                     <toD uri="${exchangeProperty.NTX_TMP_targetConnector}"/>
                  </when>
                  <otherwise>
                     <log loggingLevel="ERROR" message="${headers.NTX_loggingKey} Connector not found: service=uniform-service; profile=${headers[X-SystemName]}; direction=out"/>
                     <throwException exceptionType="ru.entaxy.platform.services.runtime.exceptions.ConnectorNotFound" message="Connector not found: service=uniform-service; profile=${headers[X-SystemName]}; direction=out"/>
                  </otherwise>
               </choice>
            </when>
            <when>
               <simple>${headers.operationName} == 'GetPackets'</simple>
               <log loggingLevel="DEBUG" message="${headers.NTX_loggingKey} Called operation: ${headers.operationName}"/>
               <log loggingLevel="DEBUG" message="${headers.NTX_loggingKey} Sending to connector: out"/>
               <to uri="bean:uniform-passive-service-out-connector-registry?method=outConnectorFind"/>
               <choice>
                  <when>
                     <simple>${headers.NTX_targetConnector} != null</simple>
                     <setProperty name="NTX_TMP_targetConnector">
                        <simple>${headers.NTX_targetConnector}</simple>
                     </setProperty>
                     <removeHeader headerName="NTX_targetConnector"/>
                     <toD uri="${exchangeProperty.NTX_TMP_targetConnector}"/>
                  </when>
                  <otherwise>
                     <log loggingLevel="ERROR" message="${headers.NTX_loggingKey} Connector not found: service=uniform-service; profile=${headers[X-SystemName]}; direction=out"/>
                     <throwException exceptionType="ru.entaxy.platform.services.runtime.exceptions.ConnectorNotFound" message="Connector not found: service=uniform-service; profile=${headers[X-SystemName]}; direction=out"/>
                  </otherwise>
               </choice>
            </when>
            <otherwise>
               <log loggingLevel="ERROR" message="${headers.NTX_loggingKey} Uniform service operation ${header.operationName} isn't support"/>
               <throwException exceptionType="java.lang.IllegalArgumentException" message="Uniform service operation ${header.operationName} isn't support"/>
            </otherwise>
         </choice>
      </route>
   </camelContext>
</blueprint>
