Java Code Examples for com.sun.jersey.api.client.ClientResponse#getEntity()
The following examples show how to use
com.sun.jersey.api.client.ClientResponse#getEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAMWebServicesJobConf.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testJobConfDefault() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("conf").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("conf"); verifyAMJobConf(info, jobsMap.get(id)); } }
Example 2
Source File: TestNMWebServicesContainers.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testNodeContainerXML() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); ClientResponse response = r.path("ws").path("v1").path("node") .path("containers").accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("container"); assertEquals("incorrect number of elements", 4, nodes.getLength()); }
Example 3
Source File: TestHsWebServicesAttempts.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testTaskAttemptsSlash() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid) .path("attempts/").accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyHsTaskAttempts(json, task); } } }
Example 4
Source File: TestAMWebServicesJobs.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testJobAttemptsXML() throws Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1") .path("mapreduce").path("jobs").path(jobId).path("jobattempts") .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList attempts = dom.getElementsByTagName("jobAttempts"); assertEquals("incorrect number of elements", 1, attempts.getLength()); NodeList info = dom.getElementsByTagName("jobAttempt"); verifyJobAttemptsXML(info, jobsMap.get(id)); } }
Example 5
Source File: TestAMWebServicesJobs.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testJobCountersDefault() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws").path("v1").path("mapreduce") .path("jobs").path(jobId).path("counters/").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("jobCounters"); verifyAMJobCounters(info, jobsMap.get(id)); } }
Example 6
Source File: ProjectService.java From jira-rest-client with Apache License 2.0 | 6 votes |
public List<Project> getProjectList() throws IOException { if (client == null) throw new IllegalStateException("HTTP Client not Initailized"); client.setResourceName(Constants.JIRA_RESOURCE_PROJECT); ClientResponse response = client.get(); String content = response.getEntity(String.class); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true); TypeReference<List<Project>> ref = new TypeReference<List<Project>>(){}; List<Project> prj = mapper.readValue(content, ref); return prj; }
Example 7
Source File: TestRMWebServices.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testClusterSlash() throws JSONException, Exception { WebResource r = resource(); // test with trailing "/" to make sure acts same as without slash ClientResponse response = r.path("ws").path("v1").path("cluster/") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterInfo(json); }
Example 8
Source File: TestNMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testNode() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("node") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyNodeInfo(json); }
Example 9
Source File: TestRMWebServices.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testClusterDefault() throws JSONException, Exception { WebResource r = resource(); // test with trailing "/" to make sure acts same as without slash ClientResponse response = r.path("ws").path("v1").path("cluster") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterInfo(json); }
Example 10
Source File: TestNMWebServices.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testNode() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("node") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyNodeInfo(json); }
Example 11
Source File: ITConnectionAccessControl.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Ensures the READ_WRITE user can put a connection. * * @throws Exception ex */ @Test public void testReadWriteUserPutConnection() throws Exception { final ConnectionEntity entity = getRandomConnection(helper.getReadWriteUser()); assertTrue(entity.getPermissions().getCanRead()); assertTrue(entity.getPermissions().getCanWrite()); assertNotNull(entity.getComponent()); final String updatedName = "Updated Name"; // attempt to update the name final long version = entity.getRevision().getVersion(); entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID); entity.getComponent().setName(updatedName); // perform the request final ClientResponse response = updateConnection(helper.getReadWriteUser(), entity); // ensure successful response assertEquals(200, response.getStatus()); // get the response final ConnectionEntity responseEntity = response.getEntity(ConnectionEntity.class); // verify assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId()); assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue()); assertEquals(updatedName, responseEntity.getComponent().getName()); }
Example 12
Source File: TestHsWebServicesTasks.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testTaskIdXML() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws").path("v1").path("history") .path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid) .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("task"); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); verifyHsSingleTaskXML(element, task); } } } }
Example 13
Source File: ConnectionWebServiceClient.java From nextreports-server with Apache License 2.0 | 5 votes |
public DatabaseMetaData getMetaData(String id) throws WebServiceException { ClientResponse response = createRootResource().path("jdbc/connection/getMetaData") .post(ClientResponse.class, id); checkForException(response); String metaDataId = response.getEntity(String.class); return new DatabaseMetaData(metaDataId, this); }
Example 14
Source File: ITInputPortAccessControl.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Ensures the READ_WRITE user can put an input port. * * @throws Exception ex */ @Test public void testReadWriteUserPutInputPort() throws Exception { final PortEntity entity = getRandomInputPort(helper.getReadWriteUser()); assertTrue(entity.getPermissions().getCanRead()); assertTrue(entity.getPermissions().getCanWrite()); assertNotNull(entity.getComponent()); final String updatedName = "Updated Name" + count++; // attempt to update the name final long version = entity.getRevision().getVersion(); entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID); entity.getComponent().setName(updatedName); // perform the request final ClientResponse response = updateInputPort(helper.getReadWriteUser(), entity); // ensure successful response assertEquals(200, response.getStatus()); // get the response final PortEntity responseEntity = response.getEntity(PortEntity.class); // verify assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId()); assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue()); assertEquals(updatedName, responseEntity.getComponent().getName()); }
Example 15
Source File: TestAHSWebServices.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testSingleContainer() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()).path("containers") .path(containerId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); if (round == 1) { assertEquals( Status.FORBIDDEN, response.getClientResponseStatus()); return; } assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject container = json.getJSONObject("container"); assertEquals(containerId.toString(), container.getString("containerId")); assertEquals("test diagnostics info", container.getString("diagnosticsInfo")); assertEquals("-1", container.getString("allocatedMB")); assertEquals("-1", container.getString("allocatedVCores")); assertEquals(NodeId.newInstance("test host", 100).toString(), container.getString("assignedNodeId")); assertEquals("-1", container.getString("priority")); Configuration conf = new YarnConfiguration(); assertEquals(WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils.getAHSWebAppURLWithoutScheme(conf) + "/applicationhistory/logs/test host:100/container_0_0001_01_000001/" + "container_0_0001_01_000001/user1", container.getString("logUrl")); assertEquals(ContainerState.COMPLETE.toString(), container.getString("containerState")); }
Example 16
Source File: TestNMWebServicesApps.java From big-c with Apache License 2.0 | 5 votes |
public void testNodeHelper(String path, String media) throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); HashMap<String, String> hash = addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); HashMap<String, String> hash2 = addAppContainers(app2); ClientResponse response = r.path("ws").path("v1").path("node").path(path) .accept(media).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); JSONObject info = json.getJSONObject("apps"); assertEquals("incorrect number of elements", 1, info.length()); JSONArray appInfo = info.getJSONArray("app"); assertEquals("incorrect number of elements", 2, appInfo.length()); String id = appInfo.getJSONObject(0).getString("id"); if (id.matches(app.getAppId().toString())) { verifyNodeAppInfo(appInfo.getJSONObject(0), app, hash); verifyNodeAppInfo(appInfo.getJSONObject(1), app2, hash2); } else { verifyNodeAppInfo(appInfo.getJSONObject(0), app2, hash2); verifyNodeAppInfo(appInfo.getJSONObject(1), app, hash); } }
Example 17
Source File: TestTimelineWebServices.java From ambari-metrics with Apache License 2.0 | 5 votes |
@Test public void testAbout() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("timeline") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); TimelineWebServices.AboutInfo about = response.getEntity(TimelineWebServices.AboutInfo.class); Assert.assertNotNull(about); Assert.assertEquals("AMS API", about.getAbout()); }
Example 18
Source File: JMasarJerseyClient.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private ClientResponse getCall(String relativeUrl){ WebResource webResource = client.resource(jmasarServiceUrl + relativeUrl); ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class); if (response.getStatus() != 200) { String message = response.getEntity(String.class); throw new DataProviderException("Failed : HTTP error code : " + response.getStatus() + ", error message: " + message); } return response; }
Example 19
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private void buildUserList() { if (LOG.isDebugEnabled()) { LOG.debug("==> PolicyMgrUserGroupBuilder.buildUserList()"); } int totalCount = 100; int retrievedCount = 0; String relativeUrl = PM_USER_LIST_URI; while (retrievedCount < totalCount) { String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); Gson gson = new GsonBuilder().create(); if (isRangerCookieEnabled) { response = cookieBasedGetEntity(relativeUrl, retrievedCount); } else { try { clientResp = uGSyncClient.get(relativeUrl, queryParams); if (clientResp != null) { response = clientResp.getEntity(String.class); } } catch (Exception e) { LOG.error("Failed to get response, Error is : "+e.getMessage()); } } if (LOG.isDebugEnabled()) { LOG.debug("RESPONSE: [" + response + "]"); } GetXUserListResponse userList = gson.fromJson(response, GetXUserListResponse.class); totalCount = userList.getTotalCount(); if (userList.getXuserInfoList() != null) { xuserList.addAll(userList.getXuserInfoList()); retrievedCount = xuserList.size(); for (XUserInfo u : userList.getXuserInfoList()) { if (LOG.isDebugEnabled()) { LOG.debug("USER: Id:" + u.getId() + ", Name: " + u.getName() + ", Description: " + u.getDescription()); } } } } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.buildUserList()"); } }
Example 20
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private UserGroupInfo getUserGroupInfo(UserGroupInfo usergroupInfo) { UserGroupInfo ret = null; if(LOG.isDebugEnabled()){ LOG.debug("==> PolicyMgrUserGroupBuilder.getUsergroupInfo(UserGroupInfo ret, UserGroupInfo usergroupInfo)"); } String response = null; ClientResponse clientResp = null; String relativeURL = PM_ADD_USER_GROUP_INFO_URI; Gson gson = new GsonBuilder().create(); String jsonString = gson.toJson(usergroupInfo); if (LOG.isDebugEnabled()) { LOG.debug("USER GROUP MAPPING" + jsonString); } if(isRangerCookieEnabled){ response = cookieBasedUploadEntity(usergroupInfo,relativeURL); } else{ try { clientResp = uGSyncClient.post(relativeURL, null, usergroupInfo); if (clientResp != null) { response = clientResp.getEntity(String.class); } }catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } } if (LOG.isDebugEnabled()) { LOG.debug("RESPONSE: [" + response + "]"); } ret = gson.fromJson(response, UserGroupInfo.class); if ( ret != null) { XUserInfo xUserInfo = ret.getXuserInfo(); addUserToList(xUserInfo); for (XGroupInfo xGroupInfo : ret.getXgroupInfo()) { addGroupToList(xGroupInfo); addUserGroupInfoToList(xUserInfo, xGroupInfo); } } if(LOG.isDebugEnabled()){ LOG.debug("<== PolicyMgrUserGroupBuilder.getUsergroupInfo(UserGroupInfo ret, UserGroupInfo usergroupInfo)"); } return ret; }