Java Code Examples for io.vertx.core.json.JsonArray#getString()

The following examples show how to use io.vertx.core.json.JsonArray#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Artemis.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Set<String> getQueueNames() throws TimeoutException {
    log.info("Retrieving queue names for broker {}", syncRequestClient.getRemoteContainer());
    Message response = doOperation("broker", "getQueueNames");

    Set<String> queues = new LinkedHashSet<>();
    JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
    for (int i = 0; i < payload.size(); i++) {
        JsonArray inner = payload.getJsonArray(i);
        for (int j = 0; j < inner.size(); j++) {
            String queueName = inner.getString(j);
            if (!queueName.equals(syncRequestClient.getReplyTo())) {
                queues.add(queueName);
            }
        }
    }
    return queues;
}
 
Example 2
Source File: MongoAuthImpl.java    From vertx-auth with Apache License 2.0 6 votes vote down vote up
private User createUser(JsonObject json) {
  User user = new UserImpl(json);
  json.put(PROPERTY_FIELD_SALT, getSaltField());
  json.put(PROPERTY_FIELD_PASSWORD, getPasswordField());
  JsonArray roles = json.getJsonArray(mongoAuthorizationOptions.getRoleField());
  if (roles!=null) {
    for (int i=0; i<roles.size(); i++) {
      String role = roles.getString(i);
      user.authorizations().add(PROVIDER_ID, RoleBasedAuthorization.create(role));
    }
  }
  JsonArray permissions = json.getJsonArray(mongoAuthorizationOptions.getPermissionField());
  if (permissions!=null) {
    for (int i=0; i<permissions.size(); i++) {
      String permission = permissions.getString(i);
      user.authorizations().add(PROVIDER_ID, PermissionBasedAuthorization.create(permission));
    }
  }
  user.setAuthProvider(this);
  return user;
}
 
Example 3
Source File: AuthenticatorConfig.java    From vertx-mqtt-broker with Apache License 2.0 6 votes vote down vote up
public void parse(JsonObject conf) {
    JsonObject security = conf.getJsonObject("security", new JsonObject());
    JsonArray authorizedClientsArr = security.getJsonArray("authorized_clients", new JsonArray());
    if(authorizedClientsArr != null) {
        authorizedClients = new ArrayList<>();
        for(int i=0; i<authorizedClientsArr.size(); i++) {
            String item = authorizedClientsArr.getString(i);
            authorizedClients.add(item);
        }
    }
    idpUrl = security.getString("idp_url", null);
    idpUsername = security.getString("idp_username", null);
    idpPassword = security.getString("idp_password", null);
    appKey = security.getString("app_key", null);
    appSecret = security.getString("app_secret", null);
}
 
Example 4
Source File: ResultSetTest.java    From vertx-jdbc-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testResultSet() {

  assertEquals(numRows, rs.getNumRows());
  assertEquals(columnNames.size(), rs.getNumColumns());
  assertEquals(columnNames.size(), rs.getColumnNames().size());
  assertEquals(columnNames, rs.getColumnNames());
  assertEquals(results, rs.getResults());

  List<JsonObject> rows = rs.getRows();
  assertEquals(numRows, rs.getRows().size());
  int index = 0;
  for (JsonObject row: rows) {
    JsonArray result = results.get(index);
    assertEquals(columnNames.size(), row.size());
    assertEquals(row.size(), result.size());
    for (int i = 0; i < columnNames.size(); i++) {
      String columnName = columnNames.get(i);
      String columnValue = result.getString(i);
      assertEquals(columnValue, row.getString(columnName));
    }
    index++;
  }

}
 
Example 5
Source File: PostgresClient.java    From raml-module-builder with Apache License 2.0 6 votes vote down vote up
/**
 * Insert or upsert the entities into table using a single INSERT statement.
 * @param sqlConnection  the connection to run on, may be on a transaction
 * @param upsert  true for upsert, false for insert with fail on duplicate id
 * @param table  destination table to insert into
 * @param entities  each array element is a String with the content for the JSONB field of table; if id is missing a random id is generated
 * @param replyHandler  result, containing the id field for each inserted element of entities
 */
private void saveBatch(AsyncResult<SQLConnection> sqlConnection, boolean upsert, String table,
    JsonArray entities, Handler<AsyncResult<RowSet<Row>>> replyHandler) {

  try {
    List<Tuple> list = new ArrayList<>();
    if (entities != null) {
      for (int i = 0; i < entities.size(); i++) {
        String json = entities.getString(i);
        JsonObject jsonObject = new JsonObject(json);
        String id = jsonObject.getString("id");
        list.add(Tuple.of(id == null ? UUID.randomUUID() : UUID.fromString(id),
            jsonObject));
      }
    }
    saveBatchInternal(sqlConnection, upsert, table, list, replyHandler);
  } catch (Exception e) {
    log.error(e.getMessage(), e);
    replyHandler.handle(Future.failedFuture(e));
  }
}
 
Example 6
Source File: Artemis.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Set<String> getConnectorNames() throws TimeoutException {
    log.info("Retrieving conector names for broker {}", syncRequestClient.getRemoteContainer());
    Message response = doOperation("broker", "getConnectorServices");

    Set<String> connectors = new LinkedHashSet<>();
    JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
    for (int i = 0; i < payload.size(); i++) {
        JsonArray inner = payload.getJsonArray(i);
        for (int j = 0; j < inner.size(); j++) {
            String connector = inner.getString(j);
            if (!connector.equals("amqp-connector")) {
                connectors.add(connector);
            }
        }
    }
    return connectors;
}
 
Example 7
Source File: Artemis.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Set<String> getAddressNames() throws TimeoutException {
    log.info("Retrieving address names for broker {}", syncRequestClient.getRemoteContainer());
    Message response = doOperation("broker", "getAddressNames");

    Set<String> addressNames = new LinkedHashSet<>();
    JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
    for (int i = 0; i < payload.size(); i++) {
        JsonArray inner = payload.getJsonArray(i);
        for (int j = 0; j < inner.size(); j++) {
            String addressName = inner.getString(j);
            if (!addressName.equals(syncRequestClient.getReplyTo())) {
                addressNames.add(addressName);
            }
        }
    }
    return addressNames;
}
 
Example 8
Source File: JDBCAuthenticationImpl.java    From vertx-auth with Apache License 2.0 6 votes vote down vote up
private boolean verify(JsonArray row, String password) {
  String hash = row.getString(0);
  if (hash.charAt(0) != '$') {
    // this isn't a phc-string, it's legacy
    if (legacyStrategy == null) {
      throw new IllegalStateException("JDBC Authentication cannot handle legacy hashes without a JDBCStrategy");
    }
    String salt = row.getString(1);
    // extract the version (-1 means no version)
    int version = -1;
    int sep = hash.lastIndexOf('$');
    if (sep != -1) {
      try {
        version = Integer.parseInt(hash.substring(sep + 1));
      } catch (NumberFormatException e) {
        // the nonce version is not a number
        throw new IllegalStateException("Invalid nonce version: " + version);
      }
    }
    return JDBCHashStrategy.isEqual(hash, legacyStrategy.computeHash(password, salt, version));
  } else {
    return strategy.verify(hash, password);
  }
}
 
Example 9
Source File: DockerTest.java    From okapi with Apache License 2.0 6 votes vote down vote up
private static boolean checkTestModulePresent(JsonArray ar) {
  if (ar != null) {
    for (int i = 0; i < ar.size(); i++) {
      JsonObject ob = ar.getJsonObject(i);
      JsonArray ar1 = ob.getJsonArray("RepoTags");
      if (ar1 != null) {
        for (int j = 0; j < ar1.size(); j++) {
          String tag = ar1.getString(j);
          if (tag != null && tag.startsWith("okapi-test-module")) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
 
Example 10
Source File: RestVerticle.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
static String acceptCheck(JsonArray l, String h) {
  String []hl = h.split(",");
  String hBest = null;
  for (int i = 0; i < hl.length; i++) {
    String mediaRange = hl[i].split(";")[0].trim();
    for (int j = 0; j < l.size(); j++) {
      String c = l.getString(j);
      if (mediaRange.compareTo("*/*") == 0 || c.equalsIgnoreCase(mediaRange)) {
        hBest = c;
        break;
      }
    }
  }
  return hBest;
}
 
Example 11
Source File: AbstractHashingStrategy.java    From vertx-auth with Apache License 2.0 4 votes vote down vote up
@Override
public String getSalt(JsonArray row) {
  return row.getString(1);
}
 
Example 12
Source File: SchemaTypeUtils.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
/**
 * Create a {@link Schema} from a {@link JsonObject}
 *  schema descriptor. The schema descriptor contains a json object of keys
 *  of type {@link ColumnType} values in the form of:
 *  name : {@link ColumnType} value
 *
 * There are 2 exceptions to this rule.
 * {@link ColumnType#NDArray} and {@link ColumnType#Categorical}
 * both are json objects.
 * {@link ColumnType#NDArray} has the form:
 * {name : shape: [], serialization type: "json" | "b64"}
 * {@link ColumnType#Categorical} has the form:
 * {categories: []}
 * {@link ColumnType#Time} has the form:
 * {timeZoneId: timeZoneId}
 *
 *
 * @param schemaDescriptor a {@link JsonObject} with the form
 *                         described above
 * @return the equivalent {@link Schema} derived from the given descriptor
 */
public static Schema schemaFromDynamicSchemaDefinition(JsonObject schemaDescriptor) {
    Schema.Builder schemaBuilder = new Builder();
    for(String key : schemaDescriptor.fieldNames()) {
        JsonObject fieldInfo = schemaDescriptor.getJsonObject(key);
        JsonObject fieldInfoObject = fieldInfo.getJsonObject("fieldInfo");
        if(fieldInfoObject == null) {
            throw new IllegalArgumentException("Unable to find object fieldInfo!");
        }

        if(!fieldInfoObject.containsKey("type")) {
            throw new IllegalArgumentException("Illegal field info. Missing key type for identifying type of field");
        }
        //convert image to bytes and let user pre process accordingly
        String type = fieldInfoObject.getString("type");
        if(type.equals("Image")) {
            type = "Bytes";
        }
        switch(ColumnType.valueOf(type)) {
            case Boolean:
                schemaBuilder.addColumnBoolean(key);
                break;
            case Double:
                schemaBuilder.addColumnDouble(key);
                break;
            case Float:
                schemaBuilder.addColumnFloat(key);
                break;
            case Long:
                schemaBuilder.addColumnLong(key);
                break;
            case String:
                schemaBuilder.addColumnString(key);
                break;
            case Integer:
                schemaBuilder.addColumnInteger(key);
                break;
            case NDArray:
                JsonArray shapeArr = fieldInfoObject.getJsonArray("shape");
                long[] shape = new long[shapeArr.size()];
                for(int i = 0; i < shape.length; i++) {
                    shape[i] = shapeArr.getLong(i);
                }
                schemaBuilder.addColumnNDArray(key,shape);
                break;
            case Categorical:
                JsonArray jsonArray = fieldInfoObject.getJsonArray("categories");
                String[] categories = new String[jsonArray.size()];
                for(int i = 0; i < categories.length; i++) {
                    categories[i] = jsonArray.getString(i);
                }
                schemaBuilder.addColumnCategorical(key,categories);
                break;
            case Bytes:
                ColumnMetaData columnMetaData = new BinaryMetaData(key);
                schemaBuilder.addColumn(columnMetaData);
                break;
            case Time:
                TimeZone zoneById = TimeZone.getTimeZone(fieldInfoObject.getString("timeZoneId"));
                schemaBuilder.addColumnTime(key,zoneById);
                break;

        }
    }

    return schemaBuilder.build();
}
 
Example 13
Source File: Artemis.java    From enmasse with Apache License 2.0 4 votes vote down vote up
private String doOperationWithStringResult(String resource, String operation, Object ... parameters) throws TimeoutException {
    Message response = doOperation(resource, operation, parameters);
    String payload = (String) ((AmqpValue)response.getBody()).getValue();
    JsonArray json = new JsonArray(payload);
    return json.getString(0);
}
 
Example 14
Source File: AccountDBVerticle.java    From AlipayWechatPlatform with GNU General Public License v3.0 4 votes vote down vote up
private void register(Handler replyMsg, JsonArray params) {
    String email = params.getString(0);
    String password = params.getString(1);
    String name = params.getString(2);
    accDao.register(email, password, name, replyMsg);
}
 
Example 15
Source File: AccountDBVerticle.java    From AlipayWechatPlatform with GNU General Public License v3.0 4 votes vote down vote up
private void loginById(Handler replyMsg, JsonArray params) {
    Long id = params.getLong(0);
    String password = params.getString(1);
    accDao.loginById(id, password, replyMsg);
}
 
Example 16
Source File: SQLExamples.java    From vertx-jdbc-client with Apache License 2.0 4 votes vote down vote up
public void example3(ResultSet resultSet) {

    List<String> columnNames = resultSet.getColumnNames();

    List<JsonArray> results = resultSet.getResults();

    for (JsonArray row : results) {

      String id = row.getString(0);
      String fName = row.getString(1);
      String lName = row.getString(2);
      int shoeSize = row.getInteger(3);

    }

  }
 
Example 17
Source File: AccountDBVerticle.java    From AlipayWechatPlatform with GNU General Public License v3.0 4 votes vote down vote up
private void selectByEmail(Handler replyMsg, JsonArray params) {
    String email = params.getString(0);
    accDao.selectByEmail(email, replyMsg);
}
 
Example 18
Source File: JsArray.java    From vertx-codetrans with Apache License 2.0 4 votes vote down vote up
@CodeTranslate
public void getString() throws Exception {
  JsonArray arr = JsonTest.array;
  arr = JsonConverter.fromJsonArray(arr);
  JsonTest.o = arr.getString(0);
}
 
Example 19
Source File: OrderDBVerticle.java    From AlipayWechatPlatform with GNU General Public License v3.0 4 votes vote down vote up
private void getOrderByWechatOrderId(Handler replyMsg, JsonArray params) {
    String orderId = params.getString(0);
    orderDao.getByOrderId(orderId, 0, replyMsg);
}
 
Example 20
Source File: OrderDBVerticle.java    From AlipayWechatPlatform with GNU General Public License v3.0 4 votes vote down vote up
private void getOrderByAlipayOrderId(Handler replyMsg, JsonArray params) {
    String orderId = params.getString(0);
    orderDao.getByOrderId(orderId, 1, replyMsg);
}