Search in sources :

Example 51 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class RESTClientTest method testDeleteSuccessWithAccessToken.

@Test
public void testDeleteSuccessWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testDeleteAuth").toURL();
    HttpRequest request = HttpRequest.delete(url).build();
    HttpResponse response = restClient.execute(request, new AccessToken(ACCESS_TOKEN, 82000L, "Bearer"));
    verifyResponse(response, only(200), any(), only("Access token received: " + ACCESS_TOKEN));
}
Also used : FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) HttpRequest(io.cdap.common.http.HttpRequest) AccessToken(io.cdap.cdap.security.authentication.client.AccessToken) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) Test(org.junit.Test)

Example 52 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class RESTClientTest method testDeleteUnauthorizedWithAccessToken.

@Test(expected = UnauthenticatedException.class)
public void testDeleteUnauthorizedWithAccessToken() throws Exception {
    URL url = getBaseURI().resolve("/api/testDeleteAuth").toURL();
    HttpRequest request = HttpRequest.delete(url).build();
    restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Also used : FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) HttpRequest(io.cdap.common.http.HttpRequest) AccessToken(io.cdap.cdap.security.authentication.client.AccessToken) URL(java.net.URL) Test(org.junit.Test)

Example 53 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DefaultMetadataServiceClient method batch.

@Override
public void batch(List<MetadataMutation> mutations) {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "metadata-internals/batch").withBody(GSON.toJson(mutations)).build();
    HttpResponse response = execute(request);
    if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
        LOG.trace("Failed to apply metadata mutations for mutations %s: %s", mutations, response);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse)

Example 54 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class DefaultMetadataServiceClient method create.

@Override
public void create(MetadataMutation.Create createMutation) {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "metadata-internals/create").withBody(GSON.toJson(createMutation)).build();
    HttpResponse response = execute(request);
    if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
        LOG.trace("Failed to create metadata for entity %s: %s", createMutation.getEntity(), response);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse)

Example 55 with HttpRequest

use of io.cdap.common.http.HttpRequest in project cdap by caskdata.

the class RemoteAccessEnforcer method visibilityCheckCall.

private Set<? extends EntityId> visibilityCheckCall(VisibilityRequest visibilityRequest) throws IOException, UnauthorizedException {
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "isVisible").withBody(GSON.toJson(visibilityRequest)).build();
    LOG.trace("Remotely checking visibility on authorization privilege {}", visibilityRequest);
    return GSON.fromJson(remoteClient.execute(request).getResponseBodyAsString(), SET_ENTITY_TYPE);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest)

Aggregations

HttpRequest (io.cdap.common.http.HttpRequest)124 HttpResponse (io.cdap.common.http.HttpResponse)92 URL (java.net.URL)81 Test (org.junit.Test)33 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 IOException (java.io.IOException)14 AccessToken (io.cdap.cdap.security.authentication.client.AccessToken)13 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)10 BadRequestException (io.cdap.cdap.common.BadRequestException)9 NotFoundException (io.cdap.cdap.common.NotFoundException)8 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)5 ServiceManager (io.cdap.cdap.test.ServiceManager)5 TypeToken (com.google.gson.reflect.TypeToken)4 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)4 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)4 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 TopicId (io.cdap.cdap.proto.id.TopicId)4 ApplicationManager (io.cdap.cdap.test.ApplicationManager)4 ByteBuffer (java.nio.ByteBuffer)4