You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/04/29 17:10:34 UTC

svn commit: r1477133 - in /cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery: WSDVersion.java WSDiscoveryClient.java

Author: dkulp
Date: Mon Apr 29 15:10:32 2013
New Revision: 1477133

URL: http://svn.apache.org/r1477133
Log:
Merged revisions 1477117 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1477117 | dkulp | 2013-04-29 10:56:03 -0400 (Mon, 29 Apr 2013) | 2 lines

  Update to use soap 1.2 by default, but add setting to drop to 1.1

........

Modified:
    cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
    cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java

Modified: cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java?rev=1477133&r1=1477132&r2=1477133&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java (original)
+++ cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java Mon Apr 29 15:10:32 2013
@@ -23,7 +23,6 @@ import java.util.Map;
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.Dispatch;
-import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.cxf.feature.StaxTransformFeature;
 import org.apache.cxf.jaxws.DispatchImpl;
@@ -44,7 +43,6 @@ public abstract class WSDVersion {
     abstract String getToAddress();
     abstract void addVersionTransformer(Dispatch<Object> dispatch);
     abstract QName getServiceName();
-    abstract String getSoapVersion();
     
     public String getHelloAction() {
         return getNamespace() + "/Hello";
@@ -102,9 +100,6 @@ public abstract class WSDVersion {
         public QName getServiceName() {
             return new QName(NS_1_0, "DiscoveryProxy");
         }
-        public String getSoapVersion() {
-            return SOAPBinding.SOAP11HTTP_BINDING;
-        }
     }
     static final class WSDVersion11 extends WSDVersion {
         private WSDVersion11() {
@@ -131,9 +126,6 @@ public abstract class WSDVersion {
         public QName getServiceName() {
             return new QName(NS_1_1, "DiscoveryProxy");
         }
-        public String getSoapVersion() {
-            return SOAPBinding.SOAP12HTTP_BINDING;
-        }
     }
     
 }
\ No newline at end of file

Modified: cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java?rev=1477133&r1=1477132&r2=1477133&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java (original)
+++ cxf/branches/2.7.x-fixes/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java Mon Apr 29 15:10:32 2013
@@ -41,6 +41,7 @@ import javax.xml.ws.Holder;
 import javax.xml.ws.Response;
 import javax.xml.ws.Service;
 import javax.xml.ws.soap.AddressingFeature;
+import javax.xml.ws.soap.SOAPBinding;
 import javax.xml.ws.wsaddressing.W3CEndpointReference;
 import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
 
@@ -91,6 +92,7 @@ public class WSDiscoveryClient implement
     final Bus bus;
     int defaultProbeTimeout = 1000;
     WSDVersion version = WSDVersion.INSTANCE_1_1;
+    String soapVersion = SOAPBinding.SOAP12HTTP_BINDING;
 
     public WSDiscoveryClient() {
         this((Bus)null);
@@ -119,14 +121,56 @@ public class WSDiscoveryClient implement
     }
     public void setAddress(String a) {
         if (!address.equals(a)) {
+            uncache();
             resetDispatch(a);
         }
     }
     
+    
+    /**
+     * By default, CXF's WS-Discovery implementation is based on WS-Discovery 1.1.  Some devices will
+     * not respond to 1.1 probes.  This allows CXF to use the WS-Discovery 1.0 namespaces and actions
+     * which will allow older devices to be discovered.   
+     */
     public void setVersion10() {
-        version =  WSDVersion.INSTANCE_1_0;
-        service = null;
+        setVersion(true);
+    }
+    
+    public void setVersion(boolean version10) {
+        WSDVersion newv =  version10 ? WSDVersion.INSTANCE_1_0 : WSDVersion.INSTANCE_1_1;
+        if (newv != version) {
+            version = newv;
+            uncache();
+        }
+    }
+
+    
+    /**
+     * WS-Discovery will use SOAP 1.2 by default.  This allows forcing the use of SOAP 1.1. 
+     * @param do11
+     */
+    public void setSoapVersion11() {
+        setSoapVersion(true);
+    }
+    
+    
+    public void setSoapVersion(boolean do11) {
+        String newVer = do11 ? SOAPBinding.SOAP11HTTP_BINDING : SOAPBinding.SOAP12HTTP_BINDING;
+        if (!soapVersion.equals(newVer)) {
+            soapVersion = newVer;
+            uncache();
+        }
+    }
+    private void uncache() {
+        if (dispatch instanceof Closeable) {
+            try {
+                ((Closeable)dispatch).close();
+            } catch (IOException e) {
+                //ignorable
+            }
+        }
         dispatch = null;
+        service = null;
     }
     
     private synchronized JAXBContext getJAXBContext() {
@@ -147,7 +191,7 @@ public class WSDiscoveryClient implement
                                           version.getServiceName(),
                                           Service.class);
                 service.addPort(version.getServiceName(), 
-                                version.getSoapVersion(), address);
+                                soapVersion, address);
             } finally {
                 BusFactory.setThreadDefaultBus(b);
             }
@@ -156,8 +200,8 @@ public class WSDiscoveryClient implement
     }
     private synchronized void resetDispatch(String newad) {
         address = newad;
-        service = null;
         dispatch = null;
+        service = null;
         adHoc = false;
         try {
             URI uri = new URI(address);
@@ -224,6 +268,7 @@ public class WSDiscoveryClient implement
             ((Closeable)dispatch).close();
             dispatch = null;
         }
+        service = null;
     }
     protected void finalize() throws Throwable {
         super.finalize();
@@ -320,6 +365,7 @@ public class WSDiscoveryClient implement
                             if (h.getTypes().contains(sn)
                                 || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
                                 // A DiscoveryProxy wants us to flip to managed mode
+                                uncache();
                                 resetDispatch(h.getXAddrs().get(0));
                             }
                         }
@@ -365,6 +411,7 @@ public class WSDiscoveryClient implement
                             if (h.getTypes().contains(sn)
                                 || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
                                 // A DiscoveryProxy wants us to flip to managed mode
+                                uncache();
                                 resetDispatch(h.getXAddrs().get(0));
                             }
                         }