@Override
@SuppressWarnings("PMD.PreserveStackTrace")
public URI findServiceUri(final String serviceName,
final String serviceType, final ServiceHint... hints)
throws ServiceNotAvailableException {
final ServiceInformation service = findServiceInformation(serviceName,
serviceType, hints);
final String locatedScheme = service
.getProperty(ServiceInformation.PROP_SERVICE_SCHEME);
final String locatedAddress = service
.getProperty(ServiceInformation.PROP_SERVICE_ADDRESS);
final String locatedPort = service
.getProperty(ServiceInformation.PROP_SERVICE_PORT);
if (StringUtils.isEmpty(locatedScheme)
|| StringUtils.isEmpty(locatedAddress)
|| StringUtils.isEmpty(locatedPort)) {
throw new ServiceNotAvailableException(
"Service %s/%s exists but misses address information (%s/%s)",
serviceName, serviceType, locatedAddress, locatedPort);
}
try {
return new URI(locatedScheme, null, locatedAddress,
Integer.parseInt(locatedPort), "", null, null);
} catch (URISyntaxException use) {
throw new ServiceNotAvailableException(
"Could not create URI from '%s'!", service);
}
}