TCP客户端Spring与旧服务器的集成

TCP客户端Spring与旧服务器的集成,spring,tcp,spring-integration,tcpclient,Spring,Tcp,Spring Integration,Tcpclient,我需要一些迁移到Spring集成的帮助。 实际上,我们有一个基于java.net包的组件,它只包含几个带有java经典TCP客户机的类,没有什么特别之处,它实际上可以通过TCP将一些请求发送到遗留服务器。这是用于发送和接收消息的代码: public String sendMessage(String info) { try { PrintStream ps = new PrintStream(clientSocket.getOutputStream());

我需要一些迁移到Spring集成的帮助。 实际上,我们有一个基于java.net包的组件,它只包含几个带有java经典TCP客户机的类,没有什么特别之处,它实际上可以通过TCP将一些请求发送到遗留服务器。这是用于发送和接收消息的代码:

public String sendMessage(String info) {

    try {
        PrintStream ps = new PrintStream(clientSocket.getOutputStream());
        ps.println(info);

        InputStreamReader ir = new InputStreamReader(clientSocket.getInputStream());
        BufferedReader br = new BufferedReader(ir);

        return br.readLine();

    } catch (IOException e) {
        log.debug(e.getMessage());
    }
    return "";
}
问题是我想在客户端开始使用Spring集成,但我无法更改服务器,因为它属于另一家公司,但我没有收到服务器的响应,我尝试了很多配置,但一点运气都没有。 这是我现在的客户端配置:

            <int:gateway id="gw"
                 service-interface="pe.financieraoh.core.cointegrador.tcp.SimpleGateway"
                 default-request-channel="input"/>

    <int-ip:tcp-connection-factory id="client"
                                   type="client"
                                   host="localhost"
                                   port="7777"
                                   single-use="false"
                                   serializer="connectionSerializeDeserialize"
                                   deserializer="connectionSerializeDeserialize"
                                    />
    <int:channel id="input" />

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

<bean id="connectionSerializeDeserialize" 
          class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer"/>

<int:object-to-string-transformer id="clientBytes2String"
                                      input-channel="clientBytes2StringChannel" />


我尝试了很多,总是收到超时连接异常,我很确定服务器没有收到我的请求,但我不能确定,因为我没有访问服务器日志的权限。我唯一的指南是客户端中的遗留代码可以正常工作。 谢谢你的帮助


这是来自服务器的日志,我尝试了几种反序列化程序,结果相同,2020-06-21 23:47:10.377错误1---[nio-8080-exec-7]o.s.i.ip.tcp.TcpOutboundGateway:tcp网关异常org.springframework.integration.MessageTimeoutException:org.springframework.integration.ip.tcp.TcpOutboundGateway.getReply(TcpOutboundGateway.java:243)~[spring-integration-ip-5.3.0.RELEASE.jar:5.3.0.RELEASE]

对于
println
readLine
的等价物,您需要一个
ByteArrayFserializer
(如果在Linux/Unix/Mac上运行客户端)或默认的
ByteArrayRfSerializer
(如果在Windows上运行客户端)


如果这不起作用,请使用WireShark或类似工具查看网络流量。

请使用日志更新问题,而不是在评论中发布。感谢Gary的回答,我对序列化程序不感兴趣,我将尝试查看WireShark的情况,但我需要检查如何操作,因为连接在两台服务器之间,我无法从本地计算机访问tcp服务器;您可以在客户端计算机上运行wireshark来捕获网络流量。另一种可能性是服务器正在关闭套接字以发出结束信号(而不是CRLF或LF)。在这种情况下,请尝试一个
ByteArrayRawDeserializer
。太好了,是的,我会在openshift中使用sidecard tcpdump来捕获流量,我想明天我会得到更多信息,同时我会尝试ByteArrayRawDeserializer,真的再次感谢GaryHi。我可以再次使用tcpdump和wireshark检查配置是否正常,我还有一个问题,比如防火墙或网关系统,那就是过滤与外部服务器的通信,但我不知道,为什么会这样。消息在网关中接收良好,但在最终系统中未接收,因此我收到一个“超时异常”,我将与Operation或DevOps进行检查。再次感谢加里的帮助