2013-12-13 34 views
3

我想知道是否可以在spring mvc应用程序和使用TCP-IP连接的传统系统之间插入双向连接。如何在Spring MVC应用程序中插入TCP-IP客户端服务器

作为提及遗留系统与TCP/IP而不是http协作,所以不需要谈论HTTP如何更好,谢谢!

+0

我不知道答案(我对'spring'不熟悉),但'遗留系统与TCP/IP协同工作,不需要HTTP,所以不需要谈论HTTP如何更好“任何意义;他们不是竞争协议。 – admdrew

+0

是的但在其他答案人们说http更好等 – romu31

回答

8

参见Spring Integration。您可以使用短信网关

简单地连线的SI流进你的MVC控制器

控制器 - >网关 - > {可选的过滤/转换} - > TCP出站网关

网关使用其服务注入到控制器-接口。

tcp-client-server sample显示如何。

编辑:

如果现在还不清楚从样品,你需要定义SI流...

<!-- 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)"/> 

并注入网关到您的@Controller ...

public interface SimpleGateway { 

    public String send(String text); 

} 

@Controller 
public class MyController { 

     @Autowired 
     SimpleGateway gw; 

    ... 
} 
+0

谢谢,所以如果我得到它的权利网关将成为控制器的成员? – romu31

+0

我想我的问题可能是什么是推动TCP/IP客户端服务器到一个春天MVC应用程序的最佳解决方案 – romu31

+0

我认为这就是我的回答;如果从样本中不清楚,我更新了答案。 TCP材料的完整文档在这里:http://docs.spring.io/spring-integration/docs/2.2.6.RELEASE/reference/html/ip.html如果你说你想让你的控制器作为服务器(而不是客户端),那么你可以使用示例的服务器端。 –

相关问题