List of usage examples for javax.json JsonObject getString
String getString(String name);
From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavendependency.MavenDependencyEditAction.java
@Override public void handle(Request request, Response response) throws Exception { JsonReader jsonReader = Json/*from www. j av a2 s .co m*/ .createReader(new StringReader(request.param(MavenDependencyConfiguration.PARAM))); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close(); boolean oldKeyIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_OLD_KEY)); boolean newKeyIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_NEW_KEY)); boolean newLicenseIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_NEW_LICENSE)); if (oldKeyIsNotBlank && newKeyIsNotBlank && newLicenseIsNotBlank) { MavenDependency newMavenDependency = new MavenDependency( jsonObject.getString(MavenDependencyConfiguration.PROPERTY_NEW_KEY), jsonObject.getString(MavenDependencyConfiguration.PROPERTY_NEW_LICENSE)); if (!mavenDependencySettingsService.hasDependency(newMavenDependency)) { mavenDependencySettingsService .deleteMavenDependency(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_OLD_KEY)); mavenDependencySettingsService.addMavenDependency(newMavenDependency); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK); LOGGER.info(MavenDependencyConfiguration.INFO_EDIT_SUCCESS + jsonObject.toString()); } else { LOGGER.error(MavenDependencyConfiguration.ERROR_EDIT_ALREADY_EXISTS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } } else { LOGGER.error(MavenDependencyConfiguration.ERROR_ADD_INVALID_INPUT + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } }
From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavenlicense.MavenLicenseEditAction.java
@Override public void handle(Request request, Response response) throws Exception { JsonReader jsonReader = Json.createReader(new StringReader(request.param(MavenLicenseConfiguration.PARAM))); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close();/*from ww w . ja v a2 s . c om*/ boolean oldRegexIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_OLD_REGEX)); boolean newRegexIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_NEW_REGEX)); boolean newKeyIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_NEW_KEY)); if (oldRegexIsNotBlank && newRegexIsNotBlank && newKeyIsNotBlank) { MavenLicense newMavenLicense = new MavenLicense( jsonObject.getString(MavenLicenseConfiguration.PROPERTY_NEW_REGEX), jsonObject.getString(MavenLicenseConfiguration.PROPERTY_NEW_KEY)); if (!mavenLicenseSettingsService.checkIfListContains(newMavenLicense)) { mavenLicenseSettingsService .deleteMavenLicense(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_OLD_REGEX)); mavenLicenseSettingsService.addMavenLicense(newMavenLicense); mavenLicenseSettingsService.sortMavenLicenses(); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK); LOGGER.info(MavenLicenseConfiguration.INFO_EDIT_SUCCESS + jsonObject.toString()); } else { LOGGER.error(MavenLicenseConfiguration.ERROR_EDIT_ALREADY_EXISTS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } } else { LOGGER.error(MavenLicenseConfiguration.ERROR_EDIT_INVALID_INPUT + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } }
From source file:com.natixis.appdynamics.traitements.GetInfoLicense.java
public Map<String, Object> RetrieveInfoLicense() throws ClientProtocolException, IOException { Map<String, Object> myMapInfoLicense = new HashMap<String, Object>(); HttpClient client = new DefaultHttpClient(); String[] chaineUrl = GetParamApplication.urlApm.split("/" + "/"); String hostApm = chaineUrl[1]; URI uri = null;/*from www .j a v a 2s . co m*/ try { uri = new URIBuilder().setScheme("http").setHost(hostApm).setPath(GetParamApplication.uriInfoLicense) .setParameter("startdate", GetDateInfoLicence()).setParameter("enddate", GetDateInfoLicence()) .build(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(hostApm, 80), new UsernamePasswordCredentials(GetParamApplication.userApm, GetParamApplication.passwordApm)); HttpGet request = new HttpGet(uri); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); String jsonContent = EntityUtils.toString(entity); Reader stringReader = new StringReader(jsonContent); JsonReader rdr = Json.createReader(stringReader); JsonObject obj = rdr.readObject(); JsonArray results = obj.getJsonArray("usages"); for (JsonObject result : results.getValuesAs(JsonObject.class)) { BeanInfoLicense myBeanInfoLicense = new BeanInfoLicense(result.getString("agentType"), result.getInt("avgUnitsAllowed"), result.getInt("avgUnitsUsed")); myMapInfoLicense.put(result.getString("agentType"), myBeanInfoLicense); //System.out.println(result.getString("agentType")+","+result.getInt("avgUnitsAllowed")+","+result.getInt("avgUnitsUsed")); } return myMapInfoLicense; }
From source file:Servlet.newServlet.java
@POST @Consumes("application/json") @Produces("application/json") public Response add(JsonObject json) { String name = json.getString("name"); String description = json.getString("description"); String quantity = String.valueOf(json.getInt("quantity")); System.out.println(name + '\t' + description + '\t' + quantity); int result = doUpdate("INSERT INTO product (name,description,quantity) VALUES (?,?,?)", name, description, quantity);// w w w . j a v a 2 s . co m if (result <= 0) { return Response.status(500).build(); } else { return Response.ok(json).build(); } }
From source file:Servlet.newServlet.java
@PUT @Path("{id}") @Consumes("application/json") @Produces("application/json") public Response updateData(@PathParam("id") String id, JsonObject json) { String name = json.getString("name"); String description = json.getString("description"); String quantity = String.valueOf(json.getInt("quantity")); System.out.println(name + '\t' + description + '\t' + quantity + '\t' + id); int result = doUpdate("UPDATE product SET name=?,description=?,quantity=? where productID=?", name, description, quantity, String.valueOf(id)); if (result <= 0) { return Response.status(500).build(); } else {// w ww . j a va 2s . co m return Response.ok(json).build(); } }
From source file:org.fuin.esmp.Downloads.java
/** * Loads the data from the JSON download versions file. * /*from w ww . j a v a2 s . co m*/ * @throws IOException * Parsing the event store version file failed. */ public final void parse() throws IOException { final Reader reader = new FileReader(jsonDownloadsFile); try { final JsonReader jsonReader = Json.createReader(reader); final JsonArray osArray = jsonReader.readArray(); for (int i = 0; i < osArray.size(); i++) { final JsonObject osObj = (JsonObject) osArray.get(i); final String os = osObj.getString("os"); final String currentVersion = osObj.getString("currentVersion"); final JsonArray downloadsArray = osObj.getJsonArray("downloads"); final List<DownloadVersion> versions = new ArrayList<>(); for (int j = 0; j < downloadsArray.size(); j++) { final JsonObject downloadObj = (JsonObject) downloadsArray.get(j); final String version = downloadObj.getString("version"); final String url = downloadObj.getString("url"); versions.add(new DownloadVersion(version, url)); } Collections.sort(versions); osList.add(new DownloadOS(os, currentVersion, versions)); } Collections.sort(osList); } finally { reader.close(); } for (final DownloadOS os : osList) { LOG.info("Latest '" + os + "': " + os.getLatestVersion() + " (Versions: " + os.getVersions().size() + ")"); } }
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.j a va 2 s.c o m*/ */ 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 ww w . ja va 2s . co 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:GUI_The_Code_Book.ParserAPIStackEx.java
private void parseStackExchange(String jsonStr) { JsonReader reader = null;/*from www.ja va 2s . com*/ try { reader = Json.createReader(new StringReader(jsonStr)); JsonObject jsonObject = reader.readObject(); reader.close(); JsonArray array = jsonObject.getJsonArray("items"); for (JsonObject result : array.getValuesAs(JsonObject.class)) { urlList.add(new URLlist(result.getInt("view_count"), result.getInt("answer_count"), result.getString("title"), result.getString("link"))); } } catch (Exception e) { e.printStackTrace(); } }
From source file:mypackage.products.java
@PUT @Path("{id}") @Consumes("application/json") public Response putData(String str, @PathParam("id") int id) { JsonObject json = Json.createReader(new StringReader(str)).readObject(); String id1 = String.valueOf(id); String name = json.getString("name"); String description = json.getString("description"); String qty = String.valueOf(json.getInt("quantity")); int status = doUpdate( "UPDATE PRODUCT SET productId= ?, name = ?, description = ?, quantity = ? WHERE productId = ?", id1, name, description, qty, id1); if (status == 0) { return Response.status(500).build(); } else {/*ww w .j av a 2s. c o m*/ return Response.ok("http://localhost:8080/CPD-4414-Assignment-4/products/" + id, MediaType.TEXT_HTML) .build(); } }