How to implement TCP connection handshaking with Spring Integration?

1.1k views Asked by At

I'm new to Spring Integration and currently trying to receive data from some devices over TCP. I've come up with the following Spring context:

<bean id="serializer" class="com.somepackage.CustomSerializer"/>

<int-ip:tcp-connection-factory id="connectionFactory"
                               type="server"
                               port="${tcp.socket.connection.listener.port}"
                               deserializer="serializer" />

The problem with a device's protocol is that upon initial connection it sends a handshaking sequence and expects a magic answer before it starts sending the messages.

A message pattern is different from the handshaking sequence, I cannot implement a serializer that distinguish between these two. If I could I would implement this handshaking process as an interceptor. So I tried to implement a statefull serializer but it turned out that serializers are singletons, shared between different connections.

Could you please advise how to perform some custom negotiation (handshaking) before default mechanisms (splitting data into messages) come into play ? Should I customize a connection factory ?

Thank you !

1

There are 1 answers

3
Jim Garrison On

I think you need a custom TCP Interceptor. From the documentation:

16.4 TCP Connection Interceptors

Connection factories can be configured with a reference to a TcpConnectionInterceptorFactoryChain. Interceptors can be used to add behavior to connections, such as negotiation, security, and other setup. No interceptors are currently provided by the framework but, for an example, see the InterceptedSharedConnectionTests in the source repository.