You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/12/24 04:49:06 UTC

[2/2] camel git commit: CAMEL-8168 Fixed the issue that mina2 doesn't unbind from the listening port

CAMEL-8168 Fixed the issue that mina2 doesn't unbind from the listening port


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4dd8545f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4dd8545f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4dd8545f

Branch: refs/heads/camel-2.13.x
Commit: 4dd8545f6d33ba02acef67ad0f87623d58b98cc4
Parents: 64d5bed
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 22 08:49:14 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 24 11:48:46 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/component/mina2/Mina2Consumer.java  | 12 +++++++++++-
 .../apache/camel/component/mina2/Mina2TcpTest.java   | 15 +++++++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4dd8545f/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
----------------------------------------------------------------------
diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
index 29ce424..c2f859a 100644
--- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
+++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
@@ -95,7 +95,17 @@ public class Mina2Consumer extends DefaultConsumer {
     @Override
     protected void doStop() throws Exception {
         LOG.info("Unbinding from server address: {} using acceptor: {}", address, acceptor);
-        acceptor.unbind(address);
+        if (address instanceof InetSocketAddress) {
+            // need to check if the address is IPV4 TCP all net work address
+            if ("0.0.0.0".equals(((InetSocketAddress)address).getAddress().getHostAddress())) {
+                System.out.println("Unbind the server address " + acceptor.getLocalAddresses());
+                acceptor.unbind(acceptor.getLocalAddresses());
+            } else {
+                acceptor.unbind(address);
+            }   
+        } else {
+            acceptor.unbind(address);
+        }
         super.doStop();
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4dd8545f/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java b/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
index f268a10..f9b1762 100644
--- a/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
+++ b/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
@@ -26,7 +26,18 @@ import org.junit.Test;
 public class Mina2TcpTest extends BaseMina2Test {
 
     @Test
-    public void testMinaRoute() throws Exception {
+    public void testMinaRoute1() throws Exception {
+        MockEndpoint endpoint = getMockEndpoint("mock:result");
+        Object body = "Hello there!";
+        endpoint.expectedBodiesReceived(body);
+
+        template.sendBodyAndHeader(String.format("mina2:tcp://localhost:%1$s?sync=false&minaLogger=true", getPort()), body, "cheese", 123);
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    @Test
+    public void testMinaRoute2() throws Exception {
         MockEndpoint endpoint = getMockEndpoint("mock:result");
         Object body = "Hello there!";
         endpoint.expectedBodiesReceived(body);
@@ -40,7 +51,7 @@ public class Mina2TcpTest extends BaseMina2Test {
         return new RouteBuilder() {
 
             public void configure() {
-                from(String.format("mina2:tcp://localhost:%1$s?sync=false&minaLogger=true", getPort())).to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+                from(String.format("mina2:tcp://0.0.0.0:%1$s?sync=false&minaLogger=true", getPort())).to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
             }
         };
     }