private EmoApiKey getApiKeyFromResponse(EmoResponse response) { if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.getEntity(EmoApiKey.class); } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { return null; } throw convertException(new EmoClientException(response)); }
@Override public BlobMetadata getMetadata(String apiKey, String table, String blobId) throws BlobNotFoundException { checkNotNull(table, "table"); checkNotNull(blobId, "blobId"); try { EmoResponse response = _client.resource(toUri(table, blobId)) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && BlobNotFoundException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { throw new BlobNotFoundException(blobId, new EmoClientException(response)); } else if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw new EmoClientException(response); } return parseMetadataHeaders(blobId, response); } catch (EmoClientException e) { throw convertException(e); } }
@Override public BlobMetadata getMetadata(String apiKey, String table, String blobId) throws BlobNotFoundException { checkNotNull(table, "table"); checkNotNull(blobId, "blobId"); try { EmoResponse response = _client.resource(toUri(table, blobId)) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && BlobNotFoundException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { throw new BlobNotFoundException(blobId, new EmoClientException(response)); } else if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw new EmoClientException(response); } return parseMetadataHeaders(blobId, response); } catch (EmoClientException e) { throw convertException(e); } }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
/** Returns an EmoClientException with a thin wrapper around the Jersey exception response. */ private EmoClientException asEmoClientException(UniformInterfaceException e) throws EmoClientException { throw new EmoClientException(e.getMessage(), e, toEmoResponse(e.getResponse())); }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _dataStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _dataStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _blobStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public boolean getTableExists(String apiKey, String table) { checkNotNull(table, "table"); URI uri = _blobStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .head(); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return true; } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() && UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) { return false; } else { throw convertException(new EmoClientException(response)); } }
@Override public void dropTable(String apiKey, String table, Audit audit) throws UnknownTableException { checkNotNull(table, "table"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .queryParam("audit", RisonHelper.asORison(audit)) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .delete(EmoResponse.class); if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw convertException(new EmoClientException(response)); } }
@Override public void dropTable(String apiKey, String table, Audit audit) throws UnknownTableException { checkNotNull(table, "table"); checkNotNull(audit, "audit"); URI uri = _dataStore.clone() .segment("_table", table) .build(); EmoResponse response = _client.resource(uri) .queryParam("audit", RisonHelper.asORison(audit)) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .delete(EmoResponse.class); if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw convertException(new EmoClientException(response)); } }
@Override public PollResult poll(String apiKey, @PartitionKey String subscription, Duration claimTtl, int limit) { checkNotNull(subscription, "subscription"); checkNotNull(claimTtl, "claimTtl"); URI uri = getPollUriBuilder(subscription, claimTtl, limit).build(); EmoResponse response = _client.resource(uri) .queryParam("includeTags", "true") .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .get(EmoResponse.class); if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw convertException(new EmoClientException(response)); } Iterator<Event> events = response.getEntity(new TypeReference<Iterator<Event>>() {}); boolean moreEvents; String databusEmpty = response.getFirstHeader(POLL_DATABUS_EMPTY_HEADER); if (databusEmpty != null) { // Use the header value from the server to determine if the databus subscription is empty moreEvents = !Boolean.parseBoolean(databusEmpty); } else { // Must be polling an older version of Emo which did not include this header. Infer whether the queue // is empty based on whether any results were returned. moreEvents = events.hasNext(); } return new PollResult(events, limit, moreEvents); }
throw new EmoClientException(response);
throw new EmoClientException(response);
@Override public EmoRole getRole(String apiKey, EmoRoleKey roleKey) { checkNotNull(roleKey, "roleKey"); URI uri = _uac.clone() .segment("role") .segment(roleKey.getGroup()) .segment(roleKey.getId()) .build(); EmoResponse response = _client.resource(uri) .accept(MediaType.APPLICATION_JSON_TYPE) .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey) .get(EmoResponse.class); if (response.getStatus() == Response.Status.OK.getStatusCode()) { return response.getEntity(EmoRole.class); } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { return null; } throw convertException(new EmoClientException(response)); }