@Override public boolean exists(NamespaceId namespaceId) throws Exception { try { get(namespaceId); } catch (NamespaceNotFoundException e) { return false; } catch (UnauthorizedException e) { // get throws UnauthorizedException only after ensuring that the namespace exists. Ignoring since we have // semantics that user can check for existence without having access } return true; } }
@Override public List<NamespaceMeta> list() throws Exception { HttpRequest request = HttpRequest.get(resolve("namespaces")).build(); HttpResponse response = execute(request); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return ObjectResponse.fromJsonBody(response, new TypeToken<List<NamespaceMeta>>() { }).getResponseObject(); } throw new IOException(String.format("Cannot list namespaces. Reason: %s", response.getResponseBodyAsString())); }
@Override public List<NamespaceMeta> list() throws Exception { HttpRequest request = HttpRequest.get(resolve("namespaces")).build(); HttpResponse response = execute(request); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return ObjectResponse.fromJsonBody(response, new TypeToken<List<NamespaceMeta>>() { }).getResponseObject(); } throw new IOException(String.format("Cannot list namespaces. Reason: %s", response.getResponseBodyAsString())); }
@Override public NamespaceMeta get(NamespaceId namespaceId) throws Exception { HttpResponse response = execute(HttpRequest.get(resolve(String.format("namespaces/%s", namespaceId.getNamespace()))).build()); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NamespaceNotFoundException(namespaceId); } else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return ObjectResponse.fromJsonBody(response, NamespaceMeta.class).getResponseObject(); } throw new IOException(String.format("Cannot get namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString())); }
@Override public boolean exists(NamespaceId namespaceId) throws Exception { try { get(namespaceId); } catch (NamespaceNotFoundException e) { return false; } catch (UnauthorizedException e) { // get throws UnauthorizedException only after ensuring that the namespace exists. Ignoring since we have // semantics that user can check for existence without having access } return true; } }
@Override public NamespaceMeta get(NamespaceId namespaceId) throws Exception { HttpResponse response = execute(HttpRequest.get(resolve(String.format("namespaces/%s", namespaceId.getNamespace()))).build()); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NamespaceNotFoundException(namespaceId); } else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return ObjectResponse.fromJsonBody(response, NamespaceMeta.class).getResponseObject(); } throw new IOException(String.format("Cannot get namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString())); }