Search in sources :

Example 1 with ProbeMatchType

use of org.apache.cxf.ws.discovery.wsdl.ProbeMatchType in project cxf by apache.

the class WSDiscoveryClient method probe.

public List<EndpointReference> probe(QName type) {
    ProbeType p = new ProbeType();
    if (type != null) {
        p.getTypes().add(type);
    }
    ProbeMatchesType pmt = probe(p, defaultProbeTimeout);
    List<EndpointReference> er = new ArrayList<>();
    for (ProbeMatchType pm : pmt.getProbeMatch()) {
        for (String add : pm.getXAddrs()) {
            W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
            builder.address(add);
            // builder.serviceName(type);
            // builder.endpointName(type);
            er.add(builder.build());
        }
    }
    return er;
}
Also used : W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) ProbeType(org.apache.cxf.ws.discovery.wsdl.ProbeType) ArrayList(java.util.ArrayList) ProbeMatchesType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType) EndpointReference(javax.xml.ws.EndpointReference) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ProbeMatchType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchType)

Example 2 with ProbeMatchType

use of org.apache.cxf.ws.discovery.wsdl.ProbeMatchType in project cxf by apache.

the class WSDiscoveryServiceImpl method handleProbe.

public ProbeMatchesType handleProbe(ProbeType pt) {
    List<HelloType> consider = new LinkedList<HelloType>(registered);
    // ALL types in the probe must be in the registered type
    if (pt.getTypes() != null && !pt.getTypes().isEmpty()) {
        ListIterator<HelloType> cit = consider.listIterator();
        while (cit.hasNext()) {
            HelloType ht = cit.next();
            boolean matches = true;
            for (QName qn : pt.getTypes()) {
                if (!ht.getTypes().contains(qn)) {
                    matches = false;
                }
            }
            if (!matches) {
                cit.remove();
            }
        }
    }
    // next, consider the scopes
    matchScopes(pt, consider);
    if (consider.isEmpty()) {
        return null;
    }
    ProbeMatchesType pmt = new ProbeMatchesType();
    for (HelloType ht : consider) {
        ProbeMatchType m = new ProbeMatchType();
        m.setEndpointReference(ht.getEndpointReference());
        m.setScopes(ht.getScopes());
        m.setMetadataVersion(ht.getMetadataVersion());
        m.getTypes().addAll(ht.getTypes());
        m.getXAddrs().addAll(ht.getXAddrs());
        pmt.getProbeMatch().add(m);
    }
    return pmt;
}
Also used : QName(javax.xml.namespace.QName) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) ProbeMatchesType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType) LinkedList(java.util.LinkedList) ProbeMatchType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchType)

Example 3 with ProbeMatchType

use of org.apache.cxf.ws.discovery.wsdl.ProbeMatchType in project cxf by apache.

the class WSDiscoveryClientTest method main.

// this is a standalone test
public static void main(String[] arg) throws Exception {
    try {
        Bus bus = BusFactory.getDefaultBus();
        Endpoint ep = Endpoint.publish("http://localhost:51919/Foo/Snarf", new FooImpl());
        WSDiscoveryServiceImpl service = new WSDiscoveryServiceImpl(bus);
        service.startup();
        // this service will just generate an error.  However, the probes should still
        // work to probe the above stuff.
        WSDiscoveryServiceImpl s2 = new WSDiscoveryServiceImpl() {

            public ProbeMatchesType handleProbe(ProbeType pt) {
                throw new RuntimeException("Error!!!");
            }
        };
        s2.startup();
        HelloType h = service.register(ep.getEndpointReference());
        bus = BusFactory.newInstance().createBus();
        WSDiscoveryClient c = new WSDiscoveryClient(bus);
        c.setVersion10();
        System.out.println("1");
        ProbeType pt = new ProbeType();
        ScopesType scopes = new ScopesType();
        pt.setScopes(scopes);
        ProbeMatchesType pmts = c.probe(pt, 1000);
        System.out.println("2");
        if (pmts != null) {
            for (ProbeMatchType pmt : pmts.getProbeMatch()) {
                System.out.println("Found " + pmt.getEndpointReference());
                System.out.println(pmt.getTypes());
                System.out.println(pmt.getXAddrs());
            }
        }
        if (pmts.getProbeMatch().isEmpty()) {
            System.exit(0);
        }
        pmts = c.probe(pt);
        System.out.println("Size:" + pmts.getProbeMatch().size());
        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();
        System.exit(0);
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) Bus(org.apache.cxf.Bus) ProbeType(org.apache.cxf.ws.discovery.wsdl.ProbeType) WSDiscoveryServiceImpl(org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) ProbeMatchType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchType) ResolveMatchType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchType) Endpoint(javax.xml.ws.Endpoint) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ProbeMatchesType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType)

Aggregations

ProbeMatchType (org.apache.cxf.ws.discovery.wsdl.ProbeMatchType)3 ProbeMatchesType (org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType)3 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)2 HelloType (org.apache.cxf.ws.discovery.wsdl.HelloType)2 ProbeType (org.apache.cxf.ws.discovery.wsdl.ProbeType)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1 Endpoint (javax.xml.ws.Endpoint)1 EndpointReference (javax.xml.ws.EndpointReference)1 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)1 Bus (org.apache.cxf.Bus)1 WSDiscoveryServiceImpl (org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl)1 ResolveMatchType (org.apache.cxf.ws.discovery.wsdl.ResolveMatchType)1 ScopesType (org.apache.cxf.ws.discovery.wsdl.ScopesType)1