cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1374411 - in /cxf/trunk: rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/ services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/ services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws...
Date Fri, 17 Aug 2012 19:53:54 GMT
Author: dkulp
Date: Fri Aug 17 19:53:53 2012
New Revision: 1374411

URL: http://svn.apache.org/viewvc?rev=1374411&view=rev
Log:
Flip from adHoc mode to managed mode if a DiscoveryProxy sends a Hello

Modified:
    cxf/trunk/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
    cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
    cxf/trunk/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java

Modified: cxf/trunk/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java?rev=1374411&r1=1374410&r2=1374411&view=diff
==============================================================================
--- cxf/trunk/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
(original)
+++ cxf/trunk/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
Fri Aug 17 19:53:53 2012
@@ -271,7 +271,7 @@ public class UDPConduit extends Abstract
                 byte bytes[] = new byte[64 * 1024];
                 DatagramPacket p = new DatagramPacket(bytes, bytes.length);
                 Integer i = (Integer)message.getContextualProperty(MULTI_RESPONSE_TIMEOUT);
-                if (i == null) {
+                if (i == null || message.getExchange().isSynchronous()) {
                     socket.setSoTimeout(30000);
                     socket.receive(p);
                     dataReceived(message, IoBuffer.wrap(bytes, 0, p.getLength()), false);

Modified: cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java?rev=1374411&r1=1374410&r2=1374411&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
Fri Aug 17 19:53:53 2012
@@ -105,6 +105,12 @@ public class WSDiscoveryClient implement
         }
         return service;
     }
+    private synchronized void resetDispatch(String newad) {
+        address = newad;
+        service = null;
+        dispatch = null;
+        adHoc = false;
+    }
     
     private synchronized Dispatch<Object> getDispatchInternal(boolean addSeq) {
         if (dispatch == null) {
@@ -208,32 +214,46 @@ public class WSDiscoveryClient implement
     }    
     public ProbeMatchesType probe(ProbeType params, int timeout) {
         Dispatch<Object> disp = this.getDispatchInternal(false);
-        disp.getRequestContext().put("udp.multi.response.timeout", timeout);
-        final ProbeMatchesType response = new ProbeMatchesType();
-        AsyncHandler<Object> handler = new AsyncHandler<Object>() {
-            public void handleResponse(Response<Object> res) {
-                try {
-                    Object o = res.get();
-                    while (o instanceof JAXBElement) {
-                        o = ((JAXBElement)o).getValue();
-                    }
-                    if (o instanceof ProbeMatchesType) {
-                        response.getProbeMatch().addAll(((ProbeMatchesType)o).getProbeMatch());
-                    } else if (o instanceof HelloType) {
-                        //DiscoveryProxy wants us to switch to managed
-                        //FIXME
+        if (adHoc) {
+            disp.getRequestContext().put("udp.multi.response.timeout", timeout);
+            final ProbeMatchesType response = new ProbeMatchesType();
+            AsyncHandler<Object> handler = new AsyncHandler<Object>() {
+                public void handleResponse(Response<Object> res) {
+                    try {
+                        Object o = res.get();
+                        while (o instanceof JAXBElement) {
+                            o = ((JAXBElement)o).getValue();
+                        }
+                        if (o instanceof ProbeMatchesType) {
+                            response.getProbeMatch().addAll(((ProbeMatchesType)o).getProbeMatch());
+                        } else if (o instanceof HelloType) {
+                            HelloType h = (HelloType)o;
+                            if (h.getTypes().contains(SERVICE_QNAME)
+                                || h.getTypes().contains(new QName("", SERVICE_QNAME.getLocalPart())))
{
+                                // A DiscoveryProxy wants us to flip to managed mode
+                                resetDispatch(h.getXAddrs().get(0));
+                            } else {
+                                System.out.println(h.getTypes());
+                            }
+                            
+                        }
+                    } catch (InterruptedException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    } catch (ExecutionException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
                     }
-                } catch (InterruptedException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                } catch (ExecutionException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
                 }
-            }
-        };
-        disp.invokeAsync(new ObjectFactory().createProbe(params), handler);
-        return response;
+            };
+            disp.invokeAsync(new ObjectFactory().createProbe(params), handler);
+            return response;
+        }
+        Object o = disp.invoke(new ObjectFactory().createProbe(params));
+        while (o instanceof JAXBElement) {
+            o = ((JAXBElement)o).getValue();
+        }
+        return (ProbeMatchesType)o;
     }
     
     

Modified: cxf/trunk/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java?rev=1374411&r1=1374410&r2=1374411&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
Fri Aug 17 19:53:53 2012
@@ -56,9 +56,18 @@ public final class WSDiscoveryClientTest
                     System.out.println(pmt.getXAddrs());
                 }
             }
+            pmts = c.probe(new ProbeType());
+            System.out.println("3");
+            if  (pmts != null) {
+                for (ProbeMatchType pmt : pmts.getProbeMatch()) {
+                    System.out.println("Found " + pmt.getEndpointReference());
+                    System.out.println(pmt.getTypes());
+                    System.out.println(pmt.getXAddrs());
+                }
+            }
             
             c.unregister(h);
-            System.out.println("2");
+            System.out.println("4");
             c.close();
             
             System.exit(0);



Mime
View raw message