Search in sources :

Example 1 with HelloType

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

the class WSDiscoveryClient method probe.

public ProbeMatchesType probe(ProbeType params, int timeout) {
    Dispatch<Object> disp = this.getDispatchInternal(false, version.getProbeAction());
    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;
                        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().createProbe(params), handler);
        return response;
    }
    Object o = disp.invoke(new ObjectFactory().createProbe(params));
    while (o instanceof JAXBElement) {
        o = ((JAXBElement) o).getValue();
    }
    return (ProbeMatchesType) o;
}
Also used : Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) ObjectFactory(org.apache.cxf.ws.discovery.wsdl.ObjectFactory) QName(javax.xml.namespace.QName) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) ProbeMatchesType(org.apache.cxf.ws.discovery.wsdl.ProbeMatchesType) JAXBElement(javax.xml.bind.JAXBElement) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with HelloType

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

the class WSDiscoveryClient method register.

/**
 * Sends the "Hello" to broadcast the availability of a service
 * @param ert The endpoint reference of the Service itself
 * @return the Hello that was used to broadcast the availability.
 */
public HelloType register(EndpointReference ert) {
    HelloType hello = new HelloType();
    hello.setScopes(new ScopesType());
    hello.setMetadataVersion(1);
    EndpointReferenceType ref = ProviderImpl.convertToInternal(ert);
    proccessEndpointReference(ref, hello.getScopes(), hello.getTypes(), hello.getXAddrs());
    hello.setEndpointReference(generateW3CEndpointReference());
    return register(hello);
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType)

Example 3 with HelloType

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

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

the class WSDiscoveryServiceImpl method register.

public HelloType register(EndpointReference ref) {
    startup(false);
    HelloType ht = client.register(ref);
    registered.add(ht);
    return ht;
}
Also used : HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType)

Example 5 with HelloType

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

the class WSDiscoveryServiceImpl method serverStarted.

public void serverStarted(Server server) {
    Object o = getProperty(server, "ws-discovery-disable");
    if (o == Boolean.TRUE || Boolean.valueOf((String) o)) {
        return;
    }
    if (!startup(true)) {
        return;
    }
    HelloType ht = new HelloType();
    ht.setScopes(new ScopesType());
    ht.setMetadataVersion(1);
    o = getProperty(server, "ws-discovery-types");
    if (o instanceof QName) {
        ht.getTypes().add((QName) o);
    } else if (o instanceof List) {
        for (Object o2 : (List<?>) o) {
            if (o2 instanceof QName) {
                ht.getTypes().add((QName) o2);
            } else if (o2 instanceof String) {
                ht.getTypes().add(QName.valueOf((String) o2));
            }
        }
    } else if (o instanceof String) {
        ht.getTypes().add(QName.valueOf((String) o));
    }
    if (ht.getTypes().isEmpty()) {
        QName sn = ServiceModelUtil.getServiceQName(server.getEndpoint().getEndpointInfo());
        ht.getTypes().add(sn);
    }
    o = getProperty(server, "ws-discovery-scopes");
    if (o != null) {
        setScopes(ht, o);
    }
    setXAddrs(ht, server);
    String uuid = (String) getProperty(server, "ws-discovery-uuid");
    if (uuid != null) {
        // persistent uuid
        W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
        builder.address(uuid);
        ht.setEndpointReference(builder.build());
    }
    ht = client.register(ht);
    registered.add(ht);
    server.getEndpoint().put(HelloType.class.getName(), ht);
}
Also used : ScopesType(org.apache.cxf.ws.discovery.wsdl.ScopesType) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) QName(javax.xml.namespace.QName) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LinkedList(java.util.LinkedList)

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