Search in sources :

Example 96 with HttpResponse

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());
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 97 with HttpResponse

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);
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) NotificationFeedNotFoundException(co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException) HttpResponse(co.cask.common.http.HttpResponse)

Example 98 with HttpResponse

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);
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) HttpResponse(co.cask.common.http.HttpResponse)

Example 99 with HttpResponse

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);
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo) List(java.util.List)

Example 100 with HttpResponse

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);
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) TopicNotFoundException(co.cask.cdap.api.messaging.TopicNotFoundException) HttpResponse(co.cask.common.http.HttpResponse) TopicMetadata(co.cask.cdap.messaging.TopicMetadata)

Aggregations

HttpResponse (co.cask.common.http.HttpResponse)204 URL (java.net.URL)145 HttpRequest (co.cask.common.http.HttpRequest)77 NotFoundException (co.cask.cdap.common.NotFoundException)41 TypeToken (com.google.common.reflect.TypeToken)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)24 Test (org.junit.Test)24 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)19 BadRequestException (co.cask.cdap.common.BadRequestException)17 IOException (java.io.IOException)14 ExploreException (co.cask.cdap.explore.service.ExploreException)12 ServiceManager (co.cask.cdap.test.ServiceManager)12 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)10 ApplicationManager (co.cask.cdap.test.ApplicationManager)10 StreamNotFoundException (co.cask.cdap.common.StreamNotFoundException)8 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)6 TypeToken (com.google.gson.reflect.TypeToken)6 List (java.util.List)6 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)5 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)5