Java 类javax.json.JsonException 实例源码

项目:iopipe-java-core    文件:RemoteResult.java   
/**
 * 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;
}
项目:iopipe-java-core    文件:RemoteRequest.java   
/**
 * 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;
}
项目:KITE    文件:DataCenterServlet.java   
/**
 * @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();
  }
}
项目:springboot-addon    文件:ConvertHelper.java   
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;
}
项目:springboot-addon    文件:ConvertHelper.java   
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;
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:PostServletUpdateTest.java   
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"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:PostServletOrderTest.java   
/**
 * 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());
    }
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:ModifyAceTest.java   
/**
 * 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"));

}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:RemoveAcesTest.java   
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());
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:RemoveAcesTest.java   
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());
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:RemoveAcesTest.java   
/**
 * 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);
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:VersionParameterTest.java   
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;
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:InstallManyBundlesTest.java   
@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);
    }
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:JsonUtil.java   
public static Object unbox(JsonValue value, Function<JsonStructure, Object> convert) throws JsonException {
    switch (value.getValueType()) {
        case ARRAY:
        case OBJECT:
            return convert.apply((JsonStructure) value);
        case FALSE:
            return Boolean.FALSE;
        case TRUE:
            return Boolean.TRUE;
        case NULL:
            return null;
        case NUMBER:
            JsonNumber number = (JsonNumber) value;
            return number.isIntegral() ? number.longValue() : number.doubleValue();
        case STRING:
            return ((JsonString) value).getString();
        default:
            throw new JsonException("Unknow value type");
    }
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:RedirectTest.java   
/** test JSON result for .json requests with sling:target */
public void testRedirectJson() throws JsonException, IOException {
    // create a sling:redirect node without a target
    Map<String, String> props = new HashMap<String, String>();
    props.put("sling:resourceType", "sling:redirect");
    props.put("sling:target", "/index.html");
    String redirNodeUrl = testClient.createNode(postUrl, props);

    // get the created node without following redirects
    final GetMethod get = new GetMethod(redirNodeUrl + ".json");
    get.setFollowRedirects(false);
    final int status = httpClient.executeMethod(get);

    // expect 200 OK with the JSON data
    assertEquals(200, status);
    assertTrue(get.getResponseHeader("Content-Type").getValue().startsWith(CONTENT_TYPE_JSON));

    // the json data
    String jsonString = get.getResponseBodyAsString();
    JsonObject json = JsonUtil.parseObject(jsonString);

    assertEquals("sling:redirect", json.getString("sling:resourceType"));
    assertEquals("/index.html", json.getString("sling:target"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:RedirectTest.java   
/** test JSON result for .json requests with sling:target */
public void testRedirectJson2() throws JsonException, IOException {
    // create a sling:redirect node without a target
    Map<String, String> props = new HashMap<String, String>();
    props.put("sling:resourceType", "sling:redirect");
    String redirNodeUrl = testClient.createNode(postUrl, props);

    // get the created node without following redirects
    final GetMethod get = new GetMethod(redirNodeUrl + ".json");
    get.setFollowRedirects(false);
    final int status = httpClient.executeMethod(get);

    // expect 200 OK with the JSON data
    assertEquals(200, status);
    assertTrue(get.getResponseHeader("Content-Type").getValue().startsWith(CONTENT_TYPE_JSON));

    // the json data
    String jsonString = get.getResponseBodyAsString();
    JsonObject json = JsonUtil.parseObject(jsonString);

    assertEquals("sling:redirect", json.getString("sling:resourceType"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:CreateUserTest.java   
/**
 * Test for SLING-1677
 */
@Test 
public void testCreateUserResponseAsJSON() throws IOException, JsonException {
       String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.json";

    testUserId = "testUser" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testUserId));
    postParams.add(new NameValuePair("marker", testUserId));
    postParams.add(new NameValuePair("pwd", "testPwd"));
    postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
    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 jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UpdateUserTest.java   
/**
 * Test for SLING-1677
 */
@Test 
public void testUpdateUserResponseAsJSON() throws IOException, JsonException {
    testUserId = H.createTestUser();

       String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.json";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("displayName", "My Updated Test User"));
    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
    Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
    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 jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UserPrivilegesInfoTest.java   
/**
 * Checks whether the current user has been granted privileges
 * to add a new user.
 */
@Test 
public void testCanAddUser() throws JsonException, IOException {
    testUserId = H.createTestUser();

    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);

    assertEquals(false, jsonObj.getBoolean("canAddUser"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UserPrivilegesInfoTest.java   
/**
 * Checks whether the current user has been granted privileges
 * to add a new group.
 */
@Test 
public void testCanAddGroup() throws IOException, JsonException {
    testUserId = H.createTestUser();

    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);

    assertEquals(false, jsonObj.getBoolean("canAddGroup"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UserPrivilegesInfoTest.java   
/**
 * Checks whether the current user has been granted privileges
 * to update the properties of the specified group.
 */
@Test 
public void testCanUpdateGroupProperties() throws IOException, JsonException {
    testGroupId = H.createTestGroup();
    testUserId = H.createTestUser();

    //1. Verify non admin user can not update group properties
    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);

    //normal user can not update group properties
    assertEquals(false, jsonObj.getBoolean("canUpdateProperties"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UserPrivilegesInfoTest.java   
/**
 * Checks whether the current user has been granted privileges
 * to remove the specified group.
 */
@Test 
public void testCanRemoveGroup() throws IOException, JsonException {
    testGroupId = H.createTestGroup();
    testUserId = H.createTestUser();

    //1. Verify non admin user can not remove group
    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);

    //normal user can not remove group
    assertEquals(false, jsonObj.getBoolean("canRemove"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UserPrivilegesInfoTest.java   
/**
 * Checks whether the current user has been granted privileges
 * to update the membership of the specified group.
 */
@Test 
public void testCanUpdateGroupMembers() throws IOException, JsonException {
    testGroupId = H.createTestGroup();
    testUserId = H.createTestUser();

    //1. Verify non admin user can not update group membership
    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".privileges-info.json";

    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");

    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);

    //normal user can not remove group
    assertEquals(false, jsonObj.getBoolean("canUpdateGroupMembers"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:CreateGroupTest.java   
public void testCreateGroup() throws IOException, JsonException {
       String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";

    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    postParams.add(new NameValuePair("marker", testGroupId));
    assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);

    //fetch the group profile json to verify the settings
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals(testGroupId, jsonObj.getString("marker"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:CreateGroupTest.java   
public void testCreateGroupWithExtraProperties() throws IOException, JsonException {
       String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";

    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    postParams.add(new NameValuePair("marker", testGroupId));
    postParams.add(new NameValuePair("displayName", "My Test Group"));
    postParams.add(new NameValuePair("url", "http://www.apache.org"));
    assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);

    //fetch the group profile json to verify the settings
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals(testGroupId, jsonObj.getString("marker"));
    assertEquals("My Test Group", jsonObj.getString("displayName"));
    assertEquals("http://www.apache.org", jsonObj.getString("url"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UpdateGroupTest.java   
public void testUpdateGroup() throws IOException, JsonException {
    testGroupId = createTestGroup();

       String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("displayName", "My Updated Test Group"));
    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));

    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);

    //fetch the user profile json to verify the settings
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals("My Updated Test Group", jsonObj.getString("displayName"));
    assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:UpdateGroupTest.java   
/**
 * Test for SLING-1677
 */
public void testUpdateGroupResponseAsJSON() throws IOException, JsonException {
    testGroupId = createTestGroup();

       String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.json";

    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("displayName", "My Updated Test Group"));
    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));

    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 jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
项目:sling-org-apache-sling-launchpad-integration-tests    文件:RemoveAuthorizablesTest.java   
/**
 * Test for SLING-1677
 */
public void testRemoveAuthorizablesResponseAsJSON() throws IOException, JsonException {
    String userId = createTestUser();
    String groupId = createTestGroup();

       Credentials creds = new UsernamePasswordCredentials("admin", "admin");

    String postUrl = HTTP_BASE_URL + "/system/userManager.delete.json";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":applyTo", "group/" + groupId));
    postParams.add(new NameValuePair(":applyTo", "user/" + userId));
    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 jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
项目:PrOfESSOS    文件:TestStepLogger.java   
private String formatBody(String contentType, String body) {
    if (body != null && contentType != null) {
        if (contentType.startsWith("application/json")) {
            try {
                JsonStructure json = Json.createReader(new StringReader(body)).read();
                StringWriter w = new StringWriter();
                HashMap<String, Object> p = new HashMap<>();
                p.put(JsonGenerator.PRETTY_PRINTING, true);
                Json.createWriterFactory(p).createWriter(w).write(json);
                return w.toString();
            } catch (JsonException ex) {
                return body;
            }
        } else {
            return body;
        }
    } else {
        return null;
    }
}
项目:cookjson    文件:JsonPathProvider.java   
@Override
public Object parse (String jsonString) throws InvalidJsonException
{
    try
    {
        Reader r = new StringReader (jsonString);
        TextJsonParser p = new TextJsonParser (r);
        p.next ();  // read the very first token to get initiated.
        JsonValue v = p.getValue ();
        p.close ();
        return v;
    }
    catch (JsonException ex)
    {
        throw new InvalidJsonException (ex);
    }
}
项目:polygene-java    文件:MigrationService.java   
@Override
public JsonObject removeProperty( MigrationContext context, JsonObject state, String name )
    throws JsonException
{
    JsonObject valueState = state.getJsonObject( JSONKeys.VALUE );
    if( valueState.containsKey( name ) )
    {
        valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build();
        JsonObject migratedState = jsonFactories
            .cloneBuilderExclude( state, JSONKeys.VALUE )
            .add( JSONKeys.VALUE, valueState )
            .build();
        context.markAsChanged();
        for( MigrationEvents migrationEvent : migrationEvents )
        {
            migrationEvent.propertyRemoved( state.getString( JSONKeys.IDENTITY ), name );
        }
        return migratedState;
    }
    else
    {
        context.addFailure( "Remove property " + name );
        return state;
    }
}
项目:polygene-java    文件:MigrationService.java   
@Override
public JsonObject removeAssociation( MigrationContext context, JsonObject state, String name )
    throws JsonException
{
    JsonObject valueState = state.getJsonObject( JSONKeys.VALUE );
    if( valueState.containsKey( name ) )
    {
        valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build();
        JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE )
                                                .add( JSONKeys.VALUE, valueState )
                                                .build();
        context.markAsChanged();
        for( MigrationEvents migrationEvent : migrationEvents )
        {
            migrationEvent.associationRemoved( state.getString( JSONKeys.IDENTITY ), name );
        }
        return migratedState;
    }
    else
    {
        context.addFailure( "Remove association " + name );
        return state;
    }
}
项目:polygene-java    文件:MigrationService.java   
@Override
public JsonObject removeManyAssociation( MigrationContext context, JsonObject state, String name )
    throws JsonException
{
    JsonObject valueState = state.getJsonObject( JSONKeys.VALUE );
    if( valueState.containsKey( name ) )
    {
        valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build();
        JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE )
                                                .add( JSONKeys.VALUE, valueState )
                                                .build();
        context.markAsChanged();
        for( MigrationEvents migrationEvent : migrationEvents )
        {
            migrationEvent.manyAssociationRemoved( state.getString( JSONKeys.IDENTITY ), name );
        }
        return migratedState;
    }
    else
    {
        context.addFailure( "Remove many-association " + name );
        return state;
    }
}
项目:polygene-java    文件:MigrationService.java   
@Override
public JsonObject removeNamedAssociation( MigrationContext context, JsonObject state, String name )
    throws JsonException
{
    JsonObject valueState = state.getJsonObject( JSONKeys.VALUE );
    if( !valueState.containsKey( name ) )
    {
        valueState = jsonFactories.cloneBuilderExclude( valueState, name ).build();
        JsonObject migratedState = jsonFactories.cloneBuilderExclude( state, JSONKeys.VALUE )
                                                .add( JSONKeys.VALUE, valueState )
                                                .build();
        context.markAsChanged();
        for( MigrationEvents migrationEvent : migrationEvents )
        {
            migrationEvent.namedAssociationRemoved( state.getString( JSONKeys.IDENTITY ), name );
        }
        return migratedState;
    }
    else
    {
        context.addFailure( "Remove named-association " + name );
        return state;
    }
}
项目:polygene-java    文件:MigrationService.java   
@Override
public JsonObject changeEntityType( MigrationContext context, JsonObject state,
                                    String fromType, String toType )
    throws JsonException
{
    String currentType = state.getString( JSONKeys.TYPE );
    if( fromType.equals( currentType ) )
    {
        JsonObject migratedState = jsonFactories.cloneBuilder( state )
                                                .add( JSONKeys.TYPE, toType )
                                                .build();
        for( MigrationEvents migrationEvent : migrationEvents )
        {
            migrationEvent.entityTypeChanged( state.getString( JSONKeys.IDENTITY ), toType );
        }
        return migratedState;
    }
    else
    {
        context.addFailure( "Change entity type from " + fromType + " to " + toType );
        return state;
    }
}
项目:polygene-java    文件:JSONManyAssociationState.java   
@Override
public boolean add( int idx, EntityReference entityReference )
{
    try
    {
        if( indexOfReference( entityReference.identity().toString() ) != -1 )
        {
            return false;
        }
        entityState.stateCloneAddManyAssociation( idx, stateName, entityReference );
        entityState.markUpdated();
        return true;
    }
    catch( JsonException e )
    {
        throw new EntityStoreException( e );
    }
}
项目:polygene-java    文件:JSONNamedAssociationState.java   
@Override
public boolean put( String name, EntityReference entityReference )
{
    try
    {
        if( containsName( name )
            && entityReference.identity().toString().equals( getReferences().getString( name ) ) )
        {
            return false;
        }
        entityState.stateCloneAddNamedAssociation( stateName, name, entityReference );
        entityState.markUpdated();
        return true;
    }
    catch( JsonException ex )
    {
        throw new EntityStoreException( ex );
    }
}