use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class PrivilegeRestTest method getAndDeleteAndAdd.
@Test(dependsOnMethods = "getAndPut")
public void getAndDeleteAndAdd() throws Exception {
String result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
JSONObject jbody = parseResult(result);
String jsonStr = jbody.getString(PrivilegeResource.RESULT);
result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).delete(String.class);
//OK
validateResult(result, 200, "OK");
Form form = new Form();
form.add("privilege.json", jsonStr);
form.add("subject", hashedTokenId);
result = webClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
validateResult(result, 201, "Created");
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class PrivilegeRestTest method getAndPut.
@Test(dependsOnMethods = "search")
public void getAndPut() throws Exception {
String result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
JSONObject jbody = parseResult(result);
String jsonStr = jbody.getString(PrivilegeResource.RESULT);
Privilege privilege = Privilege.getNewInstance(new JSONObject(jsonStr));
privilege.setDescription("desciption1");
Form form = new Form();
form.add("privilege.json", privilege.toMinimalJSONObject());
result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).put(String.class, form);
//OK
validateResult(result, 200, "OK");
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestPermissionTest method decisionRestCall.
private void decisionRestCall() throws Exception {
Form params = new Form();
params.add("subject", hashedTokenId);
params.add("resource", "http://www.example.com/index.html");
params.add("action", "GET");
params.add("realm", REALM);
decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
}
use of com.sun.jersey.api.representation.Form in project ORCID-Source by ORCID.
the class SalesForceDaoImpl method getFreshAccessToken.
private String getFreshAccessToken() {
LOGGER.info("About get SalesForce access token");
WebResource resource = client.resource(tokenEndPointUrl);
Form form = new Form();
form.add("grant_type", "password");
form.add("client_id", clientId);
form.add("client_secret", clientSecret);
form.add("username", username);
form.add("password", password);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, form);
if (response.getStatus() == 200) {
try {
return response.getEntity(JSONObject.class).getString("access_token");
} catch (ClientHandlerException | UniformInterfaceException | JSONException e) {
throw new RuntimeException("Unable to extract access token from response", e);
}
} else {
throw new RuntimeException("Error getting access token from SalesForce, status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body = " + response.getEntity(String.class));
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method missingResourceTest.
@Test
public void missingResourceTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
try {
entitlementClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
throw new Exception("RESTTest.missingResourceTest: no exception thrown.");
} catch (UniformInterfaceException e) {
int errorCode = e.getResponse().getStatus();
if (errorCode != 400) {
throw new Exception("RESTTest.missingResourceTest: incorrect error code");
}
String json = e.getResponse().getEntity(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 420) {
throw new Exception("RESTTest.missingResourceTest() failed, status code not 420");
}
if (jo.optJSONObject("body") != null) {
throw new Exception("RESTTest.missingResourceTest() failed, body not empty");
}
}
}
Aggregations