当前位置: 首页>>代码示例>>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;未经允许,请勿转载。