下面列出了io.vertx.core.json.JsonObject#getBoolean ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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");
}
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");
}
}
}
}
@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);
}
}
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());
}
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");
}
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");
}
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);
}
/**
* 执行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());
}
@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()
);
}
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;
}
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;
}
/**
* 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");
}
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;
}
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);
}
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;
}
@Override
public ConfigStore create(Vertx vertx, JsonObject configuration) {
return new EnvVariablesConfigStore(configuration.getBoolean("raw-data", false), configuration.getJsonArray("keys"));
}
@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);
}
}
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");
}
@CodeTranslate
public void getBooleanFromIdentifier() throws Exception {
JsonObject obj = new JsonObject().put("_true", true);
JsonTest.o = obj.getBoolean("_true");
}
/**
* 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");
}