本文整理匯總了Java中io.vertx.core.json.JsonObject.getInteger方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonObject.getInteger方法的具體用法?Java JsonObject.getInteger怎麽用?Java JsonObject.getInteger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.getInteger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addToList
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private void addToList(RoutingContext rc) {
JsonObject json = rc.getBodyAsJson();
int quantity = json.getInteger("quantity", 1);
if (quantity <= 0) {
rc.response().setStatusCode(400);
return;
}
redis.hset(KEY, json.getString("name"), Integer.toString(quantity), r -> {
if (r.succeeded()) {
getList(rc);
} else {
rc.fail(r.cause());
}
});
}
示例2: applyForOauth
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
* 申請微信授權
* /awp/wxOauth/apply/{body}
* web服務需要授權時,向用戶發送重定向,重定向到當前接口
* 參數隻有一個,內容為JSON,請用http://localhost:8083/awp/base64.html進行加密
* {
* "eid":web項目使用的公眾號在本項目中的用戶ID
* "type":0=靜默授權,隻能獲取OpenID,1=正常授權,會彈出授權確認頁麵,可以獲取到用戶信息
* "callback":授權成功後調用的web項目回調接口地址,請使用完整地址,
* 回調時會使用GET方法,加上rs參數,
* 如果靜默授權,rs參數內容就是openid
* 如果正常授權,rs參數內容是turingBase64加密的授權結果(JSON)
* }
*
* @param rc Vertx的RoutingContext對象
* @author Leibniz.Hu
*/
private void applyForOauth(RoutingContext rc) {
HttpServerResponse resp = rc.response();
String decodedBody = TuringBase64Util.decode(rc.request().getParam("body"));
JsonObject reqJson = new JsonObject(decodedBody);
Integer eid = reqJson.getInteger("eid");
int type = reqJson.getInteger("type");
String callback = TuringBase64Util.encode(reqJson.getString("callback"));//授權後回調方法
vertx.eventBus().<JsonObject>send(ADDR_ACCOUNT_DB.get(), makeMessage(COMMAND_GET_ACCOUNT_BY_ID, eid), ar -> {
if (ar.succeeded()) {
JsonObject account = ar.result().body();
String redirectAfterUrl = PROJ_URL + "oauth/wx/" + (type == 0 ? "baseCb" : "infoCb") + "?eid=" + eid + "&visitUrl=" + callback;
String returnUrl = null;
try {
returnUrl = String.format((type == 0 ? OAUTH_BASE_API : OAUTH_INFO_API)
, account.getString(WXAPPID), URLEncoder.encode(redirectAfterUrl, "UTF-8"));
} catch (UnsupportedEncodingException ignored) { //不可能出現的
}
resp.setStatusCode(302).putHeader("Location", returnUrl).end();
} else {
log.error("EventBus消息響應錯誤", ar.cause());
resp.setStatusCode(500).end("EventBus error!");
}
});
}
示例3: init
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
* Read the configuration and set the initial values.
* @param config the configuration
*/
void init(JsonObject config) {
period = config.getLong("period", 3000L);
variation = config.getInteger("variation", 100);
name = config.getString("name");
Objects.requireNonNull(name);
symbol = config.getString("symbol", name);
stocks = config.getInteger("volume", 10000);
price = config.getDouble("price", 100.0);
value = price;
ask = price + random.nextInt(variation / 2);
bid = price + random.nextInt(variation / 2);
share = stocks / 2;
System.out.println("Initialized " + name);
}
示例4: updateAfterPaid
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
* 支付完成後,更新訂單信息
* 包括支付平台的訂單ID,以及支付時間
*/
public void updateAfterPaid(JsonObject order, Handler<Integer> callback) {
String platOrderId = order.getString(PLATORDERID);
if (platOrderId == null || platOrderId.length() == 0) {
throw new IllegalArgumentException("OrderId of pay platform cannot be null!!!");
}
String orderId = order.getString(ORDERID);
if (orderId == null || orderId.length() == 0)
throw new IllegalArgumentException("OrderId in Order object cannot be null!!!");
Integer type = order.getInteger(TYPE);
if (type == null)
throw new IllegalArgumentException("Type in Order object cannot be null!!!");
String sql = "UPDATE awp_order SET platOrderId = ?, payTime = NOW() where orderId=? and type=?";
JsonArray params = new JsonArray().add(platOrderId).add(orderId).add(type);
update(sql, params, callback);
}
示例5: getChannel
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
* @param vertx Vert.x instance
* @param config configuration
* @return ManagedChannel
*/
public static ManagedChannel getChannel(final Vertx vertx,
final JsonObject config) {
final String rpcHost = config.getString(Key.HOST);
final Integer rpcPort = config.getInteger(Key.PORT);
LOGGER.info(Info.CLIENT_RPC, rpcHost, String.valueOf(rpcPort));
final VertxChannelBuilder builder =
VertxChannelBuilder
.forAddress(vertx, rpcHost, rpcPort);
Fn.safeSemi(null != config.getValue(Key.SSL), LOGGER,
() -> {
final JsonObject sslConfig = config.getJsonObject(Key.SSL);
if (null != sslConfig && !sslConfig.isEmpty()) {
final Object type = sslConfig.getValue("type");
final CertType certType = null == type ?
CertType.PEM : Types.fromStr(CertType.class, type.toString());
final TrustPipe<JsonObject> pipe = TrustPipe.get(certType);
// Enable SSL
builder.useSsl(pipe.parse(sslConfig));
} else {
builder.usePlaintext(true);
}
});
return builder.build();
}
示例6: createFromJSON
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public static Message createFromJSON (JsonObject json) {
Message message = new Message();
//get header information
message.event = json.getString("event");
String messageID = json.getString("messageID");
int statusCode = json.getInteger("statusCode");
message.type = ResponseType.getByString(json.getString("status"));
message.data = json.getJsonObject("data");
message.ssid = json.getString("ssid");
if (!messageID.isEmpty() && !messageID.equals("none")) {
//get UUID
message.uuid = UUID.fromString(messageID);
}
return message;
}
示例7: create
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@Override
public Single<JsonObject> create(JsonObject item) {
if (item == null) {
return Single.error(new IllegalArgumentException("The item must not be null"));
}
if (item.getString("name") == null || item.getString("name").isEmpty()) {
return Single.error(new IllegalArgumentException("The name must not be null or empty"));
}
if (item.getInteger("stock", 0) < 0) {
return Single.error(new IllegalArgumentException("The stock must greater or equal to 0"));
}
if (item.containsKey("id")) {
return Single.error(new IllegalArgumentException("The created item already contains an 'id'"));
}
return db.rxGetConnection()
.flatMap(conn -> {
JsonArray params = new JsonArray().add(item.getValue("name")).add(item.getValue("stock", 0));
return conn
.rxUpdateWithParams(INSERT, params)
.map(ur -> item.put("id", ur.getKeys().getLong(0)))
.doAfterTerminate(conn::close);
});
}
示例8: addToList
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private void addToList(RoutingContext rc) {
JsonObject json = rc.getBodyAsJson();
String name = json.getString("name");
Integer quantity = json
.getInteger("quantity", 1);
client.hset(KEY, name, quantity.toString(), x -> {
getList(rc);
});
}
示例9: buy
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@Override
public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
if (amount <= 0) {
resultHandler.handle(Future.failedFuture("Cannot buy " + quote.getString("name") + " - the amount must be " +
"greater than 0"));
return;
}
if (quote.getInteger("shares") < amount) {
resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " - not enough " +
"stocks on the market (" + quote.getInteger("shares") + ")"));
return;
}
double price = amount * quote.getDouble("ask");
String name = quote.getString("name");
// 1) do we have enough money
if (portfolio.getCash() >= price) {
// Yes, buy it
portfolio.setCash(portfolio.getCash() - price);
int current = portfolio.getAmount(name);
int newAmount = current + amount;
portfolio.getShares().put(name, newAmount);
sendActionOnTheEventBus("BUY", amount, quote, newAmount);
resultHandler.handle(Future.succeededFuture(portfolio));
} else {
resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " of " + name + " - " + "not enough money, " +
"need " + price + ", has " + portfolio.getCash()));
}
}
示例10: update
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@Override
public Completable update(long id, JsonObject item) {
if (item == null) {
return Completable.error(new IllegalArgumentException("The item must not be null"));
}
if (item.getString("name") == null || item.getString("name").isEmpty()) {
return Completable.error(new IllegalArgumentException("The name must not be null or empty"));
}
if (item.getInteger("stock", 0) < 0) {
return Completable.error(new IllegalArgumentException("The stock must greater or equal to 0"));
}
if (item.containsKey("id") && id != item.getInteger("id")) {
return Completable.error(new IllegalArgumentException("The 'id' cannot be changed"));
}
return db.rxGetConnection()
.flatMapCompletable(conn -> {
JsonArray params = new JsonArray().add(item.getValue("name")).add(item.getValue("stock", 0)).add(id);
return conn.rxUpdateWithParams(UPDATE, params)
.flatMapCompletable(up -> {
if (up.getUpdated() == 0) {
return Completable.error(new NoSuchElementException("Unknown item '" + id + "'"));
}
return Completable.complete();
})
.doAfterTerminate(conn::close);
});
}
示例11: handleNotification
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private void handleNotification(ProtonDelivery delivery, Message message) {
JsonObject json = new JsonObject(Buffer.buffer(((Data) message.getBody()).getValue().getArray()));
String deviceId = json.getString("device-id");
int temperature = json.getInteger("temperature");
log.info("Received notification with payload {}", json);
adjustTemperature(deviceId, temperature);
}
示例12: addToList
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private void addToList(RoutingContext rc) {
JsonObject json = rc.getBodyAsJson();
String name = json.getString("name");
Integer quantity = json.getInteger("quantity", 1);
redis.hset(KEY, name, quantity.toString(), x -> {
getList(rc);
});
}
開發者ID:cescoffier,項目名稱:vertx-kubernetes-live-coding-devoxx-ma,代碼行數:9,代碼來源:ShoppingBackendVerticle.java
示例13: createRecord
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private Record createRecord(final JsonObject item) {
final String name = item.getString(NAME);
final String host = item.getString(HOST);
final Integer port = item.getInteger(PORT);
final JsonObject meta = item.getJsonObject(META);
return HttpEndpoint.createRecord(
name, host, port, "/*", meta
);
}
示例14: VertxPrometheusOptions
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public VertxPrometheusOptions(@NotNull JsonObject json) {
super(json);
host = json.getString("host", DEFAULT_HOST);
port = json.getInteger("port", DEFAULT_PORT);
metrics = EnumSet.noneOf(MetricsType.class);
for (Object metric : json.getJsonArray("metrics", EMPTY_METRICS).getList()) {
metrics.add(MetricsType.valueOf(metric.toString()));
}
}
示例15: queryTimeSeries
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
* Searches datapoints within range and for selected targets
*
* @param msg
*/
void queryTimeSeries(final Message<JsonObject> msg) {
long start = System.currentTimeMillis();
final JsonObject query = msg.body();
LOG.debug("{}\n{}", address, query.encodePrettily());
// get the paramsters from the query
final Range range = rangeParser.parse(query.getJsonObject("range").getString("from"),
query.getJsonObject("range").getString("to"));
final Integer limit = query.getInteger("maxDataPoints");
final String interval = query.getString("interval");
List<Future> futures = range.split(numChunks)
.stream()
.map(rc -> Tuple.of(obj().put("range",
obj().put("from", rc.getStartString())
.put("to", rc.getEndString()))
.put("interval", interval)
.put("maxDataPoints", limit / numChunks)
.put("targets", query.getJsonArray("targets")),
Future.<Message<JsonObject>>future()))
.map(tup -> {
vertx.eventBus()
.send(queryChunkAddress, tup.getFirst(), tup.getSecond().completer());
return tup.getSecond();
})
.collect(toList());
CompositeFuture.all(futures).setHandler(result -> {
if (result.succeeded()) {
JsonArray rawResult = result.result()
.list()
.stream()
.map(o -> (Message) o)
.map(m -> (JsonArray) m.body())
.collect(toMergedResult());
// POST Processing if registered
if (this.postProcessingAddress != null) {
vertx.eventBus().send(this.postProcessingAddress, rawResult, ppReply -> {
if (ppReply.succeeded()) {
sendReply(msg, rawResult.addAll((JsonArray) ppReply.result().body()), start);
} else {
LOG.error("PostProcessing failed", ppReply.cause());
sendReply(msg, rawResult, start);
this.postProcessingAddress = null;
}
});
} else {
sendReply(msg, rawResult, start);
}
} else {
LOG.warn("Could not process query", result.cause());
}
});
}