本文整理匯總了Java中io.vertx.core.json.JsonObject.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonObject.getString方法的具體用法?Java JsonObject.getString怎麽用?Java JsonObject.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.getString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
});
}
示例2: AuthMgr
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public AuthMgr(JsonObject conf,AppContain app){
this.authenticationUrl = conf.getString("authentication");
this.authorisationUrl = conf.getString("authorisation");
this.mainpage = conf.getString("mainpage");
this.successFiled = conf.getString("successfield","userid");
this.loginpage = conf.getString("loginpage");
String authapp = conf.getString("app");
String sufix = conf.getString("exclude.end");
String noauthpath = conf.getString("exclude.start");
this.setNotAuthSufix(sufix);
this.setNoAuthPaths(noauthpath);
if(S.isNotBlank(this.loginpage))
this.addNoAuthPath(this.loginpage);
this.authApp = app.getAppInfo(authapp);
this.authenticationUrl = this.authApp.offsetUrl(this.authenticationUrl);
this.authorisationUrl = this.authApp.offsetUrl(this.authorisationUrl);
this.authProvider = new GateAuthProvider(this);
}
示例3: generate
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public void generate(Message<JsonObject> message) {
JsonObject metadata = message.body();
String build = metadata.getString("build", "maven");
String language = metadata.getString("language", "java");
//Act as a activation flags in .gitignore
metadata.put(build, true);
metadata.put(language, true);
String baseDir = metadata.getString("baseDir");
CompositeFuture.all(
generateFile(metadata, baseDir, BUILD.get(build)),
generateFile(metadata, baseDir, LANGUAGES.get(language)),
generateFile(metadata, baseDir, ".gitignore"),
generateFile(metadata, baseDir, ".editorconfig")
).setHandler(ar -> {
if (ar.failed()) {
log.error("Impossible to generate project {} : {}", metadata, ar.cause().getMessage());
message.fail(500, ar.cause().getMessage());
} else {
message.reply(null);
}
});
}
示例4: computeResponse
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private void computeResponse(RoutingContext rc) {
JsonObject json = rc.getBodyAsJson();
String name = json.getString("name");
Double price = prices.computeIfAbsent(name, k -> (double) random.nextInt(50));
Integer q = Integer.parseInt(json.getString("quantity", "1"));
rc.response().end(new JsonObject()
.put("name", name)
.put("price", price)
.put("quantity", json.getString("quantity", "1"))
.put("total", "" + (price * q))
.encodePrettily());
}
示例5: 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);
});
}
示例6: sell
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@Override
public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
if (amount <= 0) {
resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " +
"greater than 0"));
return;
}
double price = amount * quote.getDouble("bid");
String name = quote.getString("name");
int current = portfolio.getAmount(name);
// 1) do we have enough stocks
if (current >= amount) {
// Yes, sell it
int newAmount = current - amount;
if (newAmount == 0) {
portfolio.getShares().remove(name);
} else {
portfolio.getShares().put(name, newAmount);
}
portfolio.setCash(portfolio.getCash() + price);
sendActionOnTheEventBus("SELL", amount, quote, newAmount);
resultHandler.handle(Future.succeededFuture(portfolio));
} else {
resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " +
"in portfolio"));
}
}
示例7: handleMsg
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@Override
public void handleMsg(Buffer data) {
JsonObject j = data.toJsonObject();
String msgType = j.getString(GossipMessageFactory.KEY_MSG_TYPE);
String _data = j.getString(GossipMessageFactory.KEY_DATA);
String cluster = j.getString(GossipMessageFactory.KEY_CLUSTER);
String from = j.getString(GossipMessageFactory.KEY_FROM);
if (StringUtil.isNullOrEmpty(cluster) || !GossipManager.getInstance().getCluster().equals(cluster)) {
LOGGER.error("This message shouldn't exist my world!" + data.toString());
return;
}
MessageHandler handler = null;
MessageType type = MessageType.valueOf(msgType);
if (type == MessageType.SYNC_MESSAGE) {
handler = new SyncMessageHandler();
} else if (type == MessageType.ACK_MESSAGE) {
handler = new AckMessageHandler();
} else if (type == MessageType.ACK2_MESSAGE) {
handler = new Ack2MessageHandler();
} else if (type == MessageType.SHUTDOWN) {
handler = new ShutdownMessageHandler();
} else {
LOGGER.error("Not supported message type");
}
if (handler != null) {
handler.handle(cluster, _data, from);
}
}
示例8: getRecord
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
static Record getRecord(final JsonObject config) {
/** Config Verify **/
Fn.flingUp(() -> Fn.shuntZero(() -> Ruler.verify(Key.RULE_KEY, config), config),
LOGGER);
// Connect remote etcd to check service
final ConcurrentMap<String, Record> registryData = ORIGIN.getRegistryData();
final String name = config.getString(Key.NAME);
final String address = config.getString(Key.ADDR);
LOGGER.debug(Info.RPC_SERVICE, name, address);
// Empty Found
Fn.flingWeb(registryData.values().isEmpty(), LOGGER,
_424RpcServiceException.class, RpcHelper.class,
name, address);
// Service status checking
final RxHod container = new RxHod();
// Lookup Record instance
Observable.fromIterable(registryData.values())
.filter(Objects::nonNull)
.filter(item -> StringUtil.notNil(item.getName()))
.filter(item -> name.equals(item.getName()) &&
address.equals(item.getMetadata().getString(Key.PATH)))
.subscribe(container::add);
// Service Not Found
Fn.flingWeb(!container.successed(), LOGGER,
_424RpcServiceException.class, RpcHelper.class,
name, address);
// Address Not Found
Fn.flingWeb(!container.successed(), LOGGER,
_424RpcServiceException.class, RpcHelper.class,
name, address);
final Record record = container.get();
LOGGER.debug(Info.RPC_FOUND, record.toJson());
return container.get();
}
示例9: FakeSourceImpl
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public FakeSourceImpl(JsonObject json) {
super(Flowable.fromIterable(
json.getJsonArray("items").getList()).map(Data::new)
);
name = json.getString("name");
}
示例10: alipayRefund
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
* 支付寶退款接口;
*
* @param bizContent 支付寶退款接口的業務內容請求JSON實例
* @param acc 企業用戶賬戶對象
* 異步返回 是否調用成功
*
* @author Leibniz
*/
public void alipayRefund(RefundBizContent bizContent, JsonObject acc, String successUrl, Handler<Boolean> callback) {
String bizContentStr = bizContent.toString(); // 將參數bizContent轉成字符串
// 檢查bizContent是否合法
if (!bizContent.checkParameters()) {
throw new IllegalArgumentException("錯誤的支付寶退款接口請求業務JSON:" + bizContentStr); // 拋出異常
}
String notifyUrl = zfbPayNotifyUrl; // 服務器後台回調通知的url
AliAccountInfo aliAccountInfo = new AliAccountInfo(acc.getString(ZFBAPPID), acc.getString(ZFBPRIVKEY), acc.getString(ZFBPUBKEY), successUrl, notifyUrl, null); // 該對象保存了支付寶賬號的相關信息,以及請求回調地址
AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 獲取支付寶連接
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); // 創建退款請求
request.setBizContent(bizContentStr); // 設置請求的bizContent
AlipayTradeRefundResponse response = null;
try {
response = alipayClient.execute(request); // 發送退款請求並獲得響應
} catch (AlipayApiException e) { // 捕捉異常
log.error("調用支付寶退款接口時拋出異常,請求的JSON:" + bizContentStr, e); // 打日誌
}
// 判斷是否有響應
if (response != null) { // 響應成功
// 判斷退款是否成功
if (response.isSuccess()) { // 退款成功
log.info("調用成功"); // 打日誌
callback.handle(true);
// 退款成功,其他都是錯
} else { // 退款失敗
log.error("調用支付寶退款接口錯誤,code={},msg={},sub_code={},sub_msg={}", response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg()); // 打日誌
callback.handle(false);
}
} else { // 響應失敗
log.error("調用支付寶退款接口時發生異常,返回響應對象為null!{}", bizContentStr); // 打日誌
callback.handle(false);
}
}
示例11: create
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@Override
public <T> Single<Source<T>> create(Vertx vertx, JsonObject json) {
String address = json.getString("address");
if (address == null) {
String name = json.getString("name");
if (name != null) {
json.put("address", name);
} else {
throw new IllegalArgumentException("Either address or name must be set");
}
}
return Single.just(new EventBusSource<>(vertx, json));
}
示例12: CamelSink
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public CamelSink(JsonObject config) {
endpoint = config.getString("endpoint");
camelContext = new DefaultCamelContext();
try {
camelContext.start();
producerTemplate = camelContext.createProducerTemplate();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例13: parseSubMenus
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
protected void parseSubMenus (Menu menu, JsonArray jsonArray) {
for (int i = 0; i < jsonArray.size(); i++) {
//get json object
JsonObject entry = jsonArray.getJsonObject(i);
//get event and title
String event = entry.getString("event");
String title = entry.getString("title");
//create new menu item
MenuItem menuItem = new MenuItem(title);
//add click handler
menuItem.setOnAction(event1 -> {
System.out.println("open activitiy: " + event);
EventBus.getInstance().raiseEvent("open_activity", event);
});
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN));
//check for shortcut
if (entry.containsKey("shortcut") && !entry.getString("shortcut").isEmpty()) {
String keys[] = entry.getString("shortcut").split("\\+");
if (keys.length > 1) {
KeyCombination.Modifier modifier = null;
if (keys[1].equals("SHIFT_DOWN")) {
modifier = KeyCombination.SHIFT_DOWN;
} else {
throw new UnsupportedOperationException("Unsupported key code: " + keys[1]);
}
//KeyCombination combination = KeyCombination.keyCombination(keys[1]);
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(keys[0]), modifier));
} else if (keys.length == 1) {
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(keys[0])));
} else {
//no shortcut is set
}
}
//add menu item to menu
menu.getItems().add(menuItem);
}
}
示例14: getAuthenticationData
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public static String getAuthenticationData(JsonObject user) {
return "username=" + user.getString("username") +
"&password=" + user.getString("password") +
"&client_name=FormClient";
}
示例15: getID
import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
private String getID(final Record record) {
final JsonObject metadata = record.getMetadata();
return metadata.getString(Origin.ID);
}