List of usage examples for javax.json Json createReader
public static JsonReader createReader(InputStream in)
From source file:httputils.HttpUtil.java
public static JsonObject convertResponseToJson(HttpResponse response) throws ParseException, IOException { InputStream in = response.getEntity().getContent(); JsonReader reader = Json.createReader(in); JsonObject jObj = reader.readObject(); reader.close();//from ww w. j a v a2 s .c o m in.close(); return jObj; }
From source file:com.lyonsdensoftware.config.DeviceConfigUtils.java
/** * Reads the {@link DeviceConfig} from disk. Pass in the name of the config file * * @return The configuration.//w w w .j a va 2s.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 wundergroundObject = configObject.getJsonObject("wundergroundApi"); String wundergroundApiKey = wundergroundObject.getString("wundergroundApiKey"); String wundergroundStateIdentifier = wundergroundObject.getString("wundergroundStateIdentifier"); String wundergroundCity = wundergroundObject.getString("wundergroundCity"); String productId = configObject.getString("productId"); String dsn = configObject.getString("dsn"); JsonObject pythonTCPSettings = configObject.getJsonObject("pythonTCPSettings"); String hostname = pythonTCPSettings.getString("hostname"); int port = pythonTCPSettings.getInt("port"); DeviceConfig deviceConfig = new DeviceConfig(wundergroundApiKey, wundergroundStateIdentifier, wundergroundCity, productId, dsn, hostname, port); return deviceConfig; } catch (FileNotFoundException e) { throw new RuntimeException("The required file " + deviceConfigName + " could not be opened.", e); } finally { IOUtils.closeQuietly(file); } }
From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavenlicense.MavenLicenseDeleteAction.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 w ww .j a v a2 s. c o m*/ if (StringUtils.isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX))) { mavenLicenseSettingsService .deleteMavenLicense(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX)); LOGGER.info(MavenLicenseConfiguration.INFO_DELETE_SUCCESS + jsonObject.toString()); mavenLicenseSettingsService.sortMavenLicenses(); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK); } else { LOGGER.error(MavenLicenseConfiguration.ERROR_DELETE_INVALID_INPUT + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } }
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. ja v a2s. c om*/ */ 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); } }
From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavenlicense.MavenLicenseAddAction.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();/*w ww. j a va2 s . c o m*/ boolean keyIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_KEY)); boolean regexIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX)); if (keyIsNotBlank && regexIsNotBlank) { boolean success = mavenLicenseSettingsService.addMavenLicense( jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX), jsonObject.getString(MavenLicenseConfiguration.PROPERTY_KEY)); if (success) { LOGGER.info(MavenLicenseConfiguration.INFO_ADD_SUCCESS + jsonObject.toString()); mavenLicenseSettingsService.sortMavenLicenses(); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK); } else { LOGGER.error(MavenLicenseConfiguration.ERROR_ADD_ALREADY_EXISTS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } } else { LOGGER.error(MavenLicenseConfiguration.ERROR_ADD_INVALID_INPUT + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } }
From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavendependency.MavenDependencyDeleteAction.java
@Override public void handle(Request request, Response response) throws Exception { JsonReader jsonReader = Json .createReader(new StringReader(request.param(MavenDependencyConfiguration.PARAM))); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close();// w ww.ja v a 2 s. co m if (StringUtils.isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY))) { mavenDependencySettingsService .deleteMavenDependency(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY)); LOGGER.info(MavenDependencyConfiguration.INFO_DELETE_SUCCESS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK); } else { LOGGER.error(MavenDependencyConfiguration.ERROR_DELETE_INVALID_INPUT + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } }
From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavendependency.MavenDependencyAddAction.java
@Override public void handle(Request request, Response response) throws Exception { JsonReader jsonReader = Json .createReader(new StringReader(request.param(MavenDependencyConfiguration.PARAM))); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close();//w w w . j av a2 s .co m boolean keyIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY)); boolean licenseIsNotBlank = StringUtils .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_LICENSE)); if (keyIsNotBlank && licenseIsNotBlank) { boolean success = mavenDependencySettingsService.addMavenDependency( jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY), jsonObject.getString(MavenDependencyConfiguration.PROPERTY_LICENSE)); if (success) { LOGGER.info(MavenDependencyConfiguration.INFO_ADD_SUCCESS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK); } else { LOGGER.error(MavenDependencyConfiguration.ERROR_ADD_ALREADY_EXISTS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } } else { LOGGER.error(MavenDependencyConfiguration.INFO_ADD_SUCCESS + jsonObject.toString()); response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED); } }
From source file:mypackage.products.java
@POST @Consumes("application/json") public Response post(String str) { JsonObject json = Json.createReader(new StringReader(str)).readObject(); String id = String.valueOf(json.getInt("productId")); String name = json.getString("name"); String description = json.getString("description"); String qty = String.valueOf(json.getInt("quantity")); int status = doUpdate("INSERT INTO PRODUCT (productId, name, description, quantity) VALUES (?, ?, ?, ?)", id, name, description, qty); if (status == 0) { return Response.status(500).build(); } else {/*w w w . jav a2 s. c o m*/ return Response.ok("http://localhost:8080/CPD-4414-Assignment-4/products/" + id, MediaType.TEXT_HTML) .build(); } }
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();//ww w .j a va 2 s. co m 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.bhuwan.eventregistration.business.boundary.EventRegistrationResource.java
@GET @Path("{id}") public Response getEventData(@PathParam("id") String id) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/eventdata/" + id + ".json"); JsonReader jsonReader = Json.createReader(inputStream); return Response.ok(jsonReader.readObject()).header("Access-Control-Allow-Origin", "*").build(); }