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();
}
}
}
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();
}
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);
}
}
Aggregations