當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.getJSONObject方法代碼示例

本文整理匯總了Java中org.codehaus.jettison.json.JSONObject.getJSONObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.getJSONObject方法的具體用法?Java JSONObject.getJSONObject怎麽用?Java JSONObject.getJSONObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jettison.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.getJSONObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doComputeContents

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
protected synchronized void doComputeContents() {
	try {
		pageImports.clear();
		pageFunctions.clear();
		JSONObject newComputedContent = initJsonComputed();
		
		JSONObject jsonScripts = newComputedContent.getJSONObject("scripts");
		computeScripts(jsonScripts);
		
		newComputedContent.put("style", computeStyle());
		newComputedContent.put("template", computeTemplate());
		
		computedContents = newComputedContent;
		
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:19,代碼來源:PageComponent.java

示例2: testJobId

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobId() 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).accept(MediaType.APPLICATION_JSON)
        .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("job");
    verifyAMJob(info, jobsMap.get(id));
  }

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAMWebServicesJobs.java

示例3: testMultipleContainers

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testMultipleContainers() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, 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")
        .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 containers = json.getJSONObject("containers");
  assertEquals("incorrect number of elements", 1, containers.length());
  JSONArray array = containers.getJSONArray("container");
  assertEquals("incorrect number of elements", 5, array.length());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:TestAHSWebServices.java

示例4: testJobsQueryLimitInvalid

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobsQueryLimitInvalid() throws JSONException, Exception {
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("limit", "-1")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils.checkStringMatch("exception message",
      "java.lang.Exception: limit value must be greater then 0", message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:TestHsWebServicesJobsQuery.java

示例5: testTasksQueryReduce

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testTasksQueryReduce() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    String type = "r";
    ClientResponse response = r.path("ws").path("v1").path("mapreduce")
        .path("jobs").path(jobId).path("tasks").queryParam("type", type)
        .accept(MediaType.APPLICATION_JSON).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 tasks = json.getJSONObject("tasks");
    JSONArray arr = tasks.getJSONArray("task");
    assertEquals("incorrect number of elements", 1, arr.length());
    verifyAMTask(arr, jobsMap.get(id), type);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestAMWebServicesTasks.java

示例6: verifyHsTaskAttempts

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public void verifyHsTaskAttempts(JSONObject json, Task task)
    throws JSONException {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject attempts = json.getJSONObject("taskAttempts");
  assertEquals("incorrect number of elements", 1, json.length());
  JSONArray arr = attempts.getJSONArray("taskAttempt");
  for (TaskAttempt att : task.getAttempts().values()) {
    TaskAttemptId id = att.getID();
    String attid = MRApps.toString(id);
    Boolean found = false;

    for (int i = 0; i < arr.length(); i++) {
      JSONObject info = arr.getJSONObject(i);
      if (attid.matches(info.getString("id"))) {
        found = true;
        verifyHsTaskAttempt(info, att, task.getType());
      }
    }
    assertTrue("task attempt with id: " + attid
        + " not in web service output", found);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestHsWebServicesAttempts.java

示例7: testJobAttempts

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobAttempts() 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("history")
        .path("mapreduce").path("jobs").path(jobId).path("jobattempts")
        .accept(MediaType.APPLICATION_JSON).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("jobAttempts");
    verifyHsJobAttempts(info, appContext.getJob(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestHsWebServicesJobs.java

示例8: verifyClusterSchedulerFifo

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public void verifyClusterSchedulerFifo(JSONObject json) throws JSONException,
    Exception {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject info = json.getJSONObject("scheduler");
  assertEquals("incorrect number of elements", 1, info.length());
  info = info.getJSONObject("schedulerInfo");
  assertEquals("incorrect number of elements", 11, info.length());

  verifyClusterSchedulerFifoGeneric(info.getString("type"),
      info.getString("qstate"), (float) info.getDouble("capacity"),
      (float) info.getDouble("usedCapacity"),
      info.getInt("minQueueMemoryCapacity"),
      info.getInt("maxQueueMemoryCapacity"), info.getInt("numNodes"),
      info.getInt("usedNodeCapacity"), info.getInt("availNodeCapacity"),
      info.getInt("totalNodeCapacity"), info.getInt("numContainers"));

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestRMWebServices.java

示例9: testJobIdSlash

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobIdSlash() 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("history")
        .path("mapreduce").path("jobs").path(jobId + "/")
        .accept(MediaType.APPLICATION_JSON).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("job");

    VerifyJobsUtils.verifyHsJob(info, appContext.getJob(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestHsWebServicesJobs.java

示例10: verifyNodeInfo

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public void verifyNodeInfo(JSONObject json) throws JSONException, Exception {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject info = json.getJSONObject("nodeInfo");
  assertEquals("incorrect number of elements", 17, info.length());
  verifyNodeInfoGeneric(info.getString("id"), info.getString("healthReport"),
      info.getLong("totalVmemAllocatedContainersMB"),
      info.getLong("totalPmemAllocatedContainersMB"),
      info.getLong("totalVCoresAllocatedContainers"),
      info.getLong("totalGCoresAllocatedContainers"),
      info.getBoolean("vmemCheckEnabled"),
      info.getBoolean("pmemCheckEnabled"),
      info.getLong("lastNodeUpdateTime"), info.getBoolean("nodeHealthy"),
      info.getString("nodeHostName"), info.getString("hadoopVersionBuiltOn"),
      info.getString("hadoopBuildVersion"), info.getString("hadoopVersion"),
      info.getString("nodeManagerVersionBuiltOn"),
      info.getString("nodeManagerBuildVersion"),
      info.getString("nodeManagerVersion"));

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestNMWebServices.java

示例11: testJobsQueryFinishTimeBeginNegative

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobsQueryFinishTimeBeginNegative() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("finishedTimeBegin", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject msg = response.getEntity(JSONObject.class);
  JSONObject exception = msg.getJSONObject("RemoteException");
  assertEquals("incorrect number of elements", 3, exception.length());
  String message = exception.getString("message");
  String type = exception.getString("exception");
  String classname = exception.getString("javaClassName");
  WebServicesTestUtils.checkStringMatch("exception message",
      "java.lang.Exception: finishedTimeBegin must be greater than 0",
      message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TestHsWebServicesJobsQuery.java

示例12: testNodesQueryNew

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testNodesQueryNew() throws JSONException, Exception {
  WebResource r = resource();
  MockNM nm1 = rm.registerNode("h1:1234", 5120);
  MockNM nm2 = rm.registerNode("h2:1235", 5121);
  rm.sendNodeStarted(nm1);
  rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
  rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW);

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("nodes").queryParam("states", NodeState.NEW.toString())
      .accept(MediaType.APPLICATION_JSON).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 nodes = json.getJSONObject("nodes");
  assertEquals("incorrect number of elements", 1, nodes.length());
  JSONArray nodeArray = nodes.getJSONArray("node");
  assertEquals("incorrect number of elements", 1, nodeArray.length());
  JSONObject info = nodeArray.getJSONObject(0);

  verifyNodeInfo(info, nm2);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TestRMWebServicesNodes.java

示例13: testTaskAttemptIdDefault

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testTaskAttemptIdDefault() 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());

      for (TaskAttempt att : task.getAttempts().values()) {
        TaskAttemptId attemptid = att.getID();
        String attid = MRApps.toString(attemptid);

        ClientResponse response = r.path("ws").path("v1").path("mapreduce")
            .path("jobs").path(jobId).path("tasks").path(tid)
            .path("attempts").path(attid).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("taskAttempt");
        verifyAMTaskAttempt(info, att, task.getType());
      }
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:TestAMWebServicesAttempts.java

示例14: testTaskAttemptIdDefault

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testTaskAttemptIdDefault() 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());

      for (TaskAttempt att : task.getAttempts().values()) {
        TaskAttemptId attemptid = att.getID();
        String attid = MRApps.toString(attemptid);

        ClientResponse response = r.path("ws").path("v1").path("history")
            .path("mapreduce").path("jobs").path(jobId).path("tasks")
            .path(tid).path("attempts").path(attid).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("taskAttempt");
        verifyHsTaskAttempt(info, att, task.getType());
      }
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:TestHsWebServicesAttempts.java

示例15: testTasksQueryInvalid

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testTasksQueryInvalid() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    // tasktype must be exactly either "m" or "r"
    String tasktype = "reduce";

    try {
      r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId)
          .path("tasks").queryParam("type", tasktype)
          .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
      fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
      ClientResponse response = ue.getResponse();
      assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject msg = response.getEntity(JSONObject.class);
      JSONObject exception = msg.getJSONObject("RemoteException");
      assertEquals("incorrect number of elements", 3, exception.length());
      String message = exception.getString("message");
      String type = exception.getString("exception");
      String classname = exception.getString("javaClassName");
      WebServicesTestUtils.checkStringMatch("exception message",
          "java.lang.Exception: tasktype must be either m or r", message);
      WebServicesTestUtils.checkStringMatch("exception type",
          "BadRequestException", type);
      WebServicesTestUtils.checkStringMatch("exception classname",
          "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:34,代碼來源:TestAMWebServicesTasks.java


注:本文中的org.codehaus.jettison.json.JSONObject.getJSONObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。