You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/10/21 22:22:06 UTC

[2/5] git commit: Try to find a more usable interface as the "default" may not support multicast

Try to find a more usable interface as the "default" may not support multicast


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

Branch: refs/heads/2.7.x-fixes
Commit: cf14336a79b16d2922ff0ff9146bf21e2fb27bb2
Parents: ad11608
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Oct 20 13:11:00 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Tue Oct 21 16:21:41 2014 -0400

----------------------------------------------------------------------
 .../cxf/ws/discovery/WSDiscoveryClientTest.java | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/cf14336a/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
----------------------------------------------------------------------
diff --git a/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java b/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
index 2a548aa..e7f7bba 100644
--- a/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
+++ b/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
@@ -22,10 +22,13 @@ package org.apache.cxf.ws.discovery;
 import java.io.InputStream;
 import java.net.DatagramPacket;
 import java.net.InetAddress;
+import java.net.InterfaceAddress;
 import java.net.MulticastSocket;
 import java.net.NetworkInterface;
 import java.net.SocketAddress;
+import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.List;
 
 import javax.jws.WebMethod;
 import javax.jws.WebService;
@@ -55,6 +58,24 @@ import org.junit.Test;
 public final class WSDiscoveryClientTest {
     public static final String PORT = TestUtil.getPortNumber(WSDiscoveryClientTest.class);
    
+    static NetworkInterface findIpv4Interface() throws Exception {
+        Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
+        List<NetworkInterface> possibles = new ArrayList<NetworkInterface>();
+        while (ifcs.hasMoreElements()) {
+            NetworkInterface ni = ifcs.nextElement();
+            if (ni.supportsMulticast()
+                && ni.isUp()) {
+                for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
+                    if (ia.getAddress() instanceof java.net.Inet4Address
+                        && !ia.getAddress().isLoopbackAddress()
+                        && !ni.getDisplayName().startsWith("vnic")) {
+                        possibles.add(ni);
+                    }
+                }
+            }
+        }
+        return possibles.isEmpty() ? null : possibles.get(possibles.size() - 1);
+    }
     
     @Test
     public void testMultiResponses() throws Exception {
@@ -87,6 +108,7 @@ public final class WSDiscoveryClientTest {
                     InetAddress address = InetAddress.getByName("239.255.255.250");
                     MulticastSocket s = new MulticastSocket(Integer.parseInt(PORT));
                     s.setBroadcast(true);
+                    s.setNetworkInterface(findIpv4Interface());
                     s.joinGroup(address);
                     s.setReceiveBufferSize(64 * 1024);
                     s.setSoTimeout(5000);