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 9CA3317947 for ; Tue, 21 Oct 2014 20:22:06 +0000 (UTC) Received: (qmail 29128 invoked by uid 500); 21 Oct 2014 20:22:06 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 28942 invoked by uid 500); 21 Oct 2014 20:22:06 -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 28535 invoked by uid 99); 21 Oct 2014 20:22:06 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Oct 2014 20:22:06 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DF43493BBFB; Tue, 21 Oct 2014 20:22:05 +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: Tue, 21 Oct 2014 20:22:07 -0000 Message-Id: <907898788a44485bb980b3c17f2e82d0@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/5] 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/6d4746a7 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6d4746a7 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6d4746a7 Branch: refs/heads/2.7.x-fixes Commit: 6d4746a7be50765d5b1326fde52833e2b81c34b3 Parents: cf14336 Author: Daniel Kulp Authored: Mon Oct 20 13:21:25 2014 -0400 Committer: Daniel Kulp Committed: Tue Oct 21 16:21:43 2014 -0400 ---------------------------------------------------------------------- .../cxf/transport/udp/UDPDestination.java | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/6d4746a7/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();