From 3b7696449b710c0e64f85379863f3241c7243103 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 28 May 2010 22:25:05 +0000 Subject: [PATCH] INT-1146 close on inbound adapter should close socket regardless of success of channel send --- .../ip/tcp/TcpNetReceivingChannelAdapter.java | 4 +++- .../ip/tcp/TcpNioReceivingChannelAdapter.java | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNetReceivingChannelAdapter.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNetReceivingChannelAdapter.java index 38932f6192..78cea2dff5 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNetReceivingChannelAdapter.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNetReceivingChannelAdapter.java @@ -102,7 +102,6 @@ public class TcpNetReceivingChannelAdapter extends return; } if (messageStatus == SocketReader.MESSAGE_COMPLETE) { - processMessage(reader); if (close) { logger.debug("Closing socket because close=true"); try { @@ -110,6 +109,9 @@ public class TcpNetReceivingChannelAdapter extends } catch (IOException ioe) { logger.error("Error on close", ioe); } + } + processMessage(reader); + if (close) { break; } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNioReceivingChannelAdapter.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNioReceivingChannelAdapter.java index 1e778a7eae..5cabc88d78 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNioReceivingChannelAdapter.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpNioReceivingChannelAdapter.java @@ -177,21 +177,23 @@ public class TcpNioReceivingChannelAdapter extends return; } if (messageStatus == SocketReader.MESSAGE_COMPLETE) { + if (close) { + logger.debug("Closing channel because close=true"); + try { + key.channel().close(); + } catch (IOException ioe) { + logger.error("Error on close", ioe); + } + } Message message; message = mapper.toMessage(reader); if (message != null) { sendMessage(message); - if (close) { - logger.debug("Closing channel because close=true"); - try { - key.channel().close(); - } catch (IOException ioe) { - logger.error("Error on close", ioe); - } - } } } - } catch (Exception e) {} + } catch (Exception e) { + logger.error("Failure on read or message send", e); + } } @Override