Package com.amazonaws.util.json

Examples of com.amazonaws.util.json.JSONArray


            if (Arrays.asList(JSONObject.getNames(jPolicy)).contains(JsonDocumentFields.POLICY_ID)) {
                policy.setId(jPolicy.getString(JsonDocumentFields.POLICY_ID));
            }

            JSONArray jStatements = jPolicy.getJSONArray(JsonDocumentFields.STATEMENT);

            for (int index = 0 ; index < jStatements.length() ; index++) {
                Statement statement = convertStatement(jStatements.getJSONObject(index));
                if (statement != null) {
                statements.add(statement);
                }
            }
        } catch (Exception e) {
View Full Code Here


                statement.getPrincipals().add(new Principal(serviceId));
                } else if (field.equalsIgnoreCase("Service")) {
                    statement.getPrincipals().add(new Principal(Services.fromString(serviceId)));
                }
            } else {
                JSONArray jPrincipal = jPrincipals.getJSONArray(field);
                convertPrincipalRecord(field, statement, jPrincipal);
            }
        }
    }
View Full Code Here

        for (String key : keys) {
            String value = jCondition.optString(key);
            if (value != null && value.length() > 0) {
                values.add(value);
            } else {
                JSONArray jValues = jCondition.getJSONArray(key);
                for (int index = 0; index < jValues.length(); index++) {
                    values.add(jValues.getString(index));
                }
            }
            conditions.add(new Condition().withType(type).withConditionKey(key).withValues(values));
        }
    }
View Full Code Here

            actions.add(new NamedAction(actionName));
            statement.setActions(actions);
            return;
        }

        JSONArray jActions = jStatement.getJSONArray(JsonDocumentFields.ACTION);
        for (int index = 0 ; index < jActions.length() ; index++) {
            actionName = jActions.getString(index);
            actions.add(new NamedAction(actionName));
        }
        statement.setActions(actions);
    }
View Full Code Here

            resources.add(new Resource(resourceId));
            statement.setResources(resources);
            return;
        }

        JSONArray jResources = jStatement.getJSONArray(JsonDocumentFields.RESOURCE);
        for (int index = 0 ; index < jResources.length() ; index++) {
            resources.add(new Resource(jResources.getString(index)));
        }
        statement.setResources(resources);
    }
View Full Code Here

        JsonObjectNames.INDEX_COLLECTION);
    return uniqifyIndexes(merge).toString();
  }

  private JSONObject uniqifyIndexes(JSONObject json) throws JSONException {
    JSONArray jsonArray = json.getJSONArray(JsonObjectNames.INDEX_COLLECTION);
    Set<String> uniqueIndexes = new HashSet<String>();
    for (int i = 0; i < jsonArray.length(); i++)
      uniqueIndexes.add(jsonArray.getString(i));
    return JsonUtils.writeKeyValueAsJson(JsonObjectNames.INDEX_COLLECTION,
        uniqueIndexes);
  }
View Full Code Here

    assertEquals("Error for empty resourceId", "Error", service.getResource(null, null, Product.ec2, null, null, 0));
    assertEquals("Error for empty resourceId", "Error", service.getResource(null, null, Product.ec2, "", null, 0));

    assertEquals("Unknown for resourceIds that we do not find", "Unknown", service.getResource(null, null, Product.ec2, "someunknowninstance", null, 0));

    JSONArray instances = service.readInstanceArray();

    String resource = service.getResource(null, null, Product.ec2, instances.getString(0), null, 0);
    assertFalse("Not Error for an actual instance", "Error".equals(resource));

    resource = service.getResource(null, null, Product.ec2_instance, instances.getString(0), null, 0);
    assertFalse("Not Error for an actual instance", "Error".equals(resource));

    for(int i = 0;i < instances.length();i++) {
      resource = service.getResource(null, null, Product.ec2_instance, instances.getString(i), null, 0);
      assertFalse("Not Error for an actual instance", "Error".equals(resource));
    }
  }
View Full Code Here

  @Test
  public void testWrongURL() throws Exception {
    // use a normal setup for retrieving the instances
    EddaResourceService service = new EddaResourceService(new Properties());
    JSONArray instances = service.readInstanceArray();

    // overwrite config with an invalid hostname
    Properties prop = new Properties();
    prop.setProperty("ice.eddaresourceservice.url", "http://invalidhostname:18081/edda/api/v2/");
    service = new EddaResourceService(prop);

    // now the retrieved resources should return an error even for valid instances
    String resource = service.getResource(null, null, Product.ec2, instances.getString(0), null, 0);
    assertTrue("Error even for an actual instance when using wrong URL", "Error".equals(resource));

    // overwrite config with an invalid URL
    prop.setProperty("ice.eddaresourceservice.url", "sasie://invalidhostname:18081/edda/api/v2/");
    service = new EddaResourceService(prop);

    // now the retrieved resources should return an error even for valid instances
    resource = service.getResource(null, null, Product.ec2, instances.getString(0), null, 0);
    assertTrue("Error even for an actual instance when using wrong URL", "Error".equals(resource));
  }
View Full Code Here

        logger.warn("Had empty resourceId");
        return "Error";
      }

      try {
        JSONArray instances = readInstanceArray();
        boolean found = false;
        for(int i = 0;i < instances.length();i++) {
          String instance = instances.getString(i);
          if(resourceId.equals(instance)) {
            found = true;
            break;
          }
        }
        if(!found) {
          logger.warn("Did not find resourceId in edda: " + resourceId);
          return "Unknown";
        }

        InputStream stream = new URL(EDDA_ROOT_URL + "view/instances/" + resourceId).openStream();
        final String json;
        try {
          json = IOUtils.toString(stream);
        } finally {
          stream.close();
        }

        JSONObject object = new JSONObject(json);
        JSONArray tags = object.getJSONArray("tags");
        for(int i = 0;i < tags.length();i++) {
          JSONObject tag = tags.getJSONObject(i);
          String key = tag.getString("key");
          if(key.equals(EDDA_TAG_NAME)) {
            String usage = tag.getString("value");
            logger.debug("Found usage: " + usage + " for resource " + resourceId);
            return usage;
View Full Code Here

    try {
      json = IOUtils.toString(stream);
    } finally {
      stream.close();
    }
    JSONArray instances = new JSONArray(json);
    return instances;
  }
View Full Code Here

TOP

Related Classes of com.amazonaws.util.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.