use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method createRole.
@Override
public void createRole(Role role) throws AccessException {
URL url = resolveURL(String.format(AUTHORIZATION_BASE + "roles/%s", role.getName()));
HttpRequest request = HttpRequest.put(url).build();
HttpResponse httpResponse = doExecuteRequest(request, HttpURLConnection.HTTP_CONFLICT);
if (httpResponse.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new AlreadyExistsException(role);
}
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class AuthorizationClient method listGrants.
@Override
public Set<GrantedPermission> listGrants(Principal principal) throws AccessException {
String urlStr = String.format(AUTHORIZATION_BASE + "%s/%s/privileges", principal.getType(), principal.getName());
URL url = resolveURL(urlStr);
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = doExecuteRequest(request);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return ObjectResponse.fromJsonBody(response, TYPE_OF_PRIVILEGE_SET, GSON).getResponseObject();
}
throw new AccessIOException(String.format("Cannot list privileges. Reason: %s", response.getResponseBodyAsString()));
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ProgramClient method getStatus.
/**
* Gets the status of multiple programs.
*
* @param namespace the namespace of the programs
* @param programs the list of programs to get status for
* @return the status of each program
*/
public List<BatchProgramStatus> getStatus(NamespaceId namespace, List<BatchProgram> programs) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "status");
HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(programs)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken());
return ObjectResponse.<List<BatchProgramStatus>>fromJsonBody(response, BATCH_STATUS_RESPONSE_TYPE, GSON).getResponseObject();
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ScheduleClient method doAdd.
/*------------ private helpers ---------------------*/
private void doAdd(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException {
String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path);
HttpRequest request = HttpRequest.put(url).withBody(json).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
} else if (HttpURLConnection.HTTP_CONFLICT == response.getResponseCode()) {
throw new AlreadyExistsException(scheduleId);
}
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class RESTClientTest method testPostUnauthorizedWithAccessToken.
@Test(expected = UnauthenticatedException.class)
public void testPostUnauthorizedWithAccessToken() throws Exception {
URL url = getBaseURI().resolve("/api/testPostAuth").toURL();
HttpRequest request = HttpRequest.post(url).build();
restClient.execute(request, new AccessToken("Unknown", 82000L, "Bearer"));
}
Aggregations