Search in sources :

Example 6 with HelloType

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

the class WSDiscoveryServiceImpl method matchScopes.

private void matchScopes(ProbeType pt, List<HelloType> consider) {
    if (pt.getScopes() == null || pt.getScopes().getValue().isEmpty()) {
        return;
    }
    String mb = pt.getScopes().getMatchBy();
    if (mb == null) {
        mb = "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/rfc3986";
    }
    if (mb.startsWith(WSDVersion.NS_1_0)) {
        mb = mb.substring(WSDVersion.NS_1_0.length());
    } else if (mb.startsWith(WSDVersion.NS_1_1)) {
        mb = mb.substring(WSDVersion.NS_1_1.length());
    }
    ListIterator<HelloType> cit = consider.listIterator();
    while (cit.hasNext()) {
        HelloType ht = cit.next();
        boolean matches = false;
        if ("/rfc3986".equals(mb)) {
            matches = true;
            if (!pt.getScopes().getValue().isEmpty()) {
                for (String ps : pt.getScopes().getValue()) {
                    boolean foundOne = false;
                    URI psuri = URI.create(ps);
                    for (String hts : ht.getScopes().getValue()) {
                        URI hturi = URI.create(hts);
                        if (matchURIs(psuri, hturi)) {
                            foundOne = true;
                        }
                    }
                    matches &= foundOne;
                }
            }
        } else if ("/uuid".equals(mb)) {
            matches = true;
            if (!pt.getScopes().getValue().isEmpty()) {
                for (String ps : pt.getScopes().getValue()) {
                    boolean foundOne = false;
                    UUID psuuid = toUUID(ps);
                    for (String hts : ht.getScopes().getValue()) {
                        UUID htuuid = toUUID(hts);
                        if (!htuuid.equals(psuuid)) {
                            foundOne = true;
                        }
                    }
                    matches &= foundOne;
                }
            }
        } else if ("/ldap".equals(mb)) {
            // LDAP not supported
            if (!pt.getScopes().getValue().isEmpty()) {
                matches = false;
            }
        } else if ("/strcmp0".equals(mb)) {
            matches = true;
            if (!pt.getScopes().getValue().isEmpty()) {
                for (String s : pt.getScopes().getValue()) {
                    if (!ht.getScopes().getValue().contains(s)) {
                        matches = false;
                    }
                }
            }
        } else if ("/none".equals(mb) && (ht.getScopes() == null || ht.getScopes().getValue().isEmpty())) {
            matches = true;
        }
        if (!matches) {
            cit.remove();
        }
    }
}
Also used : HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) UUID(java.util.UUID) URI(java.net.URI)

Example 7 with HelloType

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

the class WSDiscoveryClient method resolve.

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
                            uncache();
                            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();
}
Also used : AsyncHandler(javax.xml.ws.AsyncHandler) ResolveMatchesType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchesType) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ResolveType(org.apache.cxf.ws.discovery.wsdl.ResolveType) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) JAXBElement(javax.xml.bind.JAXBElement) Response(javax.xml.ws.Response) ObjectFactory(org.apache.cxf.ws.discovery.wsdl.ObjectFactory) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with HelloType

use of org.apache.cxf.ws.discovery.wsdl.HelloType 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

HelloType (org.apache.cxf.ws.discovery.wsdl.HelloType)8 QName (javax.xml.namespace.QName)4 ProbeMatchesType (org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType)3 ScopesType (org.apache.cxf.ws.discovery.wsdl.ScopesType)3 LinkedList (java.util.LinkedList)2 ExecutionException (java.util.concurrent.ExecutionException)2 JAXBElement (javax.xml.bind.JAXBElement)2 AsyncHandler (javax.xml.ws.AsyncHandler)2 Response (javax.xml.ws.Response)2 ObjectFactory (org.apache.cxf.ws.discovery.wsdl.ObjectFactory)2 ProbeMatchType (org.apache.cxf.ws.discovery.wsdl.ProbeMatchType)2 URI (java.net.URI)1 List (java.util.List)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Endpoint (javax.xml.ws.Endpoint)1 Holder (javax.xml.ws.Holder)1 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)1 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)1 Bus (org.apache.cxf.Bus)1