List of usage examples for javax.json JsonObject getBoolean
boolean getBoolean(String name, boolean defaultValue);
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
private void getHFCAIdentity(JsonObject result) { type = result.getString("type"); if (result.containsKey("secret")) { this.secret = result.getString("secret"); }//from w w w . j a v a 2 s.c o m maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
/** * read retrieves a specific identity/*from w w w . j a v a2s .c om*/ * * @param registrar The identity of the registrar (i.e. who is performing the registration). * @return statusCode The HTTP status code in the response * @throws IdentityException if retrieving an identity fails. * @throws InvalidArgumentException Invalid (null) argument specified */ public int read(User registrar) throws IdentityException, InvalidArgumentException { if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String readIdURL = ""; try { readIdURL = HFCA_IDENTITY + "/" + enrollmentID; logger.debug(format("identity url: %s, registrar: %s", readIdURL, registrar.getName())); JsonObject result = client.httpGet(readIdURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { type = result.getString("type"); maxEnrollments = result.getInt("max_enrollments"); affiliation = result.getString("affiliation"); JsonArray attributes = result.getJsonArray("attrs"); Collection<Attribute> attrs = new ArrayList<Attribute>(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0; i < attributes.size(); i++) { JsonObject attribute = attributes.getJsonObject(i); Attribute attr = new Attribute(attribute.getString("name"), attribute.getString("value"), attribute.getBoolean("ecert", false)); attrs.add(attr); } } this.attrs = attrs; logger.debug(format("identity url: %s, registrar: %s done.", readIdURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while getting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while getting user '%s' from url '%s': %s", enrollmentID, readIdURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcAddress jsonAddress(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//from w w w .j a va2 s. c o m BtcAddress address = new BtcAddress(); address.setValid(object.getBoolean(BTCOBJ_ADDRESS_VALID, false)); address.setAddress(object.getString(BTCOBJ_ADDRESS_ADDRESS, "")); address.setMine(object.getBoolean(BTCOBJ_ADDRESS_MINE, false)); address.setScript(object.getBoolean(BTCOBJ_ADDRESS_SCRIPT, false)); address.setPublicKey(object.getString(BTCOBJ_ADDRESS_PUBLIC_KEY, "")); address.setCompressed(object.getBoolean(BTCOBJ_ADDRESS_COMPRESSED, false)); BtcAccount account = new BtcAccount(); account.setAccount(object.getString(BTCOBJ_ADDRESS_ACCOUNT, "")); address.setAccount(account); address.setAmount(jsonDouble(object, BTCOBJ_ADDRESS_AMOUNT)); address.setConfirmations(jsonLong(object, BTCOBJ_ADDRESS_CONFIRMATIONS)); return address; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcAddedNode jsonAddedNode(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/*w w w . jav a 2 s . co m*/ BtcAddedNode addedNode = new BtcAddedNode(); addedNode.setAddedNode(object.getString(BTCOBJ_NODE_ADDED_NODE, "")); addedNode.setConnected(object.getBoolean(BTCOBJ_NODE_CONNECTED, false)); List<BtcNode> nodes = new ArrayList<BtcNode>(); JsonValue addresses = object.get(BTCOBJ_NODE_ADDRESSES); if ((addresses != null) && (addresses.getValueType() == JsonValue.ValueType.ARRAY) && (addresses instanceof JsonArray)) { JsonArray addressesArray = (JsonArray) addresses; for (JsonValue address : addressesArray.getValuesAs(JsonValue.class)) { nodes.add(jsonNode(address)); } } addedNode.setAddresses(nodes); return addedNode; }
From source file:com.buffalokiwi.aerodrome.jet.orders.OrderRec.java
/** * Turn Jet Json into an OrderRec/*w ww . ja va 2 s . com*/ * @param json Jet json * @return object */ public static OrderRec fromJson(final JsonObject json) { Utils.checkNull(json, "json"); final Builder b = new Builder().setMerchantOrderId(json.getString("merchant_order_id", "")) .setReferenceOrderId(json.getString("reference_order_id", "")) .setCustomerReferenceOrderId(json.getString("customer_reference_order_id", "")) .setFulfillmentNode(json.getString("fulfillment_node", "")) .setAltOrderId(json.getString("alt_order_id", "")).setHashEmail(json.getString("hash_email", "")) .setStatus(OrderStatus.fromText(json.getString("status", ""))) .setExceptionState(OrderExceptionState.fromText(json.getString("exception_state", ""))) .setOrderPlacedDate(JetDate.fromJetValueOrNull(json.getString("order_placed_date", ""))) .setOrderTransmissionDate(JetDate.fromJetValueOrNull(json.getString("order_transmission_date", ""))) .setJetRequestDirectedCancel(json.getBoolean("jet_requested_directed_cancel", false)) .setOrderReadyDate(JetDate.fromJetValueOrNull(json.getString("order_ready_date", ""))) .setHasShipments(json.getBoolean("has_shipments", false)) .setOrderAckDate(JetDate.fromJetValueOrNull(json.getString("order_acknowledge_date", ""))) .setAckStatus(AckStatus.fromText(json.getString("acknowledgement_status", ""))); buildOrderDetail(b, json.getJsonObject("order_detail")); buildBuyer(b, json.getJsonObject("buyer")); buildShipTo(b, json.getJsonObject("shipping_to")); buildOrderTotals(b, json.getJsonObject("order_totals")); try { buildOrderItems(b, json.getJsonArray("order_items")); } catch (JetException e) { APILog.error(LOG, e, "Failed to generate order items"); } //..Build the shipments final JsonArray shipments = json.getJsonArray("shipments"); if (shipments != null) { for (int i = 0; i < shipments.size(); i++) { final JsonObject shipment = shipments.getJsonObject(i); if (shipment == null) continue; b.getShipments().add(ShipmentRec.fromJson(shipment)); } } return new OrderRec(b); }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcMiningInfo jsonMiningInfo(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/*from w w w .j a v a 2s .c o m*/ BtcMiningInfo info = new BtcMiningInfo(); info.setBlocks(jsonLong(object, BTCOBJ_INFO_BLOCKS)); info.setCurrentBlockSize(jsonLong(object, BTCOBJ_INFO_CURRENT_BLOCK_SIZE)); info.setCurrentBlockTransactions(jsonLong(object, BTCOBJ_INFO_CURRENT_BLOCK_TRANSACTIONS)); info.setDifficulty(jsonDouble(object, BTCOBJ_INFO_DIFFICULTY)); info.setErrors(object.getString(BTCOBJ_INFO_ERRORS, "")); info.setGenerate(object.getBoolean(BTCOBJ_INFO_GENERATE, false)); info.setGenProcessorLimit(jsonLong(object, BTCOBJ_INFO_PROCESSOR_LIMIT, -1)); info.setHashesPerSecond(jsonLong(object, BTCOBJ_INFO_HASHES_PER_SECOND)); info.setPooledTransactions(jsonLong(object, BTCOBJ_INFO_POOLED_TRANSACTIONS)); info.setTestnet(object.getBoolean(BTCOBJ_INFO_TESTNET, false)); return info; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcInfo jsonInfo(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//from w w w .j a v a2s. com BtcInfo info = new BtcInfo(); info.setVersion(jsonLong(object, BTCOBJ_INFO_VERSION)); info.setProtocolVersion(jsonLong(object, BTCOBJ_INFO_PROTOCOL_VERSION)); info.setWalletVersion(jsonLong(object, BTCOBJ_INFO_WALLET_VERSION)); info.setBalance(jsonDouble(object, BTCOBJ_INFO_BALANCE)); info.setBlocks(jsonLong(object, BTCOBJ_INFO_BLOCKS)); info.setTimeOffset(jsonLong(object, BTCOBJ_INFO_TIME_OFFSET)); info.setConnections(jsonLong(object, BTCOBJ_INFO_CONNECTIONS)); info.setProxy(object.getString(BTCOBJ_INFO_PROXY, "")); info.setDifficulty(jsonDouble(object, BTCOBJ_INFO_DIFFICULTY)); info.setTestnet(object.getBoolean(BTCOBJ_INFO_TESTNET, false)); info.setKeyPoolOldest(jsonLong(object, BTCOBJ_INFO_KEYPOOL_OLDEST)); info.setKeyPoolSize(jsonLong(object, BTCOBJ_INFO_KEYPOOL_SIZE)); info.setTransactionFee(jsonDouble(object, BTCOBJ_INFO_TRANSACTION_FEE)); info.setErrors(object.getString(BTCOBJ_INFO_ERRORS, "")); return info; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcPeer jsonPeer(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }/* w w w .jav a 2 s .c om*/ BtcPeer peer = new BtcPeer(); peer.setNetworkAddress(object.getString(BTCOBJ_PEER_ADDRESS, "")); peer.setServices(object.getString(BTCOBJ_PEER_SERVICES, "")); peer.setLastSend(jsonLong(object, BTCOBJ_PEER_LAST_SEND)); peer.setLastReceived(jsonLong(object, BTCOBJ_PEER_LAST_RECEIVED)); peer.setBytesSent(jsonLong(object, BTCOBJ_PEER_BYTES_SENT)); peer.setBytesReceived(jsonLong(object, BTCOBJ_PEER_BYTES_RECEIVED)); peer.setConnectionTime(jsonLong(object, BTCOBJ_PEER_CONNECTION_TIME)); peer.setVersion(jsonLong(object, BTCOBJ_PEER_VERSION)); peer.setSubVersion(object.getString(BTCOBJ_PEER_SUBVERSION, "")); peer.setInbound(object.getBoolean(BTCOBJ_PEER_INBOUND, false)); peer.setStartingHeight(jsonLong(object, BTCOBJ_PEER_START_HEIGHT)); peer.setBanScore(jsonLong(object, BTCOBJ_PEER_BAN_SCORE)); peer.setSyncNode(object.getBoolean(BTCOBJ_PEER_SYNC_NODE, false)); return peer; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public BtcOutput jsonOutput(JsonValue value) throws BtcException { JsonObject object = jsonObject(value); if (object == null) { return null; }//from w w w .ja v a 2s. co m BtcOutput output = new BtcOutput(); output.setTransaction(object.getString(BTCOBJ_TX_OUTPUT_TRANSACTION, "")); output.setBestBlock(object.getString(BTCOBJ_TX_OUTPUT_BEST_BLOCK, "")); output.setConfirmations(jsonLong(object, BTCOBJ_TX_OUTPUT_CONFIRMATIONS)); output.setValue(jsonDouble(object, BTCOBJ_TX_OUTPUT_VALUE)); output.setIndex(jsonLong(object, BTCOBJ_TX_OUTPUT_INDEX)); output.setOutput(jsonLong(object, BTCOBJ_TX_OUTPUT_OUTPUT)); JsonValue scriptPubKey = object.get(BTCOBJ_TX_OUTPUT_SCRIPT_PUBLIC_KEY); if (scriptPubKey != null) { if ((scriptPubKey.getValueType() == JsonValue.ValueType.OBJECT) && (scriptPubKey instanceof JsonObject)) { output.setScript(jsonScript(scriptPubKey)); } if ((scriptPubKey.getValueType() == JsonValue.ValueType.STRING) && (scriptPubKey instanceof JsonString)) { BtcScript script = new BtcScript(); script.setPublicKey(jsonString(scriptPubKey)); output.setScript(script); } } output.setVersion(jsonLong(object, BTCOBJ_TX_OUTPUT_VERSION)); output.setCoinbase(object.getBoolean(BTCOBJ_TX_OUTPUT_COINBASE, false)); output.setDetail(jsonTransactionDetail(object)); return output; }
From source file:com.amazon.alexa.avs.config.DeviceConfigUtils.java
/** * Reads the {@link DeviceConfig} from disk. Pass in the name of the config file * * @return The configuration./*from w w w . j av a2s . co m*/ */ public static DeviceConfig readConfigFile(String filename) { FileInputStream file = null; try { deviceConfigName = filename.trim(); file = new FileInputStream(deviceConfigName); JsonReader json = Json.createReader(file); JsonObject configObject = json.readObject(); JsonObject companionServiceObject = configObject.getJsonObject(DeviceConfig.COMPANION_SERVICE); CompanionServiceInformation companionServiceInfo = null; if (companionServiceObject != null) { String serviceUrl = companionServiceObject .getString(DeviceConfig.CompanionServiceInformation.SERVICE_URL, null); String sessionId = companionServiceObject .getString(DeviceConfig.CompanionServiceInformation.SESSION_ID, null); String sslClientKeyStore = companionServiceObject .getString(DeviceConfig.CompanionServiceInformation.SSL_CLIENT_KEYSTORE, null); String sslClientKeyStorePassphrase = companionServiceObject .getString(DeviceConfig.CompanionServiceInformation.SSL_CLIENT_KEYSTORE_PASSPHRASE, null); String sslCaCert = companionServiceObject .getString(DeviceConfig.CompanionServiceInformation.SSL_CA_CERT, null); companionServiceInfo = new CompanionServiceInformation(serviceUrl, sslClientKeyStore, sslClientKeyStorePassphrase, sslCaCert); companionServiceInfo.setSessionId(sessionId); } JsonObject companionAppObject = configObject.getJsonObject(DeviceConfig.COMPANION_APP); CompanionAppInformation companionAppInfo = null; if (companionAppObject != null) { int localPort = companionAppObject.getInt(DeviceConfig.CompanionAppInformation.LOCAL_PORT, -1); String lwaUrl = companionAppObject.getString(DeviceConfig.CompanionAppInformation.LWA_URL, null); String clientId = companionAppObject.getString(DeviceConfig.CompanionAppInformation.CLIENT_ID, null); String refreshToken = companionAppObject .getString(DeviceConfig.CompanionAppInformation.REFRESH_TOKEN, null); String sslKeyStore = companionAppObject.getString(DeviceConfig.CompanionAppInformation.SSL_KEYSTORE, null); String sslKeyStorePassphrase = companionAppObject .getString(DeviceConfig.CompanionAppInformation.SSL_KEYSTORE_PASSPHRASE, null); companionAppInfo = new CompanionAppInformation(localPort, lwaUrl, sslKeyStore, sslKeyStorePassphrase); companionAppInfo.setClientId(clientId); companionAppInfo.setRefreshToken(refreshToken); } String productId = configObject.getString(DeviceConfig.PRODUCT_ID, null); String dsn = configObject.getString(DeviceConfig.DSN, null); String provisioningMethod = configObject.getString(DeviceConfig.PROVISIONING_METHOD, null); String avsHost = configObject.getString(DeviceConfig.AVS_HOST, null); boolean wakeWordAgentEnabled = configObject.getBoolean(DeviceConfig.WAKE_WORD_AGENT_ENABLED, false); String locale = configObject.getString(DeviceConfig.LOCALE, null); DeviceConfig deviceConfig = new DeviceConfig(productId, dsn, provisioningMethod, wakeWordAgentEnabled, locale, companionAppInfo, companionServiceInfo, avsHost); return deviceConfig; } catch (FileNotFoundException e) { throw new RuntimeException("The required file " + deviceConfigName + " could not be opened.", e); } finally { IOUtils.closeQuietly(file); } }