List of usage examples for javax.json JsonObject getInt
int getInt(String name);
From source file:com.amazon.alexa.avs.auth.companionapp.OAuth2ClientForPkce.java
/** * Uses the LWA service to fetch an access token and refresh token in exchange for a refresh token and clientId. * Expected use case of this method: refreshing tokens once the initial provisioning is complete and normal * usage of the device is ready to commence. * * @param refreshToken received from the initial provisioning request * @param clientId of the security profile associated with the companion app * @return {@link OAuth2AccessToken} object containing the access token and refresh token * @throws IOException//from w w w. ja v a 2s . c om */ public OAuth2TokensForPkce exchangeRefreshTokenForTokens(String refreshToken, String clientId) throws IOException { HttpURLConnection connection = (HttpURLConnection) tokenEndpoint.openConnection(); JsonObject data = prepareExchangeRefreshTokenForTokensData(refreshToken, clientId); JsonObject jsonObject = postRequest(connection, data.toString()); String newAccessToken = jsonObject.getString(AuthConstants.OAuth2.ACCESS_TOKEN); String newRefreshToken = jsonObject.getString(AuthConstants.OAuth2.REFRESH_TOKEN); int expiresIn = jsonObject.getInt(AuthConstants.OAuth2.EXPIRES_IN); return new OAuth2TokensForPkce(clientId, newAccessToken, newRefreshToken, expiresIn); }
From source file:com.amazon.alexa.avs.auth.companionapp.OAuth2ClientForPkce.java
/** * Uses the LWA service to fetch an access token and refresh token in exchange for an auth code * (and a few other relevant parameter). Expected use case of this method: once we receive a * message/notification from the companion app with the authCode, this method will be used to * hit LWA and return tokens. These tokens can then be used to access AVS. * * @param authCode provided by the companion application * @param redirectUri corresponding to the companion application * @param clientId of the security profile associated with the companion app * @param codeVerifier unique value known to the device * @return {@link OAuth2AccessToken} object containing the access token and refresh token * @throws IOException/*from w w w . j a va 2 s . c o m*/ */ public OAuth2TokensForPkce exchangeAuthCodeForTokens(String authCode, String redirectUri, String clientId, String codeVerifier) throws IOException { HttpURLConnection connection = (HttpURLConnection) tokenEndpoint.openConnection(); JsonObject data = prepareExchangeAuthCodeForTokensData(authCode, redirectUri, clientId, codeVerifier); JsonObject jsonObject = postRequest(connection, data.toString()); String newAccessToken = jsonObject.getString(AuthConstants.OAuth2.ACCESS_TOKEN); String newRefreshToken = jsonObject.getString(AuthConstants.OAuth2.REFRESH_TOKEN); int expiresIn = jsonObject.getInt(AuthConstants.OAuth2.EXPIRES_IN); return new OAuth2TokensForPkce(clientId, newAccessToken, newRefreshToken, expiresIn); }
From source file:sample.products.java
@POST @Consumes("application/json") public void postData(String str) { JsonObject json = Json.createReader(new StringReader(str)).readObject(); //System.out.println(json.getInt("id") + ": " + json.getString("name")); int id1 = json.getInt("id"); String id = String.valueOf(id1); String name = json.getString("name"); String description = json.getString("description"); int qty1 = json.getInt("qty"); String qty = String.valueOf(qty1); System.out.println(id + name + description + qty); doUpdate("INSERT INTO PRODUCT (productId, name, description, quantity) VALUES (?, ?, ?, ?)", id, name, description, qty);/*from w ww. ja v a2 s . c o m*/ }
From source file:sample.products.java
@PUT @Consumes("application/json") public void putData(String str) { JsonObject json = Json.createReader(new StringReader(str)).readObject(); //System.out.println(json.getInt("id") + ": " + json.getString("name")); int id1 = json.getInt("id"); String id = String.valueOf(id1); String name = json.getString("name"); String description = json.getString("description"); int qty1 = json.getInt("qty"); String qty = String.valueOf(qty1); System.out.println(id + name + description + qty); doUpdate("UPDATE PRODUCT SET productId= ?, name = ?, description = ?, quantity = ? WHERE productId = ?", id, name, description, qty, id); }
From source file:ro.cs.products.landsat.LandsatSearch.java
public List<ProductDescriptor> execute() throws IOException { List<ProductDescriptor> results = new ArrayList<>(); String queryUrl = getQuery(); Logger.getRootLogger().info(queryUrl); try (CloseableHttpResponse response = NetUtils.openConnection(queryUrl, credentials)) { switch (response.getStatusLine().getStatusCode()) { case 200: String body = EntityUtils.toString(response.getEntity()); final JsonReader jsonReader = Json.createReader(new StringReader(body)); Logger.getRootLogger().debug("Parsing json response"); JsonObject responseObj = jsonReader.readObject(); JsonArray jsonArray = responseObj.getJsonArray("results"); for (int i = 0; i < jsonArray.size(); i++) { LandsatProductDescriptor currentProduct = new LandsatProductDescriptor(); JsonObject result = jsonArray.getJsonObject(i); currentProduct.setName(result.getString("scene_id")); currentProduct.setId(result.getString("sceneID")); currentProduct.setPath(String.valueOf(result.getInt("path"))); currentProduct.setRow(String.valueOf(result.getInt("row"))); currentProduct.setSensingDate(result.getString("acquisitionDate")); results.add(currentProduct); }//from w ww .j av a2 s . c o m break; case 401: Logger.getRootLogger().info("The supplied credentials are invalid!"); break; default: Logger.getRootLogger().info("The request was not successful. Reason: %s", response.getStatusLine().getReasonPhrase()); break; } } Logger.getRootLogger().info("Query returned %s products", results.size()); return results; }
From source file:sample.products.java
@PUT @Path("{id}") @Consumes("application/json") public void putData(String str, @PathParam("id") int id1) { JsonObject json = Json.createReader(new StringReader(str)).readObject(); String id = String.valueOf(id1); String name = json.getString("name"); String description = json.getString("description"); String qty = String.valueOf(json.getInt("qty")); doUpdate("UPDATE PRODUCT SET productId= ?, name = ?, description = ?, quantity = ? WHERE productId = ?", id, name, description, qty, id); }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
/** * delete an identity// w w w . j a va 2 s. 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 adding an identity fails. * @throws InvalidArgumentException Invalid (null) argument specified */ public int delete(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String deleteURL = ""; try { deleteURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId()); logger.debug(format("identity url: %s, registrar: %s", deleteURL, registrar.getName())); JsonObject result = client.httpDelete(deleteURL, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", deleteURL, registrar)); } this.deleted = true; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while deleting user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), deleteURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while deleting user '%s' from url '%s': %s", getEnrollmentId(), deleteURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
/** * create an identity/*from ww w. j av a2s . co m*/ * * @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 creating an identity fails. * @throws InvalidArgumentException Invalid (null) argument specified */ public int create(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String createURL = ""; try { createURL = client.getURL(HFCA_IDENTITY); logger.debug(format("identity url: %s, registrar: %s", createURL, registrar.getName())); String body = client.toJson(idToJsonObject()); JsonObject result = client.httpPost(createURL, body, registrar); statusCode = result.getInt("statusCode"); if (statusCode >= 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", createURL, registrar)); } this.deleted = false; return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while creating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), createURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while creating user '%s' from url '%s': %s", getEnrollmentId(), createURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
/** * update an identity/*from w w w .j a va 2 s. 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 adding an identity fails. * @throws InvalidArgumentException Invalid (null) argument specified */ public int update(User registrar) throws IdentityException, InvalidArgumentException { if (this.deleted) { throw new IdentityException("Identity has been deleted"); } if (registrar == null) { throw new InvalidArgumentException("Registrar should be a valid member"); } String updateURL = ""; try { updateURL = client.getURL(HFCA_IDENTITY + "/" + getEnrollmentId()); logger.debug(format("identity url: %s, registrar: %s", updateURL, registrar.getName())); String body = client.toJson(idToJsonObject()); JsonObject result = client.httpPut(updateURL, body, registrar); statusCode = result.getInt("statusCode"); if (statusCode < 400) { getHFCAIdentity(result); logger.debug(format("identity url: %s, registrar: %s done.", updateURL, registrar)); } return statusCode; } catch (HTTPException e) { String msg = format("[Code: %d] - Error while updating user '%s' from url '%s': %s", e.getStatusCode(), getEnrollmentId(), updateURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } catch (Exception e) { String msg = format("Error while updating user '%s' from url '%s': %s", getEnrollmentId(), updateURL, e.getMessage()); IdentityException identityException = new IdentityException(msg, e); logger.error(msg); throw identityException; } }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
/** * read retrieves a specific identity// ww w .j a v a2s.c o m * * @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; } }