use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class TestAppWithCube method add.
private void add(URL serviceUrl, Collection<CubeFact> facts) throws IOException {
URL url = new URL(serviceUrl, "add");
HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(facts)).build();
HttpResponse response = HttpRequests.execute(request);
Assert.assertEquals(200, response.getResponseCode());
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteNotificationFeedManager method deleteFeed.
@Override
public void deleteFeed(NotificationFeedId feed) throws NotificationFeedNotFoundException, NotificationFeedException {
String path = String.format("namespaces/%s/feeds/categories/%s/names/%s", feed.getNamespace(), feed.getCategory(), feed.getFeed());
HttpResponse response = execute(remoteClient.requestBuilder(HttpMethod.DELETE, path).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotificationFeedNotFoundException(feed);
} else if (response.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new NotificationFeedException("Cannot delete notification feed. Reason: " + response);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteNotificationFeedManager method createFeed.
@Override
public boolean createFeed(NotificationFeedInfo feed) throws NotificationFeedException {
String path = String.format("namespaces/%s/feeds/categories/%s/names/%s", feed.getNamespace(), feed.getCategory(), feed.getFeed());
HttpRequest request = remoteClient.requestBuilder(HttpMethod.PUT, path).withBody(GSON.toJson(feed)).build();
HttpResponse response = execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return true;
} else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
return false;
}
throw new NotificationFeedException("Cannot create notification feed. Reason: " + response);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteNotificationFeedManager method listFeeds.
@Override
public List<NotificationFeedInfo> listFeeds(NamespaceId namespace) throws NotificationFeedException {
String path = String.format("namespaces/%s/feeds", namespace.getNamespace());
HttpResponse response = execute(remoteClient.requestBuilder(HttpMethod.GET, path).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
ObjectResponse<List<NotificationFeedInfo>> r = ObjectResponse.fromJsonBody(response, new TypeToken<List<NotificationFeedInfo>>() {
}.getType());
return r.getResponseObject();
}
throw new NotificationFeedException("Cannot list notification feeds. Reason: " + response);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ClientMessagingService method getTopic.
@Override
public TopicMetadata getTopic(TopicId topicId) throws TopicNotFoundException, IOException {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, createTopicPath(topicId)).build();
HttpResponse response = remoteClient.execute(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic());
}
handleError(response, "Failed to update topic " + topicId);
Map<String, String> properties = GSON.fromJson(response.getResponseBodyAsString(), TOPIC_PROPERTY_TYPE);
return new TopicMetadata(topicId, properties);
}
Aggregations