use of org.codehaus.jettison.json.JSONObject in project jersey by jersey.
the class BookmarkTest method step4_updateUser.
@Test
public void step4_updateUser() {
boolean thrown = false;
try {
JSONObject user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
user.put("password", "NEW PASSWORD").put("email", "NEW@EMAIL.NET").put("username", "UPDATED TEST USER");
target().path("resources/users/testuid").request().put(Entity.entity(user, "application/json"));
user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
assertEquals(user.get("username"), "UPDATED TEST USER");
assertEquals(user.get("email"), "NEW@EMAIL.NET");
assertEquals(user.get("password"), "NEW PASSWORD");
} catch (Exception e) {
e.printStackTrace();
thrown = true;
}
assertFalse(thrown);
}
use of org.codehaus.jettison.json.JSONObject in project jersey by jersey.
the class BookmarkTest method step4_updateUser.
@Test
public void step4_updateUser() {
boolean thrown = false;
try {
JSONObject user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
user.put("password", "NEW PASSWORD").put("email", "NEW@EMAIL.NET").put("username", "UPDATED TEST USER");
target().path("resources/users/testuid").request().put(Entity.entity(user, "application/json"));
user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
assertEquals(user.get("username"), "UPDATED TEST USER");
assertEquals(user.get("email"), "NEW@EMAIL.NET");
assertEquals(user.get("password"), "NEW PASSWORD");
} catch (Exception e) {
e.printStackTrace();
thrown = true;
}
assertFalse(thrown);
}
use of org.codehaus.jettison.json.JSONObject in project jersey by jersey.
the class BookmarkTest method step5_getUserBookmarkList.
// ugly.. but separation into separate test cases would be probably uglier
@Test
public void step5_getUserBookmarkList() {
boolean thrown = false;
try {
JSONObject user = target().path("resources/users/testuid").request("application/json").get(JSONObject.class);
assertTrue(user != null);
final WebTarget webTarget = client().target(user.getString("bookmarks"));
JSONObject bookmark = new JSONObject();
bookmark.put("uri", "http://java.sun.com").put("sdesc", "test desc").put("ldesc", "long test description");
webTarget.request().post(Entity.entity(bookmark, "application/json"));
JSONArray bookmarks = webTarget.request("application/json").get(JSONArray.class);
assertTrue(bookmarks != null);
int bookmarksSize = bookmarks.length();
String testBookmarkUrl = bookmarks.getString(0);
final WebTarget bookmarkResource = client().target(testBookmarkUrl);
bookmark = bookmarkResource.request("application/json").get(JSONObject.class);
assertTrue(bookmark != null);
bookmarkResource.request().delete();
bookmarks = target().path("resources/users/testuid/bookmarks").request("application/json").get(JSONArray.class);
assertTrue(bookmarks != null);
assertTrue(bookmarks.length() == (bookmarksSize - 1));
} catch (Exception e) {
e.printStackTrace();
thrown = true;
}
assertFalse(thrown);
}
use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.
the class TopCLI method getJSONObject.
private JSONObject getJSONObject(URLConnection conn) throws IOException, JSONException {
try (InputStream in = conn.getInputStream()) {
String encoding = conn.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding);
JSONObject obj = new JSONObject(body);
JSONObject clusterInfo = obj.getJSONObject("clusterInfo");
return clusterInfo;
}
}
use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.
the class LogsCLI method getAMContainerInfoForRMWebService.
protected List<JSONObject> getAMContainerInfoForRMWebService(Configuration conf, String appId) throws ClientHandlerException, UniformInterfaceException, JSONException {
Client webServiceClient = Client.create();
String webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(conf);
WebResource webResource = webServiceClient.resource(webAppAddress);
ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps").path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
JSONObject json = response.getEntity(JSONObject.class).getJSONObject("appAttempts");
JSONArray requests = json.getJSONArray("appAttempt");
List<JSONObject> amContainersList = new ArrayList<JSONObject>();
for (int i = 0; i < requests.length(); i++) {
amContainersList.add(requests.getJSONObject(i));
}
return amContainersList;
}
Aggregations