/** * Constructs URL to reach RouteConfig REST API endpoints of a service. * * @param serviceId {@link ServiceId} of the service with the application version part ignored */ private URL buildRouteConfigUrl(ServiceId serviceId) throws MalformedURLException { String path = String.format("apps/%s/services/%s/routeconfig", serviceId.getApplication(), serviceId.getEntityName()); return config.resolveNamespacedURLV3(serviceId.getNamespaceId(), path); } }
/** * Gets a {@link URL} to call methods for the endpoint of a {@link Service} with no application version. If multiple * versions exist, traffic to the {@link URL} will be distributed to each version according to routing strategy. If * only one version exists, this version will always be reached with the {@link URL}. * * @param service {@link ServiceId} of the service * @return a URL to call methods of the service * @throws NotFoundException @throws NotFoundException if the app or service could not be found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public URL getServiceURL(ServiceId service) throws NotFoundException, IOException, UnauthenticatedException, UnauthorizedException { return config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/methods/", service.getApplication(), service.getEntityName())); }
/** * Calls the non-versioned service endpoint for a given method and get routed to a specific version by the Router * * @param serviceId {@link ServiceId} of the service with the application version part ignored * @param methodPath the path specifying only the method * @return {@link HttpResponse} from the service method */ public HttpResponse callServiceMethod(ServiceId serviceId, String methodPath) throws IOException, UnauthorizedException, UnauthenticatedException { String path = String.format("apps/%s/services/%s/methods/%s", serviceId.getApplication(), serviceId.getEntityName(), methodPath); URL url = config.resolveNamespacedURLV3(serviceId.getNamespaceId(), path); return restClient.execute(HttpMethod.GET, url, config.getAccessToken()); }
/** * Gets a {@link URL} to call methods for a specific version of a {@link Service}. * * @param service {@link ServiceId} of the service * @return a URL to call methods of the service * @throws NotFoundException @throws NotFoundException if the app or service could not be found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public URL getVersionedServiceURL(ServiceId service) throws NotFoundException, IOException, UnauthenticatedException, UnauthorizedException { // Make sure the service actually exists get(service); return config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s/methods/", service.getApplication(), service.getVersion(), service.getEntityName())); }