use of co.cask.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 co.cask.common.http.HttpRequest in project cdap by caskdata.
the class RESTClientTest method testPostSuccessWithAccessToken.
@Test
public void testPostSuccessWithAccessToken() throws Exception {
URL url = getBaseURI().resolve("/api/testPostAuth").toURL();
HttpRequest request = HttpRequest.post(url).build();
HttpResponse response = restClient.execute(request, new AccessToken(ACCESS_TOKEN, 82000L, "Bearer"));
verifyResponse(response, only(200), any(), only("Access token received: " + ACCESS_TOKEN));
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method update.
/**
* Update an existing app to use a different artifact version or config.
*
* @param appId the id of the application to update
* @param updateRequest the request to update the application with
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NotFoundException if the app or requested artifact could not be found
* @throws BadRequestException if the request is invalid
*/
public void update(ApplicationId appId, AppRequest<?> updateRequest) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(appId.getParent(), String.format("apps/%s/update", appId.getApplication()));
HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(updateRequest)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException("app or app artifact");
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(String.format("Bad Request. Reason: %s", response.getResponseBodyAsString()));
}
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ApplicationClient method deploy.
/**
* Creates an application with a version using an existing artifact.
*
* @param appId the id of the application to add
* @param createRequest the request body, which contains the artifact to use and any application config
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void deploy(ApplicationId appId, AppRequest<?> createRequest) throws IOException, UnauthenticatedException {
URL url = config.resolveNamespacedURLV3(new NamespaceId(appId.getNamespace()), String.format("apps/%s/versions/%s/create", appId.getApplication(), appId.getVersion()));
HttpRequest request = HttpRequest.post(url).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(GSON.toJson(createRequest)).build();
restClient.upload(request, config.getAccessToken());
}
use of co.cask.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"));
}
Aggregations