/** * Get the address URLs. Guranteed to return at least one address. * @param epr endpoint * @return the address as a URL * @throws InvalidRecordException if the type is wrong, there are no addresses * or the payload ill-formatted * @throws MalformedURLException address can't be turned into a URL */ public static List<URL> retrieveAddressURLs(Endpoint epr) throws InvalidRecordException, MalformedURLException { if (epr == null) { throw new InvalidRecordException("", "Null endpoint"); } List<String> addresses = retrieveAddressesUriType(epr); List<URL> results = new ArrayList<URL>(addresses.size()); for (String address : addresses) { results.add(new URL(address)); } return results; }
/** * Get the address URLs. Guranteed to return at least one address. * @param epr endpoint * @return the address as a URL * @throws InvalidRecordException if the type is wrong, there are no addresses * or the payload ill-formatted * @throws MalformedURLException address can't be turned into a URL */ public static List<URL> retrieveAddressURLs(Endpoint epr) throws InvalidRecordException, MalformedURLException { if (epr == null) { throw new InvalidRecordException("", "Null endpoint"); } List<String> addresses = retrieveAddressesUriType(epr); List<URL> results = new ArrayList<URL>(addresses.size()); for (String address : addresses) { results.add(new URL(address)); } return results; }
/** * Look up an external REST API endpoint * @param record service record * @param api URI of api * @param external flag to indicate this is an external record * @return the first endpoint of the implementation, or null if there * is no entry for the API, implementation or it's the wrong type. */ public static String lookupRestAPI(ServiceRecord record, String api, boolean external) throws InvalidRecordException { try { String url = null; Endpoint endpoint = getEndpoint(record, api, external); List<String> addresses = RegistryTypeUtils.retrieveAddressesUriType(endpoint); if (addresses != null && !addresses.isEmpty()) { url = addresses.get(0); } return url; } catch (InvalidRecordException e) { log.debug("looking for API {}", api, e); return null; } }
/** * Look up an external REST API endpoint * @param record service record * @param api URI of api * @param external flag to indicate this is an external record * @return the first endpoint of the implementation, or null if there * is no entry for the API, implementation or it's the wrong type. */ public static String lookupRestAPI(ServiceRecord record, String api, boolean external) throws InvalidRecordException { try { String url = null; Endpoint endpoint = getEndpoint(record, api, external); List<String> addresses = RegistryTypeUtils.retrieveAddressesUriType(endpoint); if (addresses != null && !addresses.isEmpty()) { url = addresses.get(0); } return url; } catch (InvalidRecordException e) { log.debug("looking for API {}", api, e); return null; } }