List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:ch.luklanis.esscan.codesend.ESRSenderHttp.java
License:Apache License
public void sendToListener(final String dataToSend, final long itemId, final int position) { AsyncTask<Object, Integer, JsonObject> asyncTask = new AsyncTask<Object, Integer, JsonObject>() { @Override/*from w w w .j a v a2 s.c o m*/ protected JsonObject doInBackground(Object... objects) { try { JsonObject json = new JsonObject(); json.addProperty("hash", hash); json.addProperty("id", emailAddress); String[] encrypted = Crypto.encrypt(Crypto.getSecretKey(password, emailAddress), dataToSend); json.addProperty("iv", encrypted[0]); json.addProperty("message", encrypted[1]); return json; } catch (Exception e) { e.printStackTrace(); if (mDataSentHandler != null) { Message message = Message.obtain(mDataSentHandler, R.id.es_send_failed); message.obj = itemId; message.arg1 = position; message.sendToTarget(); } return null; } } @Override protected void onPostExecute(JsonObject json) { if (json != null) { Ion.with(context, url).setJsonObjectBody(json).asString() .setCallback(new FutureCallback<String>() { @Override public void onCompleted(Exception e, String result) { if (mDataSentHandler != null) { Message message = Message.obtain(mDataSentHandler, "OK".equals(result) ? R.id.es_send_succeeded : R.id.es_send_failed); message.obj = itemId; message.arg1 = position; message.sendToTarget(); } } }); } } }; asyncTask.execute(); }
From source file:ch.usz.c3pro.c3_pro_android_framework.dataqueue.EncryptedDataQueue.java
License:Open Source License
/** * Encrypts a FHIR resource and wraps it in a C3-PRO json object that can be sent to a C3-PRO server. */// w w w .j a v a2 s. c o m public JsonObject encryptResource(IBaseResource resourceToEncrypt) throws CertificateException, NoSuchAlgorithmException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException, InvalidAlgorithmParameterException { // convert resource to json String resourceString = Pyro.getFhirContext().newJsonParser().encodeResourceToString(resourceToEncrypt); // encrypt jsson byte[] encryptedResource = aesUtility.encryptData(resourceString.getBytes()); // encrypt secret key byte[] encryptedKey = rsaUtility.getSecretKeyWrapped(aesUtility.getSecretKey()); // create new resource JsonObject jsonToSend = new JsonObject(); jsonToSend.addProperty("key_id", "some_key_id"); // put encrypted private key jsonToSend.addProperty("symmetric_key", Base64.encodeToString(encryptedKey, Base64.DEFAULT)); // put encrypted resource jsonToSend.addProperty("message", Base64.encodeToString(encryptedResource, Base64.DEFAULT)); // put details jsonToSend.addProperty("version", C3PROFHIRVersion); // return return jsonToSend; }
From source file:cl.expertchoice.svl.Svl_RiskTier.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . ja va 2s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { response.setContentType("text/html;charset=UTF-8"); try { String accion = request.getParameter("accion"); JsonObject json = new JsonObject(); switch (accion) { case "listar": { ArrayList<RiskTier> arr = new BnRiskTier().listar(); //ArrayList<RiskTier> arr = null; if (arr != null) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } case "listar-riskindicator": { ArrayList<TablaRiskIndicator> arr = new BnTablaRiskIndicator().listar2(); ArrayList<ValorTablaCore> vtc = new BnValorTablaCore().listar(); if (arr != null) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); json.add("def", new Gson().toJsonTree(vtc)); // json.add("def", vtc); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } case "guardar-risktier": { JSONObject jsonRiskTier = new JSONObject(request.getParameter("obRiskTier")); int idTipoRiskTier = jsonRiskTier.getInt("tipoRiskTier"); int numFilas = jsonRiskTier.getInt("filas"); int numCols = jsonRiskTier.getInt("columnas"); int idOrigenX = jsonRiskTier.getJSONObject("variableX").getInt("id"); int idOrigenY = jsonRiskTier.getJSONObject("variableY").getInt("id"); JSONArray origenX = jsonRiskTier.getJSONObject("variableX").getJSONArray("datos"); JSONArray origenY = jsonRiskTier.getJSONObject("variableY").getJSONArray("datos"); JSONArray jsonClasificacion = jsonRiskTier.getJSONArray("datos"); TablaRiskIndicator riskIndicator = new TablaRiskIndicator(BigInteger.ZERO, new Variable(idOrigenX, null), new Variable(idOrigenY, null), numFilas, numCols); json = new JsonObject(); if (new BnTablaRiskIndicator().guardarRiskInidcator(riskIndicator, origenX, origenY, jsonClasificacion, idTipoRiskTier)) { json.addProperty("estado", D.EST_OK); json.add("datos", new JsonObject()); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Error al guardar Risk Tier"); } response.getWriter().print(json); break; } case "listar-admin-risktier": { json = new JsonObject(); ArrayList<AdminRiskTier> arr = new BnAdminRiskTier().listar(); if (arr.size() > 0) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } case "update-detalle-admin": { JSONArray jsonData = new JSONArray(request.getParameter("detalles")); for (int i = 0; i < jsonData.length(); i++) { JSONObject ob = jsonData.getJSONObject(i); new BnAdminRiskTier().actualizar(ob.getString("valor"), ob.getInt("idDetalleAdminRiskTier")); } json = new JsonObject(); json.addProperty("estado", D.EST_OK); response.getWriter().print(json); break; } case "listar-detalle-admin-risktier": { json = new JsonObject(); int idAdminRiskTier = Integer.parseInt(request.getParameter("idAdminRiskTier")); ArrayList<DetalleAdminRiskTier> arr = new BnAdminRiskTier().listarDetalles(idAdminRiskTier); if (arr.size() > 0) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Error al listar Risk Tier"); } response.getWriter().print(json); break; } case "listar-depuracion-renta": { json = new JsonObject(); // ArrayList<DepuracionRenta> arr = new BnDepuracionRenta().listar(); // if (arr.size() > 0) { // json.addProperty("estado", D.EST_OK); // json.add("datos", new Gson().toJsonTree(arr)); // } else { // json.addProperty("estado", D.EST_NORESULTADO); // json.addProperty("descripcion", "No data"); // } // response.getWriter().print(json); break; } case "guardar-depuracion-renta": { json = new JsonObject(); // ArrayList<DepuracionRenta> arr = new ArrayList<>(); // // DepuracionRenta dr = new DepuracionRenta(); // dr.setId(Integer.parseInt(request.getParameter("id_deuda_cred_hipotecario"))); // dr.setPorcentajeRenta(request.getParameter("deuda_cred_hipotecario")); // arr.add(dr); // // dr = new DepuracionRenta(); // dr.setId(Integer.parseInt(request.getParameter("id_deuda_comercial"))); // dr.setPorcentajeRenta(request.getParameter("deuda_comercial")); // arr.add(dr); // // dr = new DepuracionRenta(); // dr.setId(Integer.parseInt(request.getParameter("id_deuda_credito_consumo"))); // dr.setPorcentajeRenta(request.getParameter("deuda_credito_consumo")); // arr.add(dr); // // boolean flag = new BnDepuracionRenta().actualizar(arr); // if (flag) { // json.addProperty("estado", D.EST_OK); // } else { // json.addProperty("estado", D.EST_NORESULTADO); // json.addProperty("descripcion", "Error al guardar datos"); // } // // response.getWriter().print(json); break; } case "arbol-risk-tier": { json = new JsonObject(); JsonObject resp = new BnRiskTier().listarArbol2(); if (resp != null) { json.addProperty("estado", D.EST_OK); json.add("datos", resp); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } } } catch (JSONException ex) { Logger.getLogger(Svl_RiskTier.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cl.expertchoice.svl.Svl_Scoring.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .ja v a 2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try { String accion = request.getParameter("accion"); JsonObject json = new JsonObject(); switch (accion) { case "scoring": { int rut = Integer.parseInt(request.getParameter("rut")); String dv = request.getParameter("dv"); JsonObject jsonCalculos = new JsonObject(); int mesActual = BnScore.obtenerScoring(rut, dv, 0); int mes2 = BnScore.obtenerScoring(rut, dv, 1); int mes3 = BnScore.obtenerScoring(rut, dv, 2); int mes4 = BnScore.obtenerScoring(rut, dv, 3); jsonCalculos.addProperty("mes1", mesActual); jsonCalculos.addProperty("mes2", mes2); jsonCalculos.addProperty("mes3", mes3); jsonCalculos.addProperty("mes4", mes4); json.addProperty("estado", 200); json.add("datos", jsonCalculos); response.getWriter().print(json); break; } //Codigo A.M: case "ObtenerScore": { int score = Integer.parseInt(request.getParameter("score")); JsonObject jsonCalculos = new JsonObject(); Metodos metodo = new Metodos(); String scoreText = metodo.ObtenerScore(score); jsonCalculos.addProperty("scoreText", scoreText); json.addProperty("estado", 200); json.add("datos", jsonCalculos); response.getWriter().print(json); break; } } } catch (Exception ex) { // response.getWriter().print("{ \"estado\" : " + D.EST_ERROR + ", \"descripcion\" : \"" + ex + "\" }"); // D.escribirLog(ex, "Svl_Cliente"); // ex.printStackTrace(); } }
From source file:client.commands.TwitchAPICommands.java
License:Apache License
@Override public void run() { if (!this.isAllowed()) return;//from w w w . jav a 2s . co m if (this.m.getMessage().startsWith("!game")) { String[] arr = this.m.getMessage().split(" ", 2); if (arr.length > 1) { JsonObject innerbody = new JsonObject(); innerbody.addProperty("game", this.m.getMessage().split(" ", 2)[1]); JsonObject obj = new JsonObject(); obj.add("channel", innerbody); System.out.println(obj.toString()); TwitchAPI api = new TwitchAPI(s.getClientid(), s.getOauth()); api.PUT("https://api.twitch.tv/kraken/channels/" + this.m.getChannel(), obj.toString()); } else { TwitchAPI api = new TwitchAPI(s.getClientid(), s.getOauth()); this.mq.offer(new MessageOut(this.m.getChannel().toLowerCase(), api.GET("https://api.twitch.tv/kraken/channels/" + this.m.getChannel()).get("game") .toString())); } } }
From source file:clientcommunicator.Server.Cookie.java
public void setUser(User userToBeSet) { JsonObject resultingCookie = new JsonObject(); resultingCookie.addProperty("name", userToBeSet.getUsername()); resultingCookie.addProperty("password", userToBeSet.getPassword()); resultingCookie.addProperty("playerID", userToBeSet.getPlayerId()); try {//from www . j ava 2 s .c o m this.getUserJsonObject(resultingCookie, true); } catch (MalformedCookieException ex) { Logger.getLogger(Cookie.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cloudlens.cli.Whisk.java
License:Apache License
public static JsonObject main(JsonObject args) { final JsonObject res = new JsonObject(); try {/*from w ww . ja v a 2s . c om*/ final CL cl = new CL(System.out, System.err, false, true); String script = ""; String logURI = ""; if (args.has("script")) { script = args.getAsJsonPrimitive("script").getAsString(); } if (args.has("log")) { logURI = args.getAsJsonPrimitive("log").getAsString(); } try { final InputStream inputStream = FileReader.fetchFile(logURI); cl.source(inputStream); final List<ASTElement> top = ASTBuilder.parse(script); cl.launch(top); final JsonElement jelement = new JsonParser().parse(cl.cl.get("result").asString()); return jelement.getAsJsonObject(); } catch (final CLException e) { res.addProperty("error", e.getMessage()); System.err.println(e.getMessage()); } finally { cl.outWriter.flush(); cl.errWriter.flush(); } } catch (final Exception e) { res.addProperty("error", e.getMessage()); System.err.println(e.getMessage()); } return res; }
From source file:club.jmint.crossing.client.DemoClient.java
License:Apache License
public static void main(String[] args) { //Create Crossing client call proxy CrossingClient cc = CrossingClient.getInstance(); //Start Crossing Client try {/*w ww. j ava 2 s .co m*/ cc.startup(); } catch (Exception e) { System.exit(-1); } System.out.println("Starting to run example calls."); JsonObject pp4 = new JsonObject(); pp4.addProperty("type", 4); pp4.addProperty("fields", "user_id,user_true_name,status,pay_status,product_id,product_name,ticket_code,ticket_code_url"); pp4.addProperty("user_id", "1000000005"); System.out.println(pp4.toString()); CallResult result = cc.serviceCall( "TwohalfServer@com.twohalf.mifty.service.gen.OrderService@orderQueryByUser", pp4, false); if (result != null && result.isSuccess) { System.out.println(result.data); } //Stop Crossing Client cc.shutdown(); }
From source file:club.jmint.crossing.specs.CrossingService.java
License:Apache License
/** * // w w w. ja v a 2s.c o m * @param errorCode * @param errorInfo * @return */ protected String buildOutputError(int errorCode, String errorInfo) { JsonObject jo = new JsonObject(); jo.addProperty("errorCode", errorCode); jo.addProperty("errorInfo", errorInfo); return jo.toString(); }
From source file:club.jmint.crossing.specs.CrossingService.java
License:Apache License
protected String buildOutputError(CrossException ce) { JsonObject jo = new JsonObject(); jo.addProperty("errorCode", ce.getErrorCode()); jo.addProperty("errorInfo", ce.getErrorInfo()); return jo.toString(); }