SHARE
TWEET

server-config.xml

olegtikhonov Apr 1st, 2013 333 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
  5.        xmlns:int="http://www.springframework.org/schema/integration"
  6.        xmlns:context="http://www.springframework.org/schema/context"
  7.        xmlns:p="http://www.springframework.org/schema/p"
  8.        xmlns:util="http://www.springframework.org/schema/util"
  9.        xmlns:task="http://www.springframework.org/schema/task"
  10.        xmlns:stream="http://www.springframework.org/schema/integration/stream"
  11.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  12.           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  13.           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
  14.           http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
  15.           http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd
  16.           http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip-2.2.xsd
  17.           http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.2.xsd">
  18.  
  19.  
  20.     <!-- Scans all classes that located below and do injection -->
  21.     <context:component-scan base-package="org.example.tcpserver"/>
  22.     <!-- Activates various annotations to be detected in bean classes. -->
  23.     <context:annotation-config/>
  24.  
  25.     <!--
  26.         Byte arrays serializer used by server in order to properly send a message.
  27.         It means, that a sender before sending should encode a message and it's
  28.         done by serializer. A receiver, before taking a message, should deserialize
  29.         coming message, it's done by deserializer.
  30.     -->
  31.     <bean id="byteArrayLenSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"/>
  32.  
  33.  
  34.     <!-- This TCP factory creates an instance named testServer.
  35.          Spring Integration IP implements AbstractServerConnectionFactory.
  36.  
  37.          @id - a server name
  38.          @type - either server or client
  39.          @port - to be opened for listening
  40.          @single-use - If true, a new connection will be created for each use.
  41.          @serializer - to be used to marshall outcoming messages.
  42.          @deserializer - to be used to unmarshall incoming messages.
  43.     -->
  44.     <int-ip:tcp-connection-factory id="tcpServerFactory"
  45.                                    type="server"
  46.                                    port="23234"
  47.                                    single-use="false"
  48.                                    serializer="byteArrayLenSerializer"
  49.                                    deserializer="byteArrayLenSerializer"
  50.     />
  51.  
  52.     <!-- Defines server's input channel -->
  53.     <int:channel id="serverIn" />
  54.  
  55.     <!-- Defines server's output server -->
  56.     <int:channel id="serverOut" />
  57.  
  58.     <int-ip:tcp-inbound-channel-adapter channel="serverIn" connection-factory="tcpServerFactory"/>
  59.     <int-ip:tcp-outbound-channel-adapter channel="serverOut" connection-factory="tcpServerFactory"/>
  60.  
  61.     <!-- Defines a service for server side business logic. Lately will be used as reference. -->
  62.     <bean id="fileSenderService" class="org.example.tcpserver.FileSenderService"
  63.         p:sender-ref="serverOut"
  64.         p:file="file:${file}"
  65.     />
  66.    
  67.     <int:service-activator ref="fileSenderService" method="send" input-channel="serverIn"/>
  68.  
  69.     <!--
  70.         If you don't listen to the default error channel you risk losing track
  71.         of exceptions, as they cannot be passed back to the sender in band. It
  72.         is recommended to have a generic error handler in your configuration
  73.         to prevent this.
  74.     -->
  75.     <stream:stderr-channel-adapter id="errorAdapter"
  76.                                    channel="errorChannel"
  77.                                    append-newline="true"
  78.     />
  79.  
  80.     <!-- Error channel -->
  81.     <int:channel id="errorChannel">
  82.         <int:interceptors>
  83.             <int:wire-tap channel="byteArrayErrorChannel"/>
  84.         </int:interceptors>
  85.     </int:channel>
  86.  
  87.     <int:channel id="byteArrayErrorChannel"/>
  88.    
  89.     <int:service-activator input-channel="byteArrayErrorChannel">
  90.         <bean class="org.example.tcpserver.ServerErrorHandler" />
  91.     </int:service-activator>
  92.  
  93. </beans>
RAW Paste Data
Top