Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 1a96465f1 -> 43f6a421a
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/1c876942 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1c876942 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1c876942 Branch: refs/heads/3.0.x-fixes Commit: 1c8769426d0f23d1f8c217c89a06d955d31ea286 Parents: 1a96465 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:16:09 2014 -0400 ---------------------------------------------------------------------- .../cxf/ws/discovery/WSDiscoveryClientTest.java | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/1c876942/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);