Search in sources :

Example 11 with HttpResponse

use of co.cask.common.http.HttpResponse in project cdap by caskdata.

the class RemotePrivilegesManager method listPrivileges.

@Override
public Set<Privilege> listPrivileges(Principal principal) throws Exception {
    LOG.trace("Listing privileges for {}", principal);
    HttpResponse httpResponse = executeRequest("listPrivileges", principal);
    String responseBody = httpResponse.getResponseBodyAsString();
    LOG.debug("List privileges response for principal {}: {}", principal, responseBody);
    return GSON.fromJson(responseBody, SET_PRIVILEGES_TYPE);
}
Also used : HttpResponse(co.cask.common.http.HttpResponse)

Example 12 with HttpResponse

use of co.cask.common.http.HttpResponse in project cdap by caskdata.

the class RemoteUGIProvider method executeRequest.

private HttpResponse executeRequest(ImpersonationRequest impersonationRequest) throws IOException {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "impersonation/credentials").withBody(GSON.toJson(impersonationRequest)).build();
    HttpResponse response = remoteClient.execute(request);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return response;
    }
    throw new IOException(String.format("%s Response: %s.", createErrorMessage(request.getURL()), response));
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse) IOException(java.io.IOException)

Example 13 with HttpResponse

use of co.cask.common.http.HttpResponse in project cdap by caskdata.

the class StreamHandlerTest method getNumProcessed.

private long getNumProcessed(StreamId streamId) throws Exception {
    String path = String.format("/v3/metrics/query?metric=system.collect.events&tag=namespace:%s&tag=stream:%s&aggregate=true", streamId.getNamespace(), streamId.getEntityName());
    HttpRequest request = HttpRequest.post(getEndPoint(path).toURL()).build();
    HttpResponse response = HttpRequests.execute(request);
    Assert.assertEquals(200, response.getResponseCode());
    return getNumEventsFromResponse(response.getResponseBodyAsString());
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse)

Example 14 with HttpResponse

use of co.cask.common.http.HttpResponse in project cdap by caskdata.

the class StreamHandlerTest method sendEvent.

private void sendEvent(StreamId streamId, String body) throws Exception {
    URL url = createURL(streamId.getNamespace(), "streams/" + streamId.getEntityName());
    HttpRequest request = HttpRequest.post(url).withBody(body).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 15 with HttpResponse

use of co.cask.common.http.HttpResponse in project cdap by caskdata.

the class StreamHandlerTest method testStreamCreateInNonexistentNamespace.

@Test
public void testStreamCreateInNonexistentNamespace() throws Exception {
    NamespaceId originallyNonExistentNamespace = new NamespaceId("originallyNonExistentNamespace");
    StreamId streamId = originallyNonExistentNamespace.stream("streamName");
    HttpResponse response = createStream(streamId, 404);
    Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.getResponseCode());
    // once the namespace exists, the same stream create works.
    namespaceAdmin.create(new NamespaceMeta.Builder().setName(originallyNonExistentNamespace).build());
    createStream(streamId);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) HttpResponse(co.cask.common.http.HttpResponse) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Aggregations

HttpResponse (co.cask.common.http.HttpResponse)216 URL (java.net.URL)147 HttpRequest (co.cask.common.http.HttpRequest)80 NotFoundException (co.cask.cdap.common.NotFoundException)42 TypeToken (com.google.common.reflect.TypeToken)26 Test (org.junit.Test)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)24 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)21 BadRequestException (co.cask.cdap.common.BadRequestException)20 IOException (java.io.IOException)16 ExploreException (co.cask.cdap.explore.service.ExploreException)13 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 HashMap (java.util.HashMap)7 List (java.util.List)7 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)6 TypeToken (com.google.gson.reflect.TypeToken)6 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)5