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());
}
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());
}
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;
}
}
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"));
}
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"));
}
Aggregations