cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/2] git commit: Try to find a more usable interface as the "default" may not support multicast
Date Mon, 20 Oct 2014 18:01:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/master dfe481df4 -> 00ee55be4


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/c1532bfe
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c1532bfe
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c1532bfe

Branch: refs/heads/master
Commit: c1532bfe95905e1421f65b179f219b6d1bf75ee5
Parents: dfe481d
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Oct 20 13:11:00 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Mon Oct 20 13:12:40 2014 -0400

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/c1532bfe/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);


Mime
View raw message