Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B8B3E17C29 for ; Mon, 20 Oct 2014 18:01:56 +0000 (UTC) Received: (qmail 87106 invoked by uid 500); 20 Oct 2014 18:01:56 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 87041 invoked by uid 500); 20 Oct 2014 18:01:56 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 87032 invoked by uid 99); 20 Oct 2014 18:01:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Oct 2014 18:01:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 41B899D31C1; Mon, 20 Oct 2014 18:01:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkulp@apache.org To: commits@cxf.apache.org Date: Mon, 20 Oct 2014 18:01:56 -0000 Message-Id: In-Reply-To: <906883b7f89a4a15824cde51ec04ad7f@git.apache.org> References: <906883b7f89a4a15824cde51ec04ad7f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: Update UDPDestination to allow specifying the interface to use via a property Also, try to decect a usable interface if not specified Update UDPDestination to allow specifying the interface to use via a property Also, try to decect a usable interface if not specified Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/00ee55be Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/00ee55be Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/00ee55be Branch: refs/heads/master Commit: 00ee55be4b799f19b3a11624fd8d34ade0763e83 Parents: c1532bf Author: Daniel Kulp Authored: Mon Oct 20 13:21:25 2014 -0400 Committer: Daniel Kulp Committed: Mon Oct 20 13:21:25 2014 -0400 ---------------------------------------------------------------------- .../cxf/transport/udp/UDPDestination.java | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/00ee55be/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java ---------------------------------------------------------------------- diff --git a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java index f06304d..aec65f6 100644 --- a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java +++ b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java @@ -25,9 +25,15 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.DatagramPacket; import java.net.InetSocketAddress; +import java.net.InterfaceAddress; import java.net.MulticastSocket; +import java.net.NetworkInterface; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URI; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; import java.util.logging.Logger; import org.apache.cxf.Bus; @@ -56,6 +62,8 @@ import org.apache.mina.transport.socket.nio.NioDatagramAcceptor; * */ public class UDPDestination extends AbstractDestination { + public static final String NETWORK_INTERFACE = UDPDestination.class.getName() + ".NETWORK_INTERFACE"; + private static final Logger LOG = LogUtils.getL7dLogger(UDPDestination.class); private static final AttributeKey KEY_IN = new AttributeKey(StreamIoHandler.class, "in"); private static final AttributeKey KEY_OUT = new AttributeKey(StreamIoHandler.class, "out"); @@ -165,6 +173,7 @@ public class UDPDestination extends AbstractDestination { socket.setSendBufferSize(64 * 1024); socket.setTimeToLive(1); socket.bind(new InetSocketAddress(isa.getPort())); + socket.setNetworkInterface(findNetworkInterface()); socket.joinGroup(isa.getAddress()); mcast = socket; queue.execute(new MCastListener()); @@ -185,6 +194,34 @@ public class UDPDestination extends AbstractDestination { throw new RuntimeException(ex); } } + private NetworkInterface findNetworkInterface() throws SocketException { + String name = (String)this.getEndpointInfo().getProperty(UDPDestination.NETWORK_INTERFACE); + NetworkInterface ret = null; + if (!StringUtils.isEmpty(name)) { + ret = NetworkInterface.getByName(name); + } + if (ret == null) { + Enumeration ifcs = NetworkInterface.getNetworkInterfaces(); + List possibles = new ArrayList(); + 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); + } + } + } + } + ret = possibles.isEmpty() ? null : possibles.get(possibles.size() - 1); + + } + return ret; + } + protected void deactivate() { if (acceptor != null) { acceptor.unbind();