Search in sources :

Example 1 with ResolveType

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

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 AsyncHandler (javax.xml.ws.AsyncHandler)1 Holder (javax.xml.ws.Holder)1 Response (javax.xml.ws.Response)1 HelloType (org.apache.cxf.ws.discovery.wsdl.HelloType)1 ObjectFactory (org.apache.cxf.ws.discovery.wsdl.ObjectFactory)1 ResolveMatchesType (org.apache.cxf.ws.discovery.wsdl.ResolveMatchesType)1 ResolveType (org.apache.cxf.ws.discovery.wsdl.ResolveType)1