@Override
public Endpoint findEndpoint(DomainRegistry domainRegistry, String serviceName) throws NoSuchServiceException {
List<Endpoint> eps = domainRegistry.findEndpoint(serviceName);
if (eps == null || eps.size() < 1) {
throw new NoSuchServiceException(serviceName);
}
// remove any callback services from the array as we aren't
// expecting SCA clients to connect to callback service
Iterator<Endpoint> iterator = eps.iterator();
while (iterator.hasNext()){
Endpoint ep = iterator.next();
if (ep.getService().isForCallback()){
iterator.remove();
}
}
// If lookup is by component name only and there are multiple matches, verify all matches
// are from the same service. Otherwise it is ambiguous which service the client wants.
if (serviceName.indexOf('/') == -1 && eps.size() > 1) {
ComponentService firstService = eps.get(0).getService();
for (int i=1; i<eps.size(); i++) {
if (firstService != eps.get(i).getService())
throw new ServiceRuntimeException("More than one service is declared on component " + serviceName
+ ". Service name is required to get the service.");
}
}
// If there is an Endpoint using the SCA binding use that
for (Endpoint ep : eps) {
if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
return ep;
}
}
if (onlySCABinding) {
throw new NoSuchServiceException(serviceName + " not found using binding.sca");
}
// There either is a single matching endpoint, or there are multiple endpoints (bindings)
// under a single service. Just choose the first one
return eps.get(0);