You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2015/11/05 09:52:28 UTC

cxf git commit: [CXF-6172]:WS-Discovery should work also in IPv6 only environment

Repository: cxf
Updated Branches:
  refs/heads/master 807be1795 -> 66a50dd4b


[CXF-6172]:WS-Discovery should work also in IPv6 only environment


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

Branch: refs/heads/master
Commit: 66a50dd4b5a8cd4554a50c8cd8d9bcd32dd2a4a2
Parents: 807be17
Author: Jim Ma <em...@apache.org>
Authored: Thu Nov 5 16:51:31 2015 +0800
Committer: Jim Ma <em...@apache.org>
Committed: Thu Nov 5 16:52:05 2015 +0800

----------------------------------------------------------------------
 .../apache/cxf/ws/discovery/WSDiscoveryClient.java | 14 +++++++++++---
 .../discovery/internal/WSDiscoveryServiceImpl.java | 17 ++++++++++++++---
 2 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/66a50dd4/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
----------------------------------------------------------------------
diff --git a/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java b/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
index e5734ca..ab6c740 100644
--- a/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
+++ b/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
@@ -77,10 +77,8 @@ import org.apache.cxf.ws.discovery.wsdl.ScopesType;
 public class WSDiscoveryClient implements Closeable {
     
     public static final QName SERVICE_QNAME = new QName(WSDVersion.NS_1_1, "DiscoveryProxy");
-    
-    
-    
     String address = "soap.udp://239.255.255.250:3702";
+    String ipv6Address = "soap.udp://[FF02::C]:3702";
     boolean adHoc = true;
     AtomicInteger msgId = new AtomicInteger(1);
     long instanceId = System.currentTimeMillis();
@@ -95,9 +93,11 @@ public class WSDiscoveryClient implements Closeable {
 
     public WSDiscoveryClient() {
         this((Bus)null);
+        setIpV6Address();
     }
     public WSDiscoveryClient(Bus b) {
         this.bus = b == null ? BusFactory.getThreadDefaultBus() : b;
+        setIpV6Address();
     }
     public WSDiscoveryClient(String address) {
         this((Bus)null);
@@ -160,6 +160,14 @@ public class WSDiscoveryClient implements Closeable {
             uncache();
         }
     }
+
+    private void setIpV6Address() {
+        String preferIPv4StackValue = System.getProperty("java.net.preferIPv4Stack");
+        String preferIPv6AddressesValue = System.getProperty("java.net.preferIPv6Addresses");
+        if ("true".equals(preferIPv6AddressesValue) && "false".equals(preferIPv4StackValue)) {
+            address = "soap.udp://[FF02::C]:3702";
+        }
+    }
     private void uncache() {
         if (dispatch instanceof Closeable) {
             try {

http://git-wip-us.apache.org/repos/asf/cxf/blob/66a50dd4/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java b/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
index 9582a62..f4348a4 100644
--- a/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
+++ b/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
@@ -238,15 +238,26 @@ public class WSDiscoveryServiceImpl implements WSDiscoveryService {
         startup(false);
     }    
     public synchronized boolean startup(boolean optional) {
+        String preferIPv4StackValue = System.getProperty("java.net.preferIPv4Stack");
+        String preferIPv6AddressesValue = System.getProperty("java.net.preferIPv6Addresses");
         if (!started && client.isAdHoc()) {
             Bus b = BusFactory.getAndSetThreadDefaultBus(bus);
             try {
                 udpEndpoint = new EndpointImpl(bus, new WSDiscoveryProvider());
                 Map<String, Object> props = new HashMap<String, Object>();
                 props.put("jaxws.provider.interpretNullAsOneway", "true");
-                udpEndpoint.setProperties(props);
-                udpEndpoint.publish("soap.udp://239.255.255.250:3702");
-                started = true;
+                if ("true".equals(preferIPv6AddressesValue) && "false".equals(preferIPv4StackValue)) {
+                    try {
+                        udpEndpoint.publish("soap.udp://[FF02::C]:3702");
+                        started = true;
+                    } catch (Exception e) {
+                        LOG.log(Level.WARNING, "Could not start WS-Discovery Service with ipv6 address", e);
+                    }
+                }
+                if (!started) {
+                    udpEndpoint.publish("soap.udp://239.255.255.250:3702");
+                    started = true;
+                }
             } catch (RuntimeException ex) {
                 if (!optional) {
                     throw ex;