Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to plug a TCP-IP client server in a spring MVC application

I wonder if it is possible to plug a bidirectional connection between a spring mvc application and a legacy system working with TCP-IP connections.

as mentionned the legacy system works with TCP/ip and not http , so no need to talk about how HTTP is better , thanks !

like image 344
romu31 Avatar asked Dec 13 '13 19:12

romu31


1 Answers

See Spring Integration. You can simply wire an SI flow into your MVC controller using a messaging gateway

Controller->gateway->{optional filtering/transforming}->tcp outbound gateway

The gateway is injected into the controller using its service-interface.

The tcp-client-server sample shows how.

EDIT:

If it's not clear from the sample, you would need to define your SI flow...

<!-- Client side -->

<int:gateway id="gw"
    service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
    default-request-channel="input"/>

<int-ip:tcp-connection-factory id="client"
    type="client"
    host="localhost"
    port="1234"
    single-use="true"
    so-timeout="10000"/>

<int:channel id="input" />

<int-ip:tcp-outbound-gateway id="outGateway"
    request-channel="input"
    reply-channel="clientBytes2StringChannel"
    connection-factory="client"
    request-timeout="10000"
    remote-timeout="10000"/>

<int:transformer id="clientBytes2String"
    input-channel="clientBytes2StringChannel"
    expression="new String(payload)"/>

and inject the Gateway into your @Controller...

public interface SimpleGateway {

    public String send(String text);

}

@Controller 
public class MyController {

        @Autowired
        SimpleGateway gw;

     ...
}
like image 194
Gary Russell Avatar answered Sep 28 '22 03:09

Gary Russell