繁体   English   中英

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

[英]TCP Client Spring Integration with Legacy Server

我需要一些帮助来迁移到 Spring 集成。 Actually we have a component based in java.net package, it includes only a few classes with a java classic TCP Client, nothing fancy, that actually works to send some requests to a legacy server by 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" />

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

这是来自服务器的日志,我尝试了几种反序列化器,结果相同,2020-06-21 23:47:10.377 ERROR 1 --- [nio-8080-exec-7] osiip.ZE20BB202B1D5537B1415TcpZOutboundGateway3. : Tcp Gateway exception org.springframework.integration.MessageTimeoutException: Timed out waiting for response at org.springframework.integration.ip.tcp.TcpOutboundGateway.getReply(TcpOutboundGateway.java:243) ~[spring-integration-ip-5.3.0. RELEASE.jar:5.3.0.RELEASE]

对于printlnreadLine的等效项,您需要一个ByteArrayLfSerializer (如果在 Linux/Unix/Mac 上运行客户端)或默认的ByteArrayCrLfSerializer (如果在 Windows 上运行客户端)。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM