Spring TcpOutboundGateway-无法关联响应-无挂起的响应

Spring TcpOutboundGateway-无法关联响应-无挂起的响应,spring,spring-integration,tcpserver,Spring,Spring Integration,Tcpserver,我使用spring集成来创建TCP服务器,并测试它是否与junit一起工作。问题是我收到了一个错误:org.springframework.integration.ip.tcp.TcpOutboundGateway-无法关联响应-没有挂起的响应。请帮我修一下。这里有更多信息。我有一个单元测试,它向服务器发送一些数据,服务器必须对数据的每一部分回复“成功”。但在读取数据的第二部分之后,TcpOutboundGateway(在单元测试端)将错误写入日志 因此,服务器配置文件: <int:gat

我使用spring集成来创建TCP服务器,并测试它是否与junit一起工作。问题是我收到了一个错误:org.springframework.integration.ip.tcp.TcpOutboundGateway-无法关联响应-没有挂起的响应。请帮我修一下。这里有更多信息。我有一个单元测试,它向服务器发送一些数据,服务器必须对数据的每一部分回复“成功”。但在读取数据的第二部分之后,TcpOutboundGateway(在单元测试端)将错误写入日志

因此,服务器配置文件:

<int:gateway id="gw"
    service-interface="com.pc.tracker.tcp.ConnectionHandlerTestHellperGateway"
    default-request-channel="input"/>

<int-ip:tcp-connection-factory id="client"
    type="client"
    host="localhost"
    port="5000"
    single-use="false"
    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"
    reply-timeout="10000"/>

<int:transformer id="clientBytes2String"
    input-channel="clientBytes2StringChannel"
    expression="new String(payload)"/>
这是错误日志

    2014-04-11 23:12:23,059 [pool-1] ERROR com.pc.tracker.utils.ConnectionHandler - recived data: [{"s":1,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"},{"s":12,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"}]
2014-04-11 23:12:23,263 [pool-1] ERROR com.pc.tracker.utils.ConnectionHandler - parsisted
2014-04-11 23:12:23,265 [pool-2] ERROR com.pc.tracker.utils.ConnectionHandler - recived data: [{"s":13,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"},{"s":24,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"}]
2014-04-11 23:12:23,330 [pool-2] ERROR com.pc.tracker.utils.ConnectionHandler - parsisted
2014-04-11 23:12:23,331 [pool-2-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply
2014-04-11 23:12:23,332 [pool-3] ERROR com.pc.tracker.utils.ConnectionHandler - recived data: [{"s":1,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"},{"s":12,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"}]
2014-04-11 23:12:23,409 [pool-3] ERROR com.pc.tracker.utils.ConnectionHandler - parsisted
2014-04-11 23:12:23,409 [pool-2-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply
2014-04-11 23:12:23,410 [pool-4] ERROR com.pc.tracker.utils.ConnectionHandler - recived data: [{"s":1,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"},{"s":12,"t":0,"b":0,"sp":0,"long":0,"sa":0,"lat":0,"a":0,"i":"device_for_unit_tests"}]
2014-04-11 23:12:23,487 [pool-4] ERROR com.pc.tracker.utils.ConnectionHandler - parsisted
2014-04-11 23:12:23,488 [pool-2-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply
2014-04-11 23:12:23,489 [pool-5] ERROR com.pc.tracker.utils.ConnectionHandler - recived data: 
2014-04-11 23:12:23,490 [pool-2-thread-1] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply
我花了两天时间解决这个问题。 很抱歉问了这么长时间。
谢谢。

您正在使用嵌入的
\r\n
发送数据

public void testRecivedBackupedData() {
    String testData = 
         "[{\"s\":1,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"},"
        + "{\"s\":12,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"}]\r\n"
       + "[{\"s\":13,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"},"
        + "{\"s\":24,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"}]\r\n"
        + "[{\"s\":1,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"},"
        + "{\"s\":12,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"}]\r\n"
        +"[{\"s\":1,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"},"
        + "{\"s\":12,\"t\":0,\"b\":0,\"sp\":0,\"long\":0,\"sa\":0,\"lat\":0,\"a\":0,\"i\":\"device_for_unit_tests\"}]\r\n";
String result = gw.send(testData);
将它们全部移除;该框架将在末尾添加一个

您的服务器正在套接字上为一个请求发送多个答复。搜索连接id
localhost:5000:51420:9f93417a-c879-4753-a61e-0b9485940d14
。您将看到您将请求发送到

2014-04-12 11:27:11,307
回覆已于

2014-04-12 11:27:11,340
(onMessage()调用)并发送到

2014-04-12 11:27:11,343
该套接字上的下一个活动是接收另一条消息

2014-04-12 11:27:11,346
没有人等待,因此出现错误消息

现在,看看连接ID,我们可以看到远程套接字是“代码> 51420”/代码>,所以让我们看看服务器端…

服务器上相应的连接id是
localhost:51420:5000:66862ff3-3f40-4291-938f-0694bf3727be
。原始请求的答复
成功
已在发送

2014-04-12 11:27:11,339
但是,同一线程读取另一条消息(没有另一次发送)-请注意可读取的消息:
:525

因此,底线是您正在使用默认(反)序列化程序,该程序期望消息以
\r\n
终止,但您发送的请求中嵌入了
\r\n
,因此当发送方只发送一条消息时,服务器端“看到”多个请求

TCP是一种流协议-您需要以某种方式对数据进行帧处理,以便服务器端知道消息何时完成。如果需要发送包含
\r\n
的数据,则需要使用不同的反序列化程序来检测数据的结尾(可能是最有效的长度标头实现)


可用的标准序列化程序及其自定义信息如下。

您使用的是哪个版本的Spring Integration?我使用的是Spring Integration 3.0.0这对我来说毫无意义;这意味着返回到网关的回复消息的消息头有问题-使用
ip\u connectionId
将回复与响应关联起来。你的配置中没有任何东西向我跳出来;我建议您打开
TRACE
level日志记录,并将结果与tcp客户机-服务器示例进行比较,看看是否可以看到一些差异。StackOverflow不允许这样做,但是如果你能把日志发布到某个地方,我可以看看。这是跟踪级别的日志。带有#####的LIN来自服务器端的serviceActivator。谢谢
2014-04-12 11:27:11,346
2014-04-12 11:27:11,339