Java Code Examples for io.vertx.core.json.JsonObject#getBoolean()

The following examples show how to use io.vertx.core.json.JsonObject#getBoolean() . 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: IndexOptions.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor from JSON
 *
 * @param options  the JSON
 */
public IndexOptions(JsonObject options) {
    background = options.getBoolean("background", DEFAULT_BACKGROUD);
    unique = options.getBoolean("unique", DEFAULT_UNIQUE);
    name = options.getString("name");
    sparse = options.getBoolean("sparse", DEFAULT_SPARSE);
    expireAfterSeconds = options.getLong("expireAfterSeconds");
    version = options.getInteger("version");
    weights = options.getJsonObject("weights");
    defaultLanguage = options.getString("defaultLanguage");
    languageOverride = options.getString("languageOverride");
    textVersion = options.getInteger("textVersion");
    sphereVersion = options.getInteger("sphereVersion");
    bits = options.getInteger("bits");
    min = options.getDouble("min");
    max = options.getDouble("max");
    bucketSize = options.getDouble("bucketSize");
    storageEngine = options.getJsonObject("storageEngine");
    partialFilterExpression = options.getJsonObject("partialFilterExpression");
}
 
Example 2
Source File: SockJSHandlerOptions.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
public SockJSHandlerOptions(JsonObject json) {
  this.sessionTimeout = json.getLong("sessionTimeout", DEFAULT_SESSION_TIMEOUT);
  this.insertJSESSIONID = json.getBoolean("insertJSESSIONID", DEFAULT_INSERT_JSESSIONID);
  this.heartbeatInterval = json.getLong("heartbeatInterval", DEFAULT_HEARTBEAT_INTERVAL);
  this.maxBytesStreaming = json.getInteger("maxBytesStreaming", DEFAULT_MAX_BYTES_STREAMING);
  this.libraryURL = json.getString("libraryURL", DEFAULT_LIBRARY_URL);
  JsonArray arr = json.getJsonArray("disabledTransports");
  if (arr != null) {
    for (Object str : arr) {
      if (str instanceof String) {
        String sstr = (String) str;
        disabledTransports.add(sstr);
      } else {
        throw new IllegalArgumentException("Invalid type " + str.getClass() + " in disabledTransports array");
      }
    }
  }
}
 
Example 3
Source File: KubeAuthApi.java    From enmasse with Apache License 2.0 5 votes vote down vote up
@Override
public io.enmasse.api.auth.SubjectAccessReview performSubjectAccessReviewResource(TokenReview tokenReview, String namespace, String resource, String resourceName, String verb, String apiGroup) {
    if (client.isAdaptable(OkHttpClient.class)) {
        JsonObject body = new JsonObject();

        body.put("kind", "SubjectAccessReview");
        body.put("apiVersion", "authorization.k8s.io/v1");

        JsonObject spec = new JsonObject();

        JsonObject resourceAttributes = new JsonObject();
        resourceAttributes.put("group", apiGroup);
        resourceAttributes.put("namespace", namespace);
        resourceAttributes.put("resource", resource);
        if (resourceName != null) {
            resourceAttributes.put("name", resourceName);
        }
        resourceAttributes.put("verb", verb);

        spec.put("resourceAttributes", resourceAttributes);

        putCommonSpecAttributes(spec, tokenReview);

        body.put("spec", spec);
        log.debug("Subject access review request: {}", body);
        JsonObject responseBody = doRawHttpRequest("/apis/authorization.k8s.io/v1/subjectaccessreviews", "POST", body, false);
        log.debug("Subject access review response: {}", responseBody);

        JsonObject status = responseBody.getJsonObject("status");
        boolean allowed = false;
        if (status != null) {
            Boolean allowedMaybe = status.getBoolean("allowed");
            allowed = allowedMaybe == null ? false : allowedMaybe;
        }
        return new io.enmasse.api.auth.SubjectAccessReview(tokenReview.getUserName(), allowed);
    } else {
        return new SubjectAccessReview(tokenReview.getUserName(), false);
    }
}
 
Example 4
Source File: Character.java    From rxjava2-lab with Apache License 2.0 5 votes vote down vote up
public Character(JsonObject json) {
    this.id = json.getInteger("id");
    this.name = json.getString("name");
    this.villain = json.getBoolean("villain");
    JsonArray powers = json.getJsonArray("superpowers");
    this.superpowers = powers.stream().map(Object::toString).collect(Collectors.toList());

}
 
Example 5
Source File: UserData.java    From kyoko with MIT License 5 votes vote down vote up
public UserData(@NotNull JsonObject object) {
    this.id = Objects.requireNonNull(object).getLong("id");
    this.blacklisted = object.getBoolean("blacklisted");
    this.flags = object.getInteger("flags", 0);
    this.language = Language.valueOfSafe(object.getString("language", "DEFAULT"));
    this.color = object.getInteger("color", 0xff4757);
    this.image = object.getString("image", "default");
    this.voted = object.getLong("voted");
}
 
Example 6
Source File: ModerationConfig.java    From kyoko with MIT License 5 votes vote down vote up
public ModerationConfig(@NotNull JsonObject object) {
    this.id = Objects.requireNonNull(object).getLong("id");
    this.admins = JsonUtil.toListLong(object, "admins");
    this.moderators = JsonUtil.toListLong(object, "moderators");
    this.antiInvite = object.getBoolean("anti_invite");
    this.appealInfo = object.getString("appeal_info");
}
 
Example 7
Source File: ServiceRegistry.java    From vert.x-microservice with Apache License 2.0 5 votes vote down vote up
private void initConfiguration(JsonObject config) {
    expiration_age = config.getLong("expiration", DEFAULT_EXPIRATION_AGE);
    ping_time = config.getLong("ping", DEFAULT_PING_TIME);
    sweep_time = config.getLong("sweep", DEFAULT_SWEEP_TIME);
    timeout_time = config.getLong("timeout", DEFAULT_TIMEOUT);
    serviceRegisterPath = config.getString("serviceRegisterPath", GlobalKeyHolder.SERVICE_REGISTER_HANDLER);
    serviceUnRegisterPath = config.getString("serviceUnRegisterPath", GlobalKeyHolder.SERVICE_UNREGISTER_HANDLER);
    host = config.getString("host", HOST);
    port = config.getInteger("port", PORT);
    mainURL = host.concat(":").concat(Integer.valueOf(port).toString());
    debug = config.getBoolean("debug",false);

}
 
Example 8
Source File: VxApiMain.java    From VX-API-Gateway with MIT License 5 votes vote down vote up
/**
 * 执行CLI的相应指令
 * 
 * @param config
 * @param handler
 */
public void runCLICommand(JsonObject config, Handler<AsyncResult<Void>> handler) {
	// 执行客户端
	if (config.getBoolean("startEverything", false) != false) {
		vertx.eventBus().send(VxApiEventBusAddressConstant.CLI_START_EVERYTHING, null, res -> {
			if (res.failed()) {
				handler.handle(Future.failedFuture(res.cause()));
			}
		});
	} else if (config.getBoolean("startAllAPP", false) != false) {
		vertx.eventBus().send(VxApiEventBusAddressConstant.CLI_START_ALL_APP, null, res -> {
			if (res.failed()) {
				handler.handle(Future.failedFuture(res.cause()));
			}
		});
	} else if (config.getJsonArray("startAPPEverything") != null) {
		vertx.eventBus().send(VxApiEventBusAddressConstant.CLI_START_APP_EVERYTHING, config.getJsonArray("startAPPEverything"), res -> {
			if (res.failed()) {
				handler.handle(Future.failedFuture(res.cause()));
			}
		});
	} else if (config.getJsonArray("startAPP") != null) {
		vertx.eventBus().send(VxApiEventBusAddressConstant.CLI_START_APP, config.getJsonArray("startAPP"), res -> {
			if (res.failed()) {
				handler.handle(Future.failedFuture(res.cause()));
			}
		});
	}
	handler.handle(Future.succeededFuture());
}
 
Example 9
Source File: BlobReference.java    From sfs with Apache License 2.0 5 votes vote down vote up
public T merge(JsonObject jsonObject) {
    volumeId = jsonObject.getString("volume_id");
    position = jsonObject.getLong("position");
    readSha512 = jsonObject.getBinary("read_sha512");
    readLength = jsonObject.getLong("read_length");
    acknowledged = jsonObject.getBoolean("acknowledged");
    deleted = jsonObject.getBoolean("deleted");
    verifyFailCount = jsonObject.getInteger("verify_fail_count", 0);

    return (T) this;
}
 
Example 10
Source File: JsonParameterProcessorGenerator.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
public ParameterProcessor generate(JsonObject parameter, JsonObject fakeSchema, JsonPointer parameterPointer, ParameterLocation parsedLocation, String parsedStyle, GeneratorContext context) {
  JsonObject originalSchema = (JsonObject) SCHEMA_POINTER.queryJsonOrDefault(parameter, new JsonObject());
  SchemaHolder schemas = context.getSchemaHolder(
    originalSchema, context.fakeSchema(fakeSchema),
    parameterPointer.copy().append("content").append("application/json").append("schema")
  );
  return new ParameterProcessorImpl(
    parameter.getString("name"),
    parsedLocation,
    !parameter.getBoolean("required", false),
    new SingleValueParameterParser(parameter.getString("name"), ValueParser.JSON_PARSER),
    schemas.getValidator()
  );
}
 
Example 11
Source File: InitMongoDB.java    From kube_vertx_demo with Apache License 2.0 5 votes vote down vote up
public static void initMongoData(Vertx vertx,JsonObject config) {
    MongoClient mongo;
    // Create a mongo client using all defaults (connect to localhost and default port) using the database name "demo".
    String connectionUrl = connectionURL();
    boolean local = config.getBoolean("local", false);
    if (connectionUrl != null && !local) {
        String dbName = config.getString("dbname", "vxmsdemo");
        mongo = MongoClient.createShared(vertx, new JsonObject().put("connection_string", connectionUrl).put("db_name", dbName));
    } else {
        mongo = MongoClient.createShared(vertx, new JsonObject().put("db_name", "demo"));
    }
    // the load function just populates some data on the storage
    loadData(mongo);
}
 
Example 12
Source File: ConsulServiceImporter.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
private Record createRecord(Service service) {
  String address = service.getAddress();
  int port = service.getPort();

  JsonObject metadata = service.toJson();
  if (service.getTags() != null) {
    service.getTags().forEach(tag -> metadata.put(tag, true));
  }

  Record record = new Record()
      .setName(service.getName())
      .setMetadata(metadata);

  // To determine the record type, check if we have a tag with a "type" name
  record.setType(ServiceType.UNKNOWN);
  ServiceTypes.all().forEachRemaining(type -> {
    if (metadata.getBoolean(type.name(), false)) {
      record.setType(type.name());
    }
  });

  JsonObject location = new JsonObject();
  location.put("host", address);
  location.put("port", port);

  // Manage HTTP endpoint
  if (record.getType().equals("http-endpoint")) {
    if (metadata.getBoolean("ssl", false)) {
      location.put("ssl", true);
    }
    location = new HttpLocation(location).toJson();
  }

  record.setLocation(location);
  return record;
}
 
Example 13
Source File: InitMongoDB.java    From kube_vertx_demo with Apache License 2.0 5 votes vote down vote up
public static MongoClient initMongoData(Vertx vertx,JsonObject config) {
    MongoClient mongo;
    // Create a mongo client using all defaults (connect to localhost and default port) using the database name "demo".
    String connectionUrl = connectionURL();
    boolean local = config.getBoolean("local", false);
    if (connectionUrl != null && !local) {
        String dbName = config.getString("dbname", "vxmsdemo");
        mongo = MongoClient.createShared(vertx, new JsonObject().put("connection_string", connectionUrl).put("db_name", dbName));
    } else {
        mongo = MongoClient.createShared(vertx, new JsonObject().put("db_name", "demo"));
    }
    // the load function just populates some data on the storage
    return mongo;
}
 
Example 14
Source File: MqttWill.java    From vertx-mqtt with Apache License 2.0 5 votes vote down vote up
/**
 * Create instance from JSON
 *
 * @param json the JSON
 */
public MqttWill(JsonObject json) {
  this.isWillFlag = json.getBoolean("isWillFlag");
  this.willTopic = json.getString("willTopic");
  this.willMessage = json.getString("willMessage").getBytes(Charset.forName("UTF-8"));
  this.willQos = json.getInteger("willMessage");
  this.isWillRetain = json.getBoolean("isWillRetain");
}
 
Example 15
Source File: InitMongoDB.java    From vxms with Apache License 2.0 5 votes vote down vote up
public static MongoClient initMongoData(Vertx vertx, JsonObject config) {
    MongoClient mongo;
    // Create a mongo client using all defaults (connect to localhost and default port) using the database name "demo".
    String connectionUrl = connectionURL();
    boolean local = config.getBoolean("local", false);
    if (connectionUrl != null && !local) {
        String dbName = config.getString("dbname", "vxmsdemo");
        mongo = MongoClient.createShared(vertx, new JsonObject().put("connection_string", connectionUrl).put("db_name", dbName));
    } else {
        mongo = MongoClient.createShared(vertx, new JsonObject().put("db_name", "demo"));
    }
    // the load function just populates some data on the storage
    return mongo;
}
 
Example 16
Source File: Vertx3GatewayHelper.java    From apiman with Apache License 2.0 4 votes vote down vote up
/**
 * get gateway port dynamically from configuration
 * @param apiToFilePushEmulatorConfig configuration
 * @return gateway port
 */
public int getGatewayPortDynamically(JsonObject apiToFilePushEmulatorConfig) {
    boolean preferSecure = apiToFilePushEmulatorConfig.getBoolean("preferSecure");
    String method = preferSecure ? "https" : "http";
    return apiToFilePushEmulatorConfig.getJsonObject("verticles").getJsonObject(method).getInteger("port");
}
 
Example 17
Source File: JsObject.java    From vertx-codetrans with Apache License 2.0 4 votes vote down vote up
@CodeTranslate
public void getBooleanFromIdentifier() throws Exception {
  JsonObject obj = new JsonObject().put("_true", true);
  JsonTest.o = obj.getBoolean("_true");
}
 
Example 18
Source File: CookieHandler.java    From nassh-relay with GNU General Public License v2.0 4 votes vote down vote up
public CookieHandler(final JsonObject config) {
    this.authentication = config.getBoolean("authentication", true);
    this.secureCookie = config.getBoolean("secure-cookie", true);
    this.sessionTTL = config.getInteger("auth-session-timeout", 600);
    this.auth = config.getJsonObject("auth");
}
 
Example 19
Source File: KubeAuthApi.java    From enmasse with Apache License 2.0 4 votes vote down vote up
@Override
public TokenReview performTokenReview(String token) {
    if (client.isAdaptable(OkHttpClient.class)) {
        JsonObject body = new JsonObject();

        body.put("kind", "TokenReview");
        body.put("apiVersion", "authentication.k8s.io/v1");

        JsonObject spec = new JsonObject();
        spec.put("token", token);
        body.put("spec", spec);

        log.debug("Token review request: {}", body);
        JsonObject responseBody= doRawHttpRequest("/apis/authentication.k8s.io/v1/tokenreviews", "POST", body, false);
        log.debug("Token review response: {}", responseBody);
        JsonObject status = responseBody.getJsonObject("status");
        boolean authenticated = false;
        String userName = null;
        String userId = null;
        Set<String> groups = null;
        Map<String, List<String>> extra = null;
        if (status != null) {
            Boolean auth = status.getBoolean("authenticated");
            authenticated = auth == null ? false : auth;
            JsonObject user = status.getJsonObject("user");
            if (user != null) {
                userName = user.getString("username");
                userId = user.getString("uid");
                JsonArray groupArray = user.getJsonArray("groups");
                if (groupArray != null) {
                    groups = new HashSet<>();
                    for (int i = 0; i < groupArray.size(); i++) {
                        groups.add(groupArray.getString(i));
                    }
                }

                JsonObject extraObject = user.getJsonObject("extra");
                if (extraObject != null) {
                    extra = new HashMap<>();
                    for (String field : extraObject.fieldNames()) {
                        JsonArray extraValues = extraObject.getJsonArray(field);
                        List<String> extraValuesList = new ArrayList<>();
                        for (int i = 0; i < extraValues.size(); i++) {
                            extraValuesList.add(extraValues.getString(i));
                        }
                        extra.put(field, extraValuesList);
                    }
                }

            }
        }
        return new TokenReview(userName, userId, groups, extra, authenticated);
    } else {
        return new TokenReview(null, null, null, null, false);
    }
}
 
Example 20
Source File: EnvVariablesConfigStore.java    From vertx-config with Apache License 2.0 4 votes vote down vote up
@Override
public ConfigStore create(Vertx vertx, JsonObject configuration) {
  return new EnvVariablesConfigStore(configuration.getBoolean("raw-data", false), configuration.getJsonArray("keys"));
}