use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ArtifactClient method deleteProperty.
/**
* Delete a property for an artifact. If the property does not exist, this will be a no-op.
*
* @param artifactId the artifact to delete a property from
* @param key the property to delete
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the artifact does not exist
* @throws IOException if a network error occurred
*/
public void deleteProperty(ArtifactId artifactId, String key) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties/%s", artifactId.getArtifact(), artifactId.getVersion(), key);
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpRequest.Builder requestBuilder = HttpRequest.delete(url);
HttpRequest request = requestBuilder.build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class ArtifactClient method delete.
/**
* Delete an artifact.
*
* @param artifactId the artifact to delete
*
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void delete(ArtifactId artifactId) throws IOException, UnauthenticatedException, BadRequestException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), String.format("artifacts/%s/versions/%s", artifactId.getArtifact(), artifactId.getVersion()));
HttpRequest request = HttpRequest.delete(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method grant.
@Override
public void grant(EntityId entity, Principal principal, Set<Action> actions) throws IOException, UnauthenticatedException, FeatureDisabledException, UnauthorizedException, NotFoundException {
GrantRequest grantRequest = new GrantRequest(entity, principal, actions);
URL url = config.resolveURLV3(AUTHORIZATION_BASE + "/privileges/grant");
HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(grantRequest)).build();
executePrivilegeRequest(request);
}
use of co.cask.common.http.HttpRequest in project cdap by caskdata.
the class RESTClientTest method testPutSuccessWithAccessToken.
@Test
public void testPutSuccessWithAccessToken() throws Exception {
URL url = getBaseURI().resolve("/api/testPutAuth").toURL();
HttpRequest request = HttpRequest.put(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 RESTClientTest method testGetUnauthorizedWithAccessToken.
@Test(expected = UnauthenticatedException.class)
public void testGetUnauthorizedWithAccessToken() throws Exception {
URL url = getBaseURI().resolve("/api/testGetAuth").toURL();
HttpRequest request = HttpRequest.get(url).build();
restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Aggregations