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


Java JSONException類代碼示例

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


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

示例1: testTaskAttemptsSlash

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@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("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);
      verifyAMTaskAttempts(json, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAMWebServicesAttempts.java

示例2: testJobCountersDefault

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@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));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestAMWebServicesJobs.java

示例3: testTaskAttemptsDefault

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@Test
public void testTaskAttemptsDefault() 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("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("attempts")
          .get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyAMTaskAttempts(json, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAMWebServicesAttempts.java

示例4: verifyAppStateJson

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
protected static void verifyAppStateJson(ClientResponse response,
    RMAppState... states) throws JSONException {

  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  String responseState = json.getString("state");
  boolean valid = false;
  for (RMAppState state : states) {
    if (state.toString().equals(responseState)) {
      valid = true;
    }
  }
  String msg = "app state incorrect, got " + responseState;
  assertTrue(msg, valid);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestRMWebServicesAppsModification.java

示例5: getEvents

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
public Map<String, IonEvent> getEvents() {
	Map<String, IonEvent> events = new HashMap<String, IonEvent>();
	try {
		JSONObject jsonEvents = jsonBean.getJSONObject(Key.events.name());
		@SuppressWarnings("unchecked")
		Iterator<String> it = jsonEvents.keys();
		while (it.hasNext()) {
			String pkey = it.next();
			if (!pkey.isEmpty()) {
				Object ob = jsonEvents.get(pkey);
				if (ob instanceof JSONObject) {
					IonEvent event = new IonEvent((JSONObject)ob);
					event.setName(pkey);
					events.put(event.getName(), event);
				}
			}
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return events;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:23,代碼來源:IonBean.java

示例6: verifyClusterSchedulerFifo

import org.codehaus.jettison.json.JSONException; //導入依賴的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

示例7: testAppsHelper

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
public void testAppsHelper(String path, RMApp app, String media)
    throws JSONException, Exception {
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path(path).accept(media).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 apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 1, array.length());
  verifyAppInfo(array.getJSONObject(0), app);

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

示例8: testNodeContainerXML

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@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());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:TestNMWebServicesContainers.java

示例9: findExecutors

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
private Collection<JSONObject> findExecutors(final JSONArray frameworks, final String appName) throws JSONException {
    List<JSONObject> result = Lists.newArrayList();
    Optional<String> frameworkIDOptional = frameworkIDService.fetch();
    String frameworkID;
    if (frameworkIDOptional.isPresent()) {
        frameworkID = frameworkIDOptional.get();
    } else {
        return result;
    }
    for (int i = 0; i < frameworks.length(); i++) {
        JSONObject framework = frameworks.getJSONObject(i);
        if (!framework.getString("id").equals(frameworkID)) {
            continue;
        }
        JSONArray executors = framework.getJSONArray("executors");
        for (int j = 0; j < executors.length(); j++) {
            JSONObject executor = executors.getJSONObject(j);
            if (null == appName || appName.equals(getExecutorId(executor).split("@[email protected]")[0])) {
                result.add(executor);
            }
        }
    }
    return result;
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:25,代碼來源:MesosStateService.java

示例10: testJobsQueryStartTimeInvalidformat

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@Test
public void testJobsQueryStartTimeInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("startedTimeBegin", "efsd")
      .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: Invalid number format: For input string: \"efsd\"",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:TestHsWebServicesJobsQuery.java

示例11: testJobCountersSlash

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@Test
public void testJobCountersSlash() 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/")
        .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("jobCounters");
    verifyAMJobCounters(info, jobsMap.get(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestAMWebServicesJobs.java

示例12: testJobsQueryStartTimeEndNegative

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@Test
public void testJobsQueryStartTimeEndNegative() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("startedTimeEnd", 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: startedTimeEnd 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,代碼行數:24,代碼來源:TestHsWebServicesJobsQuery.java

示例13: testAppsXML

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@Test
public void testAppsXML() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  RMApp app1 = rm.submitApp(CONTAINER_MB, "testwordcount", "user1");
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps").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 nodesApps = dom.getElementsByTagName("apps");
  assertEquals("incorrect number of elements", 1, nodesApps.getLength());
  NodeList nodes = dom.getElementsByTagName("app");
  assertEquals("incorrect number of elements", 1, nodes.getLength());
  verifyAppsXML(nodes, app1);
  rm.stop();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TestRMWebServicesApps.java

示例14: testTaskIdCountersDefault

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
@Test
public void testTaskIdCountersDefault() 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("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("jobTaskCounters");
      verifyHsJobTaskCounters(info, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:TestHsWebServicesTasks.java

示例15: verifyHsJobConf

import org.codehaus.jettison.json.JSONException; //導入依賴的package包/類
public void verifyHsJobConf(JSONObject info, Job job) throws JSONException {

    assertEquals("incorrect number of elements", 2, info.length());

    WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(),
        info.getString("path"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray properties = info.getJSONArray("property");
    for (int i = 0; i < properties.length(); i++) {
      JSONObject prop = properties.getJSONObject(i);
      String name = prop.getString("name");
      String value = prop.getString("value");
      assertTrue("name not set", (name != null && !name.isEmpty()));
      assertTrue("value not set", (value != null && !value.isEmpty()));
    }
  }
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestHsWebServicesJobConf.java


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