Search in sources :

Example 26 with HttpRequest

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

the class ArtifactCacheServiceTest method testArtifactNotFound.

@Test
public void testArtifactNotFound() throws Exception {
    Id.Artifact notFoundArtifact = Id.Artifact.from(Id.Namespace.DEFAULT, "other-task", "2.0.0-SNAPSHOT");
    URL url = getURL(PEER_NAME, notFoundArtifact);
    HttpRequest httpRequest = HttpRequest.builder(HttpMethod.GET, url).build();
    HttpResponse httpResponse = HttpRequests.execute(httpRequest);
    Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, httpResponse.getResponseCode());
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) URL(java.net.URL) Test(org.junit.Test) TaskWorkerServiceTest(io.cdap.cdap.internal.app.worker.TaskWorkerServiceTest)

Example 27 with HttpRequest

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

the class TetheringServerHandlerTest method testConnectControlChannelUnknownPeer.

@Test
public void testConnectControlChannelUnknownPeer() throws IOException {
    HttpRequest request = HttpRequest.builder(HttpMethod.GET, config.resolveURL("/tethering/controlchannels/bad_peer")).build();
    HttpResponse response = HttpRequests.execute(request);
    Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.getResponseCode());
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) Test(org.junit.Test)

Example 28 with HttpRequest

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

the class DatasetServiceClient method doRequest.

private HttpResponse doRequest(HttpRequest.Builder requestBuilder) throws DatasetManagementException, UnauthorizedException {
    HttpRequest request = addUserIdHeader(requestBuilder).build();
    try {
        LOG.trace("Executing {} {}", request.getMethod(), request.getURL().getPath());
        HttpResponse response = remoteClient.execute(request);
        LOG.trace("Executed {} {}", request.getMethod(), request.getURL().getPath());
        return response;
    } catch (ServiceUnavailableException e) {
        // thrown by RemoteClient in case of ConnectException
        logThreadDump();
        LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
        throw e;
    } catch (SocketTimeoutException e) {
        // passed through by RemoteClient
        logThreadDump();
        LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
        throw new DatasetManagementException(remoteClient.createErrorMessage(request, null), e);
    } catch (IOException e) {
        // other network exceptions
        LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
        throw new DatasetManagementException(remoteClient.createErrorMessage(request, null), e);
    } catch (Throwable e) {
        // anything unexpected
        LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
        throw e;
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) SocketTimeoutException(java.net.SocketTimeoutException) HttpResponse(io.cdap.common.http.HttpResponse) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) IOException(java.io.IOException)

Example 29 with HttpRequest

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

the class RESTClientTest method testDeleteForbidden.

@Test(expected = UnauthorizedException.class)
public void testDeleteForbidden() throws Exception {
    URL url = getBaseURI().resolve("/api/testDeleteForbidden").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 30 with HttpRequest

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

the class RESTClientTest method testPutForbidden.

@Test(expected = UnauthorizedException.class)
public void testPutForbidden() throws Exception {
    URL url = getBaseURI().resolve("/api/testPutForbidden").toURL();
    HttpRequest request = HttpRequest.put(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)

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