当前位置: 首页>>代码示例>>Java>>正文


Java JsonException类代码示例

本文整理汇总了Java中javax.json.JsonException的典型用法代码示例。如果您正苦于以下问题:Java JsonException类的具体用法?Java JsonException怎么用?Java JsonException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonException类属于javax.json包,在下文中一共展示了JsonException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bodyValue

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Returns the value of the body as a structure.
 *
 * @return The value of the body as a structure.
 * @throws RemoteException If the body could not be parsed.
 * @since 2017/12/17
 */
public JsonStructure bodyValue()
	throws RemoteException
{
	Reference<JsonStructure> ref = this._jsonvalue;
	JsonStructure rv;
	
	if (ref == null || null == (rv = ref.get()))
		try
		{
			this._jsonvalue = new WeakReference<>((rv =
				Json.createReader(new StringReader(this.body)).read()));
		}
		catch (JsonException e)
		{
			throw new RemoteException("Failed to parse the body.", e);
		}
	
	return rv;
}
 
开发者ID:iopipe,项目名称:iopipe-java-core,代码行数:27,代码来源:RemoteResult.java

示例2: bodyValue

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Returns the value of the body as a structure.
 *
 * @return The value of the body as a structure.
 * @throws RemoteException If the JSON is not valid.
 * @since 2017/12/17
 */
public JsonStructure bodyValue()
	throws RemoteException
{
	Reference<JsonStructure> ref = this._jsonvalue;
	JsonStructure rv;
	
	if (ref == null || null == (rv = ref.get()))
		try
		{
			this._jsonvalue = new WeakReference<>((rv =
				Json.createReader(new StringReader(this.body)).read()));
		}
		catch (JsonException e)
		{
			throw new RemoteException("Failed to parse the body.", e);
		}
	
	return rv;
}
 
开发者ID:iopipe,项目名称:iopipe-java-core,代码行数:27,代码来源:RemoteRequest.java

示例3: doPost

import javax.json.JsonException; //导入依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

  JsonReader jsonReader = null;
  JsonObject jsonObject = null;
  try {
    jsonReader = Json.createReader(request.getReader());
    jsonObject = jsonReader.readObject();
    if (log.isDebugEnabled())
      log.debug("in->jsonObject: " + jsonObject);
    System.out.println("Json object data->"+jsonObject);
    DataCenterQueueManager.getInstance().queue.put(jsonObject);
  } catch (JsonException | IllegalStateException | InterruptedException e) {
    log.error("adding to queue", e);
  } finally {
    if (jsonReader != null)
      jsonReader.close();
  }
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:23,代码来源:DataCenterServlet.java

示例4: toMap

import javax.json.JsonException; //导入依赖的package包/类
public static Map<String, Object> toMap(JsonObject object) throws JsonException
{
   Map<String, Object> map = new HashMap<String, Object>();

   Iterator<String> keysItr = object.keySet().iterator();
   while(keysItr.hasNext()) {
      String key = keysItr.next();
      Object value = object.get(key);

      if(value instanceof JsonArray) {
         value = toList((JsonArray) value);
      }
      else if(value instanceof JsonObject) {
         value = toMap((JsonObject) value);
      }
      map.put(key, value);
   }
   return map;
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:20,代码来源:ConvertHelper.java

示例5: toList

import javax.json.JsonException; //导入依赖的package包/类
public static List<Object> toList(JsonArray array) throws JsonException
{
   List<Object> list = new ArrayList<Object>();
   for (int i = 0; i < array.size(); i++)
   {
      Object value = array.get(i);
      if (value instanceof JsonArray)
      {
         value = toList((JsonArray) value);
      }
      else if (value instanceof JsonObject)
      {
         value = toMap((JsonObject) value);
      }
      list.add(value);
   }
   return list;
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:19,代码来源:ConvertHelper.java

示例6: testUpdatingNodetype

import javax.json.JsonException; //导入依赖的package包/类
public void testUpdatingNodetype() throws IOException, JsonException {
    
    // create a node without mixin node types
    final Map <String, String> props = new HashMap <String, String> ();
    props.put("jcr:primaryType","nt:unstructured");
    final String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
    
    // assert correct nodetype
    String content = getContent(location + ".json", CONTENT_TYPE_JSON);
    JsonObject json = JsonUtil.parseObject(content);
    assertTrue("jcr:primaryType isn't set correctly", json.getString("jcr:primaryType").equals("nt:unstructured"));
    
    // change nodetype
    props.clear();
    props.put("jcr:primaryType", "sling:Folder");
    testClient.createNode(location, props);
    
    // assert correct nodetype
    content = getContent(location + ".json", CONTENT_TYPE_JSON);
    json = JsonUtil.parseObject(content);
    assertTrue("jcr:primaryType isn't set correctly", json.getString("jcr:primaryType").equals("sling:Folder"));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:23,代码来源:PostServletUpdateTest.java

示例7: verifyOrder

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Verify node order
 */
private void verifyOrder(String parentUrl, String[] names)
        throws IOException {
    // check that nodes appear in creation order in their parent's list of children
    final String content = getContent(parentUrl + ".1.json", CONTENT_TYPE_JSON);
    String expected = "";
    for (String n: names) {
        expected +=n + ",";
    }
    //assertJavascript(expected, content, TEST_SCRIPT);
    try {
        String actual = "";
        JsonObject obj = JsonUtil.parseObject(content);
        
        for (String name : obj.keySet()) {
            Object o = obj.get(name);
            if (o instanceof JsonObject) {
                actual += name + ",";
            }
        }
        assertEquals(expected, actual);
    } catch (JsonException e) {
        throw new IOException(e.toString());
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:28,代码来源:PostServletOrderTest.java

示例8: createAceOrderTestFolderWithOneAce

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Helper to create a test folder with a single ACE pre-created
 */
private void createAceOrderTestFolderWithOneAce() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
	testFolderUrl = H.createTestFolder();

	addOrUpdateAce(testFolderUrl, testUserId, true, null);

	//fetch the JSON for the acl to verify the settings.
	String getUrl = testFolderUrl + ".acl.json";

	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);
	
               JsonObject jsonObject = JsonUtil.parseObject(json);
               assertEquals(1, jsonObject.size());

               JsonObject user = jsonObject.getJsonObject(testUserId);
               assertNotNull(user);
               assertEquals(testUserId, user.getString("principal"));
               assertEquals(0, user.getInt("order"));

}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:27,代码来源:ModifyAceTest.java

示例9: addOrUpdateAce

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Helper to add or update an ace for testing
 */
private void addOrUpdateAce(String folderUrl, String principalId, boolean readGranted, String order) throws IOException, JsonException {
       String postUrl = folderUrl + ".modifyAce.html";

	//1. create an initial set of privileges
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", principalId));
	postParams.add(new NameValuePair("[email protected]:read", readGranted ? "granted" : "denied"));
	postParams.add(new NameValuePair("[email protected]:write", "denied"));
	if (order != null) {
		postParams.add(new NameValuePair("order", order));
	}
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:19,代码来源:ModifyAceTest.java

示例10: testModifyAceResponseAsJSON

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Test for SLING-1677
 */
@Test 
public void testModifyAceResponseAsJSON() throws IOException, JsonException {
	testUserId = H.createTestUser();
	
	testFolderUrl = H.createTestFolder();
	
       String postUrl = testFolderUrl + ".modifyAce.json";

	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair("principalId", testUserId));
	postParams.add(new NameValuePair("[email protected]:read", "granted"));
	postParams.add(new NameValuePair("[email protected]:write", "denied"));
	postParams.add(new NameValuePair("[email protected]:modifyAccessControl", "bogus")); //invalid value should be ignored.
	
	Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

       //make sure the json response can be parsed as a JSON object
       JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:25,代码来源:ModifyAceTest.java

示例11: testRemoveAce

import javax.json.JsonException; //导入依赖的package包/类
public void testRemoveAce() throws IOException, JsonException {
	String folderUrl = createFolderWithAces(false);
	
	//remove the ace for the testUser principal
	String postUrl = folderUrl + ".deleteAce.html"; 
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":applyTo", testUserId));
       Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

	//fetch the JSON for the acl to verify the settings.
	String getUrl = folderUrl + ".acl.json";

	String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);

	JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
	assertEquals(0, jsonObject.size());
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:21,代码来源:RemoveAcesTest.java

示例12: testRemoveAces

import javax.json.JsonException; //导入依赖的package包/类
public void testRemoveAces() throws IOException, JsonException {
	String folderUrl = createFolderWithAces(true);
	
	//remove the ace for the testUser principal
	String postUrl = folderUrl + ".deleteAce.html"; 
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":applyTo", testUserId));
	postParams.add(new NameValuePair(":applyTo", testGroupId));
       Credentials creds = new UsernamePasswordCredentials("admin", "admin");
	assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

	//fetch the JSON for the acl to verify the settings.
	String getUrl = folderUrl + ".acl.json";

	String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
	assertNotNull(json);

	JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
	assertEquals(0, jsonObject.size());
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:22,代码来源:RemoveAcesTest.java

示例13: testRemoveAcesResponseAsJSON

import javax.json.JsonException; //导入依赖的package包/类
/**
 * Test for SLING-1677
 */
public void testRemoveAcesResponseAsJSON() throws IOException, JsonException {
	String folderUrl = createFolderWithAces(true);
	
	//remove the ace for the testUser principal
	String postUrl = folderUrl + ".deleteAce.json"; 
	List<NameValuePair> postParams = new ArrayList<NameValuePair>();
	postParams.add(new NameValuePair(":applyTo", testUserId));
	postParams.add(new NameValuePair(":applyTo", testGroupId));
       Credentials creds = new UsernamePasswordCredentials("admin", "admin");
       String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);

       //make sure the json response can be parsed as a JSON object
       JsonObject jsonObject = JsonUtil.parseObject(json);
	assertNotNull(jsonObject);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:19,代码来源:RemoveAcesTest.java

示例14: createVersionableNode

import javax.json.JsonException; //导入依赖的package包/类
private String createVersionableNode() throws IOException, JsonException {
    params.put(":checkinNewVersionableNodes", "true");
    params.put("prop", "v1");
    final String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, params);
    testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, params);

    params.put("prop", "v2");
    params.put(":autoCheckout", "true");
    testClient.post(location, params);

    params.put("prop", "v3");
    testClient.post(location, params);

    final String content = getContent(location + ".txt", CONTENT_TYPE_PLAIN);
    assertTrue("Node (" + location + ") should be checked in.", content.contains("jcr:isCheckedOut: false"));
    assertEquals("v3", getProp(location + ".json"));
    return location;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:19,代码来源:VersionParameterTest.java

示例15: installAndUpgradeBundleManyTimes

import javax.json.JsonException; //导入依赖的package包/类
@Test
public void installAndUpgradeBundleManyTimes() throws IOException, JsonException {
    final String bsn = BASE_BSN + "_upgradetest";
    int i = 0;
    try {
        for(i=0; i < HOW_MANY; i++) {
            final String version = "42.0." + i;
            installAndCheckBundle(bsn, i, version);
        }
        log.info("Test bundle successfully installed, upgraded and started {} times", HOW_MANY);
    } finally {
        log.info("installAndUpgradeBundleManyTimes exiting with i={}", i);
        // we should wait until the OSGi installer has removed everything
        H.getTestClient().delete(toDelete);
        waitNoBundles(bsn);
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:18,代码来源:InstallManyBundlesTest.java


注:本文中的javax.json.JsonException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。