<?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:int="http://www.springframework.org/schema/integration"
	xmlns:ip="http://www.springframework.org/schema/integration/ip"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/integration/ip https://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
		http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
		http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">

	<int:channel id="udpChannel" />

	<int:channel id="tcpChannel" />

	<int:channel id="replyChannel" />

	<task:executor id="externalTE" pool-size="10"/>

	<bean id="udpCust" class = "org.springframework.integration.ip.config.ParserUnitTests$SocketCust"/>

	<ip:udp-inbound-channel-adapter id="testInUdp"
		channel="udpChannel"
		check-length="true"
		multicast="false"
		pool-size="27"
		port="0"
		receive-buffer-size="29"
		so-receive-buffer-size="30"
		so-send-buffer-size="31"
		so-timeout="32"
		local-address="127.0.0.1"
		task-executor="externalTE"
		error-channel="errorChannel"
		lookup-host="false"
		auto-startup="false"
		phase="1234"
		socket-customizer="udpCust"
	/>

	<ip:udp-inbound-channel-adapter id="testInUdpMulticast"
		channel="udpChannel"
		check-length="true"
		multicast="true"
		multicast-address="225.6.7.8"
		pool-size="27"
		port="0"
		receive-buffer-size="29"
		so-receive-buffer-size="30"
		so-send-buffer-size="31"
		so-timeout="32"
		local-address="127.0.0.1"
	/>

	<ip:tcp-connection-factory id="cfS1"
		type="server"
		port="0"
		lookup-host="false"
		apply-sequence="true"
		ssl-context-support="sslContextSupport"
		mapper="mapper"
		/>

	<bean id="mapper" class="org.springframework.integration.ip.tcp.connection.TcpMessageMapper" />

	<ip:tcp-connection-factory id="cfS1Nio"
		type="server"
		port="0"
		lookup-host="false"
		apply-sequence="true"
		using-nio="true"
		ssl-context-support="sslContextSupport"
		ssl-handshake-timeout="43"
		nio-connection-support="nioConnectionSupport"
		/>

	<bean id="sslContextSupport" class="org.springframework.integration.ip.tcp.connection.DefaultTcpSSLContextSupport">
		<constructor-arg value="classpath:test.ks"/>
		<constructor-arg value="test.truststore.ks"/>
		<constructor-arg value="secret"/>
		<constructor-arg value="secret"/>
	</bean>

	<bean id="nioConnectionSupport"
		class="org.springframework.integration.ip.tcp.connection.DefaultTcpNioSSLConnectionSupport">
		<constructor-arg ref="sslContextSupport" />
	</bean>

	<ip:tcp-connection-factory id="secureServer"
		type="server"
		port="0"
		lookup-host="false"
		apply-sequence="true"
		ssl-context-support="sslContextSupport"
		socket-support="socketSupport"
		net-connection-support="netConnectionSupport"
		socket-factory-support="socketFactorySupport" />

	<bean id="netConnectionSupport"
		class="org.springframework.integration.ip.tcp.connection.DefaultTcpNetConnectionSupport" />

	<ip:tcp-connection-factory id="secureServerNio"
		type="server"
		port="0"
		lookup-host="false"
		apply-sequence="true"
		using-nio="true"
		ssl-context-support="sslContextSupport"
		ssl-handshake-timeout="34"
		socket-support="socketSupport"
		socket-factory-support="socketFactorySupport" />

	<bean id="socketSupport" class="org.mockito.Mockito" factory-method="mock">
		<constructor-arg value="org.springframework.integration.ip.tcp.connection.TcpSocketSupport"
						 type="java.lang.Class"/>
	</bean>

	<bean id="socketFactorySupport" class="org.mockito.Mockito" factory-method="mock">
		<constructor-arg value="org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport"
						 type="java.lang.Class"/>
	</bean>

	<ip:tcp-inbound-channel-adapter id="testInTcp"
		channel="tcpChannel"
		error-channel="errorChannel"
		connection-factory="cfS1"
		auto-startup="false"
		phase="124"
	/>

	<ip:udp-outbound-channel-adapter id="testOutUdp"
		ack-host="somehost"
		ack-port="0"
		ack-timeout="51"
		acknowledge="true"
		channel="udpChannel"
		check-length="true"
		host="localhost"
		port="0"
		multicast="false"
		so-receive-buffer-size="52"
		so-send-buffer-size="53"
		so-timeout="54"
		local-address="127.0.0.1"
		task-executor="externalTE"
		order="23"
		socket-customizer="udpCust"
	/>

	<ip:udp-outbound-channel-adapter id="testOutUdpiMulticast"
		ack-host="somehost"
		ack-port="0"
		ack-timeout="51"
		acknowledge="true"
		channel="udpChannel"
		check-length="true"
		host="225.6.7.8"
		port="0"
		multicast="true"
		min-acks-for-success="2"
		so-receive-buffer-size="52"
		so-send-buffer-size="53"
		so-timeout="54"
		time-to-live="55"
		order="12"
	/>

	<int:channel id="udpAdviceChannel" >
		<int:queue/>
	</int:channel>

	<ip:udp-outbound-channel-adapter channel="udpAdviceChannel" host="localhost" port="0">
		<int:poller fixed-delay="100"/>
		<ip:request-handler-advice-chain>
			<bean class="org.springframework.integration.ip.config.ParserUnitTests$FooAdvice" />
		</ip:request-handler-advice-chain>
	</ip:udp-outbound-channel-adapter>


	<ip:tcp-connection-factory id="cfC1"
		type="client"
		port="0"
		host="localhost"
		lookup-host="false"
		apply-sequence="false"
		connect-timeout="70"
		read-delay="10000"
		/>

	<ip:tcp-outbound-channel-adapter id="testOutTcpNio"
		channel="tcpChannel"
		connection-factory="cfC1"
		order="35"
		auto-startup="false"
		phase="125"
	/>

	<int:channel id="tcpAdviceChannel">
		<int:queue/>
	</int:channel>

	<ip:tcp-outbound-channel-adapter id="tcpOutAdvice"
		channel="tcpAdviceChannel"
		connection-factory="mockClientCf"
		phase="125">
		<int:poller fixed-delay="100"/>
		<ip:request-handler-advice-chain>
			<bean class="org.springframework.integration.ip.config.ParserUnitTests$FooAdvice" />
		</ip:request-handler-advice-chain>
	</ip:tcp-outbound-channel-adapter>

	<ip:tcp-connection-factory id="cfS2"
		type="server"
		port="0"
		/>

	<ip:tcp-inbound-gateway id="inGateway1"
		request-channel="tcpChannel"
		reply-channel="replyChannel"
		error-channel="errorChannel"
		connection-factory="cfS2"
		reply-timeout="456"
		auto-startup="false"
		phase="126"
		/>

	<ip:tcp-connection-factory id="cfS3"
		type="server"
		port="0"
		/>

	<ip:tcp-inbound-gateway id="inGateway2"
		request-channel="tcpChannel"
		reply-channel="replyChannel"
		connection-factory="cfS3"
		reply-timeout="456"
		/>

	<ip:tcp-connection-factory id="cfC2"
		type="client"
		port="0"
		host="localhost"
		/>

	<ip:tcp-outbound-gateway id="outGateway"
		request-channel="tcpChannel"
		reply-channel="replyChannel"
		connection-factory="cfC2"
		request-timeout="234"
		reply-timeout="567"
		remote-timeout="789"
		order="24"
		auto-startup="false"
		phase="127"
		async="true"
		/>

	<int:channel id="tcpAdviceGateChannel">
		<int:queue/>
	</int:channel>

	<ip:tcp-outbound-gateway id="outAdviceGateway"
		request-channel="tcpAdviceGateChannel"
		reply-channel="replyChannel"
		remote-timeout-expression="4000"
		close-stream-after-send="true"
		connection-factory="mockClientCf">
		<int:poller fixed-delay="100"/>
		<ip:request-handler-advice-chain>
			<bean class="org.springframework.integration.ip.config.ParserUnitTests$FooAdvice" />
		</ip:request-handler-advice-chain>
	</ip:tcp-outbound-gateway>

	<ip:tcp-connection-factory
		id="client1"
		type="client"
		host="localhost"
		port="0"
		serializer="defaultSerializer"
		deserializer="defaultDeserializer"
		so-keep-alive="true"
		so-linger="54"
		so-receive-buffer-size="1234"
		so-send-buffer-size="1235"
		so-tcp-no-delay="true"
		so-timeout="1236"
		so-traffic-class="12"
		using-nio="#{props['use.nio']}"
		single-use="true"
		task-executor="externalTE"
		using-direct-buffers="true"
		interceptor-factory-chain="interceptors"
	/>

	<util:properties id="props">
		<prop key="use.nio">true</prop>
	</util:properties>

	<ip:tcp-connection-factory
		id="server1"
		type="server"
		port="#{client1.port}"
		local-address="127.0.0.1"
		serializer="defaultSerializer"
		deserializer="defaultDeserializer"
		so-keep-alive="true"
		so-linger="55"
		so-receive-buffer-size="1234"
		so-send-buffer-size="1235"
		so-tcp-no-delay="true"
		so-timeout="1236"
		so-traffic-class="12"
		using-nio="true"
		single-use="true"
		task-executor="externalTE"
		backlog="123"
		using-direct-buffers="true"
		interceptor-factory-chain="interceptors"
	/>

	<ip:tcp-connection-factory
		id="client2"
		type="client"
		host="localhost"
		port="0"
		serializer="defaultSerializer"
		deserializer="defaultDeserializer"
		so-keep-alive="true"
		so-linger="54"
		so-receive-buffer-size="1234"
		so-send-buffer-size="1235"
		so-tcp-no-delay="true"
		so-timeout="1236"
		so-traffic-class="12"
		using-nio="false"
		single-use="true"
		task-executor="externalTE"
		interceptor-factory-chain="interceptors"
	/>

	<ip:tcp-connection-factory
		id="server2"
		type="server"
		port="#{client1.port}"
		local-address="127.0.0.1"
		serializer="defaultSerializer"
		deserializer="defaultDeserializer"
		so-keep-alive="true"
		so-linger="55"
		so-receive-buffer-size="1234"
		so-send-buffer-size="1235"
		so-tcp-no-delay="true"
		so-timeout="1236"
		so-traffic-class="12"
		using-nio="false"
		single-use="true"
		task-executor="externalTE"
		backlog="123"
		interceptor-factory-chain="interceptors"
	/>

	<bean id="interceptors" class="org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain" />

	<bean id="defaultSerializer" class="org.springframework.core.serializer.DefaultSerializer" />

	<bean id="defaultDeserializer" class="org.springframework.core.serializer.DefaultDeserializer" />

	<ip:tcp-outbound-channel-adapter id="tcpNewOut1"
		channel="tcpChannel"
		connection-factory="client1"
		order="25"/>

	<ip:tcp-outbound-channel-adapter id="tcpNewOut2"
		channel="tcpChannel"
		connection-factory="server1"
		order="15"/>

	<ip:tcp-inbound-channel-adapter id="tcpNewIn1"
		channel="tcpChannel"
		connection-factory="client1" />

	<ip:tcp-inbound-channel-adapter id="tcpNewIn2"
		channel="tcpChannel"
		connection-factory="server1" />

	<ip:tcp-connection-factory id="cfC3"
		type="client"
		port="0"
		host="localhost"
		lookup-host="false"
		apply-sequence="false"
		/>

	<ip:tcp-inbound-channel-adapter id="tcpInClientMode"
		channel="tcpChannel"
		connection-factory="cfC3"
		client-mode="true"
		retry-interval="123000"
		auto-startup="false"
		scheduler="scheduler" />

	<ip:tcp-connection-factory id="cfC4"
		type="client"
		port="0"
		host="localhost"
		lookup-host="false"
		apply-sequence="false"
		/>

	<ip:tcp-outbound-channel-adapter id="tcpOutClientMode"
		channel="tcpChannel"
		connection-factory="cfC4"
		client-mode="true"
		retry-interval="124000"
		scheduler="scheduler"
		auto-startup="false" />

	<ip:tcp-connection-factory id="cfC5"
		type="client"
		port="0"
		host="localhost"
		lookup-host="false"
		apply-sequence="false"
		/>

	<ip:tcp-inbound-gateway id="inGatewayClientMode"
		request-channel="tcpChannel"
		reply-channel="replyChannel"
		connection-factory="cfC5"
		reply-timeout="456"
		client-mode="true"
		retry-interval="125000"
		scheduler="scheduler"
		auto-startup="false"
		/>

	<bean id="scheduler"
				class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
		<property name="phase" value="1073741823"/>
	</bean>

	<ip:tcp-inbound-channel-adapter id="tcpAutoChannel" />

	<int:bridge input-channel="tcpAutoChannel" output-channel="nullChannel" />

	<ip:udp-inbound-channel-adapter id="udpAutoChannel" port="0" />

	<int:bridge input-channel="udpAutoChannel" output-channel="nullChannel" />

	<bean id="failCF" class="org.springframework.integration.ip.tcp.connection.FailoverClientConnectionFactory">
		<constructor-arg>
			<list>
				<ref bean="cfC1"/>
				<ref bean="cfC2"/>
			</list>
		</constructor-arg>
	</bean>

</beans>
