2014-04-11 5 views
0

저는 스프링 통합을 사용하여 TCP 서버를 만들고 junit과 함께 작동하는지 테스트합니다. 문제는 내가 오류가 발생했다는 것입니다. org.springframework.integration.ip.tcp.TcpOutboundGateway - 응답을 연관시킬 수 없습니다 - 보류중인 응답이 없습니다. 제발 도와주세요. 여기에 더 많은 정보가 있습니다. 서버에 데이터를 보내는 유닛 테스트가 있는데 서버는 데이터의 각 부분에서 "성공"으로 응답해야합니다. 하지만 읽기 데이터의 두 번째 부분 이후에, TcpOutboundGateway (단위 테스트 측에서)는 로그에 오류를 씁니다.TcpOutboundGateway - 응답을 연관시킬 수 없음 - 응답이 없습니다.

So Server configuration file:

<int-ip:tcp-connection-factory id="crLfServer" 
    type="server" 
    port="5000" 
    single-use="false" 
    so-timeout="10000" 
    /> 

<task:executor id="pool" pool-size="16"/> 

<int-ip:tcp-inbound-gateway id="gatewayCrLf" 
    connection-factory="crLfServer" 
    request-channel="serverBytes2StringChannel" 
    error-channel="errorChannel"/> 

<int:channel id="toSA" > 
    <int:dispatcher task-executor="pool" /> 
</int:channel> 

<int:service-activator input-channel="toSA" 
    ref="connectionHandler" 
    method="handleData" /> 


<bean id="connectionHandler" class="com.pc.tracker.utils.ConnectionHandler" /> 
<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper"/> 

<int:transformer id="serverBytes2String" 
    input-channel="serverBytes2StringChannel" 
    output-channel="toSA" 
    expression="new String(payload).trim()"/> 

<int:transformer id="errorHandler" 
    input-channel="errorChannel" 
    expression="payload.failedMessage.payload + ':' + payload.cause.message"/> 

클라이언트 구성 파일 :

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

이미 언급 한 오류가 발생 시험.

@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); 

는 여기에 내가 문제를 해결 이일 보냈다

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 데이터를 전송하는

+0

어떤 스프링 통합 버전을 사용하고 있습니까? –

+0

스프링 통합 3.0.0을 사용합니다. –

+0

이것은 나에게 의미가 없습니다. 응답 메시지와 함께 게이트웨이에 리턴 된 메시지 헤더에 문제가 있음을 의미합니다. 응답에 응답을 연관시키기 위해'ip_connectionId '가 사용됩니다. 귀하의 설정에서 나와 아무런 차이가 없습니다. 'TRACE' 로깅을 켜고 그 결과를 tcp-client-server 샘플 https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client- 서버에서 어떤 차이가 있는지 확인할 수 있습니다. StackOverflow는 그것을 허용하지 않지만 당신이 어딘가에 로그를 게시 할 수 있다면, 나는 그것을 볼 수 있습니다. –

답변

0

...

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,340 

(의 onMessage() 호출)에서 수신 및

2014-04-12 11:27:11,343 

다음에 회신 채널로 전송됩니다

2014-04-12 11:27:11,307 

에서 요청을 보낸 것을 볼 수 있습니다 해당 소켓의 활동이 다른 메시지의 수신이었습니다.

2014-04-12 11:27:11,346 

오류 메시지가 대기중인 사람이 없었습니다.

지금, 접속 ID를보고, 우리는 서버에

대응하는 연결 ID는 localhost:51420:5000:66862ff3-3f40-4291-938f-0694bf3727be입니다 ... 원격 소켓 51420 것을 볼, 그래서 서버 측에서 살펴 보겠습니다 수 있습니다. 메시지 Available to read:525 알 - 원래 요청에 대한 응답 success는 같은 스레드 (다른 전송하지 않고) 다른 메시지를 읽습니다, 그러나

2014-04-12 11:27:11,339 

에 보내졌다.

따라서 결론은 메시지가 \r\n으로 끝나기를 기대하는 기본 (비) 직렬기를 사용하고 있는데 서버 측이 여러 요청을 "볼"때 \r\n이 포함 된 요청을 보내고 있습니다. 발신자는 하나의 메시지 만 보냈습니다.

TCP는 스트리밍 프로토콜입니다. 서버 측면에서 메시지가 완료 될 때 데이터를 어떻게 든 프레임화해야합니다. \r\n이 포함 된 데이터를 보내야하는 경우 데이터의 끝을 감지하기 위해 다른 디시리얼라이저를 사용해야합니다 (가장 효율적인 길이 헤더 구현 일 수 있습니다).

사용할 수있는 표준 serializer 및 사용자 지정 정보는 documented here입니다.

+0

대단히 감사합니다. –

관련 문제