cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1466120 - in /cxf/trunk/services/ws-discovery/ws-discovery-api/src: main/java/org/apache/cxf/ws/discovery/ main/java/org/apache/cxf/ws/discovery/internal/ test/java/org/apache/cxf/ws/discovery/
Date Tue, 09 Apr 2013 16:53:02 GMT
Author: dkulp
Date: Tue Apr  9 16:53:02 2013
New Revision: 1466120

URL: http://svn.apache.org/r1466120
Log:
Implement the resolve operations.

Modified:
    cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.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/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
    cxf/trunk/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java

Modified: cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java?rev=1466120&r1=1466119&r2=1466120&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDVersion.java
Tue Apr  9 16:53:02 2013
@@ -38,9 +38,10 @@ public abstract class WSDVersion {
     public static final WSDVersion INSTANCE_1_0 = new WSDVersion10();
     public static final WSDVersion INSTANCE_1_1 = new WSDVersion11();
     
-    abstract String getNamespace();
+    public abstract String getNamespace();
+    public abstract String getAddressingNamespace();
+
     abstract String getToAddress();
-    abstract String getAddressingNamespace();
     abstract void addVersionTransformer(Dispatch<Object> dispatch);
     abstract QName getServiceName();
     abstract String getSoapVersion();
@@ -54,6 +55,9 @@ public abstract class WSDVersion {
     public String getProbeAction() {
         return getNamespace() + "/Probe";
     }
+    public String getResolveAction() {
+        return getNamespace() + "/Resolve";
+    }
     
     static final class WSDVersion10 extends WSDVersion {
 

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=1466120&r1=1466119&r2=1466120&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
Tue Apr  9 16:53:02 2013
@@ -37,6 +37,7 @@ import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.EndpointReference;
+import javax.xml.ws.Holder;
 import javax.xml.ws.Response;
 import javax.xml.ws.Service;
 import javax.xml.ws.soap.AddressingFeature;
@@ -64,6 +65,9 @@ import org.apache.cxf.ws.discovery.wsdl.
 import org.apache.cxf.ws.discovery.wsdl.ProbeMatchType;
 import org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType;
 import org.apache.cxf.ws.discovery.wsdl.ProbeType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveMatchType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveMatchesType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveType;
 import org.apache.cxf.ws.discovery.wsdl.ScopesType;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
 
@@ -336,6 +340,51 @@ public class WSDiscoveryClient implement
         return (ProbeMatchesType)o;
     }
     
+    public ResolveMatchType resolve(W3CEndpointReference ref) {
+        return resolve(ref, defaultProbeTimeout);
+    }
+    public ResolveMatchType resolve(W3CEndpointReference ref, int timeout) {
+        Dispatch<Object> disp = this.getDispatchInternal(false, version.getResolveAction());
+        ResolveType rt = new ResolveType();
+        rt.setEndpointReference(ref);
+        if (adHoc) {
+            disp.getRequestContext().put("udp.multi.response.timeout", timeout);
+            final Holder<ResolveMatchesType> response = new Holder<ResolveMatchesType>();
+            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 ResolveMatchesType) {
+                            response.value = (ResolveMatchesType)o;
+                        } else if (o instanceof HelloType) {
+                            HelloType h = (HelloType)o;
+                            QName sn = version.getServiceName();
+                            if (h.getTypes().contains(sn)
+                                || h.getTypes().contains(new QName("", sn.getLocalPart())))
{
+                                // A DiscoveryProxy wants us to flip to managed mode
+                                resetDispatch(h.getXAddrs().get(0));
+                            }
+                        }
+                    } catch (InterruptedException e) {
+                        // ?
+                    } catch (ExecutionException e) {
+                        // ?
+                    }
+                }
+            };
+            disp.invokeAsync(new ObjectFactory().createResolve(rt), handler);
+            return response.value == null ? null : response.value.getResolveMatch();
+        }
+        Object o = disp.invoke(new ObjectFactory().createResolve(rt));
+        while (o instanceof JAXBElement) {
+            o = ((JAXBElement)o).getValue();
+        }
+        return o == null ? null : ((ResolveMatchesType)o).getResolveMatch();
+    }
+    
     
     private W3CEndpointReference generateW3CEndpointReference() {
         W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();

Modified: cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java?rev=1466120&r1=1466119&r2=1466120&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
Tue Apr  9 16:53:02 2013
@@ -46,6 +46,7 @@ import javax.xml.ws.EndpointReference;
 import javax.xml.ws.Provider;
 import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.soap.Addressing;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
 import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
 
 import org.w3c.dom.Document;
@@ -55,6 +56,7 @@ import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.jaxb.JAXBContextCache;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxws.spi.ProviderImpl;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.service.model.ServiceModelUtil;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -62,6 +64,7 @@ import org.apache.cxf.staxutils.transfor
 import org.apache.cxf.ws.addressing.AddressingProperties;
 import org.apache.cxf.ws.addressing.AttributedURIType;
 import org.apache.cxf.ws.addressing.ContextUtils;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.ws.addressing.impl.AddressingPropertiesImpl;
 import org.apache.cxf.ws.discovery.WSDVersion;
 import org.apache.cxf.ws.discovery.WSDiscoveryClient;
@@ -72,7 +75,11 @@ import org.apache.cxf.ws.discovery.wsdl.
 import org.apache.cxf.ws.discovery.wsdl.ProbeMatchType;
 import org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType;
 import org.apache.cxf.ws.discovery.wsdl.ProbeType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveMatchType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveMatchesType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveType;
 import org.apache.cxf.ws.discovery.wsdl.ScopesType;
+import org.apache.cxf.wsdl.EndpointReferenceUtils;
 
 public class WSDiscoveryServiceImpl implements WSDiscoveryService {
     Bus bus;
@@ -404,8 +411,51 @@ public class WSDiscoveryServiceImpl impl
             }
         }
         
+        private Source mapToOld(Document doc, JAXBElement<?> mt) throws JAXBException,
XMLStreamException {
+            doc.removeChild(doc.getDocumentElement());
+            DOMResult result = new DOMResult(doc);
+            XMLStreamWriter r = StaxUtils.createXMLStreamWriter(result);
+            context.createMarshaller().marshal(mt, r);
+            
+            XMLStreamReader domReader = StaxUtils.createXMLStreamReader(doc);
+            Map<String, String> inMap = new HashMap<String, String>();
+            inMap.put("{" + WSDVersion.INSTANCE_1_1.getNamespace() + "}*",
+                      "{" + WSDVersion.INSTANCE_1_0.getNamespace() + "}*");
+            inMap.put("{" + WSDVersion.INSTANCE_1_1.getAddressingNamespace() + "}*",
+                      "{" + WSDVersion.INSTANCE_1_0.getAddressingNamespace() + "}*");
+            
+            InTransformReader reader = new InTransformReader(domReader, inMap , null, false);
+            doc = StaxUtils.read(reader);
+            return new DOMSource(doc);            
+        }
+        private void updateOutputAction(String append) {
+            AddressingProperties p = ContextUtils.retrieveMAPs(PhaseInterceptorChain.getCurrentMessage(),
+                                                               false, false);
+            AddressingProperties pout = new AddressingPropertiesImpl();
+            AttributedURIType action = new AttributedURIType();
+            action.setValue(p.getAction().getValue() + append);
+            pout.exposeAs(p.getNamespaceURI());
+            pout.setAction(action);
+            ContextUtils.storeMAPs(pout, PhaseInterceptorChain.getCurrentMessage(), true);
+
+        }
+        
+        private Document mapFromOld(Document doc) throws XMLStreamException {
+            XMLStreamReader domReader = StaxUtils.createXMLStreamReader(doc);
+            Map<String, String> inMap = new HashMap<String, String>();
+            inMap.put("{" + WSDVersion.INSTANCE_1_0.getNamespace() + "}*",
+                      "{" + WSDVersion.INSTANCE_1_1.getNamespace() + "}*");
+            inMap.put("{" + WSDVersion.INSTANCE_1_0.getAddressingNamespace() + "}*",
+                      "{" + WSDVersion.INSTANCE_1_1.getAddressingNamespace() + "}*");
+            InTransformReader reader = new InTransformReader(domReader, inMap , null, false);
+            doc = StaxUtils.read(reader);
+            //System.out.println(StaxUtils.toString(doc));
+           
+            return doc;
+        }
 
         public Source invoke(Source request) {
+            Source ret = null;
             try {
                 //Bug in JAXB - if you pass the StaxSource or SaxSource into unmarshall,
                 //the namespaces for the QNames for the Types elements are lost.
@@ -416,17 +466,10 @@ public class WSDiscoveryServiceImpl impl
                 if ("http://schemas.xmlsoap.org/ws/2005/04/discovery"
                     .equals(doc.getDocumentElement().getNamespaceURI())) {
                     //old version of ws-discovery, we'll transform this to newer version
-                    
-                    XMLStreamReader domReader = StaxUtils.createXMLStreamReader(doc);
-                    Map<String, String> inMap = new HashMap<String, String>();
-                    inMap.put("{http://schemas.xmlsoap.org/ws/2005/04/discovery}*",
-                              "{http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}*");
-                    InTransformReader reader = new InTransformReader(domReader, inMap , null,
false);
-                    doc = StaxUtils.read(reader);
+                    doc = mapFromOld(doc);
                     mapToOld = true;
                 }
                 
-                
                 if (!"http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01"
                     .equals(doc.getDocumentElement().getNamespaceURI())) {
                     //not a proper ws-discovery message, ignore it
@@ -442,33 +485,23 @@ public class WSDiscoveryServiceImpl impl
                     if (pmt == null) {
                         return null;
                     }
-                    AddressingProperties p = ContextUtils.retrieveMAPs(PhaseInterceptorChain.getCurrentMessage(),
-                                                                       false, false);
-                    AddressingProperties pout = new AddressingPropertiesImpl();
-                    AttributedURIType action = new AttributedURIType();
-                    action.setValue(p.getAction().getValue() + "Matches");
-                    pout.exposeAs(p.getNamespaceURI());
-                    pout.setAction(action);
-                    ContextUtils.storeMAPs(pout, PhaseInterceptorChain.getCurrentMessage(),
true);
-                    
+                    updateOutputAction("Matches");
+                    if (mapToOld) {
+                        ret = mapToOld(doc, factory.createProbeMatches(pmt));
+                    } else {
+                        ret = new JAXBSource(context, factory.createProbeMatches(pmt));
+                    }
+                } else if (obj instanceof ResolveType) {
+                    ResolveMatchesType rmt = handleResolve((ResolveType)obj);
+                    if (rmt == null) {
+                        return null;
+                    }
+                    updateOutputAction("Matches");
                     if (mapToOld) {
-                        doc.removeChild(doc.getDocumentElement());
-                        DOMResult result = new DOMResult(doc);
-                        XMLStreamWriter r = StaxUtils.createXMLStreamWriter(result);
-                        context.createMarshaller().marshal(factory.createProbeMatches(pmt),
r);
-                        
-                        XMLStreamReader domReader = StaxUtils.createXMLStreamReader(doc);
-                        Map<String, String> inMap = new HashMap<String, String>();
-                        inMap.put("{http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}*",
-                                  "{http://schemas.xmlsoap.org/ws/2005/04/discovery}*");
-                        
-                        
-                        
-                        InTransformReader reader = new InTransformReader(domReader, inMap
, null, false);
-                        doc = StaxUtils.read(reader);
-                        return new DOMSource(doc);
+                        ret = mapToOld(doc, factory.createResolveMatches(rmt));
+                    } else {
+                        ret = new JAXBSource(context, factory.createResolveMatches(rmt));
                     }
-                    return new JAXBSource(context, factory.createProbeMatches(pmt));
                 } else if (obj instanceof HelloType) {
                     //check if it's a DiscoveryProxy
                     HelloType h = (HelloType)obj;
@@ -504,8 +537,48 @@ public class WSDiscoveryServiceImpl impl
                 // TODO Auto-generated catch block
                 e1.printStackTrace();
             }
+            return ret;
+        }
+
+        private ResolveMatchesType handleResolve(ResolveType resolve) {
+            ResolveMatchType rmt = new ResolveMatchType();
+            EndpointReference ref = resolve.getEndpointReference();
+            EndpointReferenceType iref = ProviderImpl.convertToInternal(ref);
+            for (HelloType hello : registered) {
+                W3CEndpointReference r = hello.getEndpointReference();
+                if (matches(iref, r)) {
+                    rmt.setEndpointReference(r);
+                    rmt.setScopes(hello.getScopes());
+                    rmt.getTypes().addAll(hello.getTypes());
+                    rmt.getXAddrs().addAll(hello.getXAddrs());
+                    rmt.getOtherAttributes().putAll(hello.getOtherAttributes());
+                    rmt.setMetadataVersion(hello.getMetadataVersion());
+                    ResolveMatchesType rmts = new ResolveMatchesType();
+                    rmts.setResolveMatch(rmt);
+                    return rmts;
+                }
+            }
             return null;
         }
+
+        private boolean matches(EndpointReferenceType ref, W3CEndpointReference r) {
+            EndpointReferenceType cref = ProviderImpl.convertToInternal(r);
+            QName snr = EndpointReferenceUtils.getServiceName(ref, bus);
+            QName snc = EndpointReferenceUtils.getServiceName(cref, bus);
+            String addr = EndpointReferenceUtils.getAddress(ref);
+            String addc = EndpointReferenceUtils.getAddress(ref);
+            
+            if (addr == null) {
+                return false;
+            }
+            if (addr.equals(addc)) {
+                if (snr != null && !snr.equals(snc)) {
+                    return false;
+                }
+                return true;
+            }
+            return false;
+        }
     }
 
 }

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=1466120&r1=1466119&r2=1466120&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
Tue Apr  9 16:53:02 2013
@@ -22,6 +22,7 @@ package org.apache.cxf.ws.discovery;
 import javax.jws.WebMethod;
 import javax.jws.WebService;
 import javax.xml.ws.Endpoint;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -31,6 +32,7 @@ import org.apache.cxf.ws.discovery.wsdl.
 import org.apache.cxf.ws.discovery.wsdl.ProbeMatchType;
 import org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType;
 import org.apache.cxf.ws.discovery.wsdl.ProbeType;
+import org.apache.cxf.ws.discovery.wsdl.ResolveMatchType;
 import org.apache.cxf.ws.discovery.wsdl.ScopesType;
 
 
@@ -75,14 +77,22 @@ public final class WSDiscoveryClientTest
             }
             pmts = c.probe(pt);
             System.out.println("3");
-            
+
+            W3CEndpointReference ref = null;
             if  (pmts != null) {
                 for (ProbeMatchType pmt : pmts.getProbeMatch()) {
+                    ref = pmt.getEndpointReference();
                     System.out.println("Found " + pmt.getEndpointReference());
                     System.out.println(pmt.getTypes());
                     System.out.println(pmt.getXAddrs());
                 }
             }
+            
+            ResolveMatchType rmt = c.resolve(ref);
+            System.out.println("Resolved " + rmt.getEndpointReference());
+            System.out.println(rmt.getTypes());
+            System.out.println(rmt.getXAddrs());
+
             service.unregister(h);
             System.out.println("4");
             c.close();



Mime
View raw message