title: TcpOutboundGateway - Cannot correlate response - no pending reply
body: <p>I'm using spring integration to create TCP server and also to test if it works with junit. The problem is that i'm receiving an error: org.springframework.integration.ip.tcp.TcpOutboundGateway - Cannot correlate response - no pending reply. Please help me to fix it. Here is more info. I have unit test that send some data to server, server has to reply with "success" on each portion of data. but after second portion of read data, TcpOutboundGateway (on unit test side) write error to log.</p>
  
  <blockquote>
    <p>So Server configuration file:</p>
  </blockquote>
  
  <pre><code>&lt;int-ip:tcp-connection-factory id="crLfServer"
      type="server"
      port="5000"
      single-use="false"
      so-timeout="10000"
       /&gt;
  
  &lt;task:executor id="pool" pool-size="16"/&gt;
  
  &lt;int-ip:tcp-inbound-gateway id="gatewayCrLf"
      connection-factory="crLfServer"
      request-channel="serverBytes2StringChannel"
      error-channel="errorChannel"/&gt;
  
  &lt;int:channel id="toSA" &gt;
      &lt;int:dispatcher task-executor="pool" /&gt;
  &lt;/int:channel&gt;
  
  &lt;int:service-activator input-channel="toSA"
      ref="connectionHandler"
      method="handleData" /&gt;
  
  
  &lt;bean id="connectionHandler" class="com.pc.tracker.utils.ConnectionHandler" /&gt;
  &lt;bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper"/&gt;
  
  &lt;int:transformer id="serverBytes2String"
      input-channel="serverBytes2StringChannel"
      output-channel="toSA"
      expression="new String(payload).trim()"/&gt;
  
  &lt;int:transformer id="errorHandler"
      input-channel="errorChannel"
      expression="payload.failedMessage.payload + ':' + payload.cause.message"/&gt;
  </code></pre>
  
  <p>Client configuration file:</p>
  
  <pre><code>&lt;int:gateway id="gw"
      service-interface="com.pc.tracker.tcp.ConnectionHandlerTestHellperGateway"
      default-request-channel="input"/&gt;
  
  &lt;int-ip:tcp-connection-factory id="client"
      type="client"
      host="localhost"
      port="5000"
      single-use="false"
      so-timeout="10000"/&gt;
  
  &lt;int:channel id="input" /&gt;
  
  &lt;int-ip:tcp-outbound-gateway id="outGateway"
      request-channel="input"
      reply-channel="clientBytes2StringChannel"
      connection-factory="client"
      request-timeout="10000"
      reply-timeout="10000"/&gt;
  
  &lt;int:transformer id="clientBytes2String"
      input-channel="clientBytes2StringChannel"
      expression="new String(payload)"/&gt;
  </code></pre>
  
  <p>and test that produce already mentioned error.</p>
  
  <pre><code>    @Test
  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);
  </code></pre>
  
  <p>here is log with error</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>I've spent two days solving the problem.
  sorry for long question.
  Thanks.</p>