List of usage examples for org.json JSONObject put
public JSONObject put(String key, Object value) throws JSONException
From source file:com.amossys.hooker.common.InterceptEvent.java
/** * @return/*from ww w . j a va 2 s . c om*/ */ public String toJson() { JSONObject object = new JSONObject(); try { // object.put("IdEvent", this.getIdEvent().toString()); object.put("Timestamp", this.getTimestamp()); object.put("RelativeTimestamp", this.getRelativeTimestamp()); object.put("HookerName", this.getHookerName()); object.put("IntrusiveLevel", this.getIntrusiveLevel()); object.put("InstanceID", this.getInstanceID()); object.put("PackageName", this.getPackageName()); object.put("ClassName", this.getClassName()); object.put("MethodName", this.getMethodName()); JSONArray parameters = new JSONArray(); if (this.getParameters() != null) { for (Entry<String, String> parameter : this.getParameters()) { JSONObject jsonParameter = new JSONObject(); jsonParameter.put("ParameterType", parameter.getKey()); jsonParameter.put("ParameterValue", parameter.getValue()); parameters.put(jsonParameter); } } object.put("Parameters", parameters); JSONObject returns = new JSONObject(); if (this.getReturns() != null) { returns.put("ReturnType", this.getReturns().getKey()); returns.put("ReturnValue", this.getReturns().getValue()); } object.put("Return", returns); JSONArray data = new JSONArray(); if (this.getData() != null) { for (String dataName : this.getData().keySet()) { if (dataName != null && this.getData().get(dataName) != null) { JSONObject dataP = new JSONObject(); dataP.put("DataName", dataName); dataP.put("DataValue", this.getData().get(dataName)); } } } object.put("Data", data); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return object.toString(); }
From source file:com.apress.progwt.server.web.controllers.GearsLocalServerManifestController.java
private String createManifest() throws JSONException { String gwtROOT = hostConfigurer.resolvePlaceholder("HOST.gears.localserver.dir"); String localServerURL = hostConfigurer.resolvePlaceholder("HOST.gears.localserver.url"); File contextF = new File(gwtROOT); JSONObject json = new JSONObject(); json.put("betaManifestVersion", Integer.parseInt(getProperty("gears.betaManifestVersion"))); json.put("version", "0.0.1." + RandomUtils.rand(0, 2048)); json.put("entries", getEntries(contextF, localServerURL)); return json.toString(); }
From source file:com.apress.progwt.server.web.controllers.GearsLocalServerManifestController.java
/** * // w w w.jav a2 s .c om * @param dir * @param localServerURL * @param dirString * @param fileArray * @return * @throws JSONException */ private JSONArray getEntries(File dir, String localServerURL, String dirString, JSONArray fileArray) throws JSONException { log.info("context: |" + dir + "|" + dirString); for (File f : dir.listFiles()) { if (shouldSkip(f.getName())) { continue; } // descend into directory if (f.isDirectory()) { log.info("found dir " + f); getEntries(f, localServerURL, f.getName() + "/", fileArray); continue; } JSONObject oo = new JSONObject(); oo.put("url", localServerURL + dirString + f.getName()); fileArray.put(oo); } return fileArray; }
From source file:org.jboss.aerogear.unifiedpush.admin.ui.utils.InstallationUtils.java
public static Response registerInstallation(String contextPath, String variantID, String secret, Installation installation) {//from w ww . ja va 2 s. c om Response response = null; try { JSONObject jsonObject = new JSONObject(); jsonObject.put("deviceToken", installation.getDeviceToken()); jsonObject.put("deviceType", installation.getDeviceType()); jsonObject.put("operatingSystem", installation.getOperatingSystem()); jsonObject.put("osVersion", installation.getOsVersion()); jsonObject.put("alias", installation.getAlias()); jsonObject.put("simplePushEndpoint", installation.getSimplePushEndpoint()); response = RestAssured.given().contentType("application/json").auth().basic(variantID, secret) .header("Accept", "application/json").body(jsonObject.toString()) .post(contextPath + "rest/registry/device"); } catch (Exception e) { e.printStackTrace(); } return response; }
From source file:io.openkit.okcloud.OKCloudAsyncRequest.java
private void postWithCompletionHandler(String relativeURL, final CompletionHandler h) { JSONObject requestParamsJSON = new JSONObject(); try {/*from ww w.j a v a 2 s .co m*/ requestParamsJSON.put("app_key", OpenKit.getOKAppID()); for (Map.Entry<String, String> entry : params.entrySet()) { requestParamsJSON.put(entry.getKey(), entry.getValue()); } } catch (JSONException e) { h.complete(null, new OKCloudException("Could not add post params to json object")); return; } OKHTTPClient.postJSON(relativeURL, requestParamsJSON, new AsyncHttpResponseHandler() { @Override public void onStart() { OKLog.v("POST started."); } @Override public void onSuccess(String response) { OKLog.v("POST succeeded, got response: %s", response); h.complete(response, null); } @Override public void onFailure(Throwable e, String response) { String errMessage = e.getMessage(); OKLog.v("POST failed, %s", errMessage); h.complete(null, new OKCloudException(errMessage)); } @Override public void onFinish() { OKLog.v("POST finished."); } }); }
From source file:com.liferay.mobile.android.v7.ddmstructure.DDMStructureService.java
public JSONArray search(long companyId, JSONArray groupIds, long classNameId, String keywords, int status, int start, int end, JSONObjectWrapper orderByComparator) throws Exception { JSONObject _command = new JSONObject(); try {//from ww w . j av a 2 s . c o m JSONObject _params = new JSONObject(); _params.put("companyId", companyId); _params.put("groupIds", checkNull(groupIds)); _params.put("classNameId", classNameId); _params.put("keywords", checkNull(keywords)); _params.put("status", status); _params.put("start", start); _params.put("end", end); mangleWrapper(_params, "orderByComparator", "com.liferay.portal.kernel.util.OrderByComparator<com.liferay.dynamic.data.mapping.model.DDMStructure>", orderByComparator); _command.put("/ddm.ddmstructure/search", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.liferay.mobile.android.v7.ddmstructure.DDMStructureService.java
public JSONArray search(long companyId, JSONArray groupIds, long classNameId, String name, String description, String storageType, int type, int status, boolean andOperator, int start, int end, JSONObjectWrapper orderByComparator) throws Exception { JSONObject _command = new JSONObject(); try {/*from w w w.j av a 2 s .c o m*/ JSONObject _params = new JSONObject(); _params.put("companyId", companyId); _params.put("groupIds", checkNull(groupIds)); _params.put("classNameId", classNameId); _params.put("name", checkNull(name)); _params.put("description", checkNull(description)); _params.put("storageType", checkNull(storageType)); _params.put("type", type); _params.put("status", status); _params.put("andOperator", andOperator); _params.put("start", start); _params.put("end", end); mangleWrapper(_params, "orderByComparator", "com.liferay.portal.kernel.util.OrderByComparator<com.liferay.dynamic.data.mapping.model.DDMStructure>", orderByComparator); _command.put("/ddm.ddmstructure/search", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.liferay.mobile.android.v7.ddmstructure.DDMStructureService.java
public JSONObject fetchStructure(long groupId, long classNameId, String structureKey, boolean includeAncestorStructures) throws Exception { JSONObject _command = new JSONObject(); try {//from w w w.j a va 2 s . c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("classNameId", classNameId); _params.put("structureKey", checkNull(structureKey)); _params.put("includeAncestorStructures", includeAncestorStructures); _command.put("/ddm.ddmstructure/fetch-structure", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONObject(0); }
From source file:com.liferay.mobile.android.v7.ddmstructure.DDMStructureService.java
public JSONObject fetchStructure(long groupId, long classNameId, String structureKey) throws Exception { JSONObject _command = new JSONObject(); try {//from ww w.ja v a 2 s . c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("classNameId", classNameId); _params.put("structureKey", checkNull(structureKey)); _command.put("/ddm.ddmstructure/fetch-structure", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONObject(0); }
From source file:com.liferay.mobile.android.v7.ddmstructure.DDMStructureService.java
public JSONObject getStructure(long structureId) throws Exception { JSONObject _command = new JSONObject(); try {//from w ww . ja va2s .c om JSONObject _params = new JSONObject(); _params.put("structureId", structureId); _command.put("/ddm.ddmstructure/get-structure", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONObject(0); }