Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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-ip="http://www.springframework.org/schema/integration/ip"
- xmlns:int="http://www.springframework.org/schema/integration"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:util="http://www.springframework.org/schema/util"
- xmlns:task="http://www.springframework.org/schema/task"
- xmlns:stream="http://www.springframework.org/schema/integration/stream"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
- http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
- http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd
- http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip-2.2.xsd
- http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.2.xsd">
- <!-- Scans all classes that located below and do injection -->
- <context:component-scan base-package="org.example.tcpserver"/>
- <!-- Activates various annotations to be detected in bean classes. -->
- <context:annotation-config/>
- <!--
- Byte arrays serializer used by server in order to properly send a message.
- It means, that a sender before sending should encode a message and it's
- done by serializer. A receiver, before taking a message, should deserialize
- coming message, it's done by deserializer.
- -->
- <bean id="byteArrayLenSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"/>
- <!-- This TCP factory creates an instance named testServer.
- Spring Integration IP implements AbstractServerConnectionFactory.
- @id - a server name
- @type - either server or client
- @port - to be opened for listening
- @single-use - If true, a new connection will be created for each use.
- @serializer - to be used to marshall outcoming messages.
- @deserializer - to be used to unmarshall incoming messages.
- -->
- <int-ip:tcp-connection-factory id="tcpServerFactory"
- type="server"
- port="23234"
- single-use="false"
- serializer="byteArrayLenSerializer"
- deserializer="byteArrayLenSerializer"
- />
- <!-- Defines server's input channel -->
- <int:channel id="serverIn" />
- <!-- Defines server's output server -->
- <int:channel id="serverOut" />
- <int-ip:tcp-inbound-channel-adapter channel="serverIn" connection-factory="tcpServerFactory"/>
- <int-ip:tcp-outbound-channel-adapter channel="serverOut" connection-factory="tcpServerFactory"/>
- <!-- Defines a service for server side business logic. Lately will be used as reference. -->
- <bean id="fileSenderService" class="org.example.tcpserver.FileSenderService"
- p:sender-ref="serverOut"
- p:file="file:${file}"
- />
- <int:service-activator ref="fileSenderService" method="send" input-channel="serverIn"/>
- <!--
- If you don't listen to the default error channel you risk losing track
- of exceptions, as they cannot be passed back to the sender in band. It
- is recommended to have a generic error handler in your configuration
- to prevent this.
- -->
- <stream:stderr-channel-adapter id="errorAdapter"
- channel="errorChannel"
- append-newline="true"
- />
- <!-- Error channel -->
- <int:channel id="errorChannel">
- <int:interceptors>
- <int:wire-tap channel="byteArrayErrorChannel"/>
- </int:interceptors>
- </int:channel>
- <int:channel id="byteArrayErrorChannel"/>
- <int:service-activator input-channel="byteArrayErrorChannel">
- <bean class="org.example.tcpserver.ServerErrorHandler" />
- </int:service-activator>
- </beans>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement