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


Java JSONObject.getString方法代碼示例

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


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

示例1: testJobIdInvalidDefault

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

  try {
    r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
        .path("job_foo").get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, 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");
    verifyJobIdInvalid(message, type, classname);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:TestHsWebServicesJobs.java

示例2: loadFilters

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
private void loadFilters() {
	JSONObject jsonDocument = getObject().getJSONObject();
	JSONObject filters = CouchKey.filters.JSONObject(jsonDocument);
	
	if (filters != null) {
		if (filters.length() > 0) {
			addChild(fFilters);
		}
		
		for (Iterator<String> i = GenericUtils.cast(filters.keys()); i.hasNext(); ) {
			String key = i.next();
			
			try {
				FilterObject filter = new FilterObject(key, filters.getString(key));
				fFilters.addChild(new DesignDocumentFilterTreeObject(viewer, filter));
			} catch (Exception e) {
				Engine.logBeans.warn("[DesignDocument] filter named '" + key + "' is null; skipping...");
			}
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:22,代碼來源:DesignDocumentTreeObject.java

示例3: testJobsQueryStateInvalid

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

  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("state", "InvalidState")
      .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
      .checkStringContains(
          "exception message",
          "org.apache.hadoop.mapreduce.v2.api.records.JobState.InvalidState",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "IllegalArgumentException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "java.lang.IllegalArgumentException", classname);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestHsWebServicesJobsQuery.java

示例4: testJobsQueryStartTimeEndInvalidformat

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobsQueryStartTimeEndInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("startedTimeEnd", "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

示例5: testNonexistNodeDefault

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testNonexistNodeDefault() throws JSONException, Exception {
  rm.registerNode("h1:1234", 5120);
  rm.registerNode("h2:1235", 5121);
  WebResource r = resource();
  try {
    r.path("ws").path("v1").path("cluster").path("nodes")
        .path("node_invalid:99").get(JSONObject.class);

    fail("should have thrown exception on non-existent nodeid");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, 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");
    verifyNonexistNodeException(message, type, classname);
  } finally {
    rm.stop();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:TestRMWebServicesNodes.java

示例6: verifyAMJobConf

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
public void verifyAMJobConf(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,代碼來源:TestAMWebServicesJobConf.java

示例7: testJobsQueryFinishTimeInvalidformat

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testJobsQueryFinishTimeInvalidformat() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("finishedTimeBegin", "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

示例8: testJobIdInvalid

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

  try {
    r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
        .path("job_foo").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, 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");
    verifyJobIdInvalid(message, type, classname);

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

示例9: testInvalidNode

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testInvalidNode() throws JSONException, Exception {
  rm.registerNode("h1:1234", 5120);
  rm.registerNode("h2:1235", 5121);

  WebResource r = resource();
  try {
    r.path("ws").path("v1").path("cluster").path("nodes")
        .path("node_invalid_foo").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);

    fail("should have thrown exception on non-existent nodeid");
  } 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",
        "Invalid NodeId \\[node_invalid_foo\\]. Expected host:port", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "IllegalArgumentException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "java.lang.IllegalArgumentException", classname);
  } finally {
    rm.stop();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:34,代碼來源:TestRMWebServicesNodes.java

示例10: add

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Override
public IDesignTreeObject add(Object object, boolean bChangeName) {
	if (object instanceof JsonData) {
		JsonData jsonData = (JsonData)object;
		Class<? extends TreeParent> c = jsonData.getOwnerClass();
		if (c.equals(DesignDocumentFunctionTreeObject.class)) {
			JSONObject jsonFunction = jsonData.getData();
			try {
				String funcName = jsonFunction.getString("name");
				String funcValue = jsonFunction.getString("value");
				FunctionObject fo = getObject().createFunction(funcName, funcValue);
				if (fo != null) {
					return addFunction(newFunction(fo));
				}
			} catch (Exception e) {
			}
		}
		else if (c.equals(DesignDocumentViewTreeObject.class)) {
			return getParentDesignTreeObject().add(object, bChangeName);
		}
	}
	else if (object instanceof DesignDocumentFunctionTreeObject) {
		return addFunction((DesignDocumentFunctionTreeObject)object);
	}
	else if (object instanceof DesignDocumentViewTreeObject) {
		return getParentDesignTreeObject().add(object, bChangeName);
	}
	return null;
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:30,代碼來源:DesignDocumentViewTreeObject.java

示例11: testJobIdInvalidBogus

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

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("bogusfoo")
        .get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, 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: JobId string : bogusfoo is not properly formed",
            message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:TestAMWebServicesJobs.java

示例12: testInvalidAppAttempts

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testInvalidAppAttempts() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .path("application_invalid_12").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid appid");
  } 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",
        "For input string: \"invalid\"", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NumberFormatException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "java.lang.NumberFormatException", classname);

  } finally {
    rm.stop();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:36,代碼來源:TestRMWebServicesApps.java

示例13: testNonexistApp

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testNonexistApp() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB, "testwordcount", "user1");
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .path("application_00000_0099").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid appid");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();

    assertEquals(Status.NOT_FOUND, 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: app with id: application_00000_0099 not found",
        message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  } finally {
    rm.stop();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:37,代碼來源:TestRMWebServicesApps.java

示例14: testNodeSingleAppsMissing

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

  try {
    r.path("ws").path("v1").path("node").path("apps")
        .path("application_1234_0009").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, 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: app with id application_1234_0009 not found",
        message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:TestNMWebServicesApps.java

示例15: testSingleContainerInvalid2

import org.codehaus.jettison.json.JSONObject; //導入方法依賴的package包/類
@Test
public void testSingleContainerInvalid2() 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);
  try {
    r.path("ws").path("v1").path("node").path("containers")
        .path("container_1234_0001").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } 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: invalid container id, container_1234_0001",
        message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "BadRequestException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:34,代碼來源:TestNMWebServicesContainers.java


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