private void getTrafficSpots() { controller.showProgressBar(); String uploadWebsite = "http://" + controller.selectedCity.URL + "/php/trafficstatus.cache?dummy=ert43"; String[] ArrayOfData = null; StreamConnection c = null; InputStream s = null; StringBuffer b = new StringBuffer(); String url = uploadWebsite; System.out.print(url); try { c = (StreamConnection) Connector.open(url); s = c.openDataInputStream(); int ch; int k = 0; while ((ch = s.read()) != -1) { System.out.print((char) ch); b.append((char) ch); } // System.out.println("b"+b); try { JSONObject ff1 = new JSONObject(b.toString()); String data1 = ff1.getString("locations"); JSONArray jsonArray1 = new JSONArray(data1); Vector TrafficStatus = new Vector(); for (int i = 0; i < jsonArray1.length(); i++) { System.out.println(jsonArray1.getJSONArray(i).getString(3)); double aDoubleLat = Double.parseDouble(jsonArray1.getJSONArray(i).getString(1)); double aDoubleLon = Double.parseDouble(jsonArray1.getJSONArray(i).getString(2)); System.out.println(aDoubleLat + " " + aDoubleLon); TrafficStatus.addElement( new LocationPointer( jsonArray1.getJSONArray(i).getString(3), (float) aDoubleLon, (float) aDoubleLat, 1, true)); } controller.setCurrentScreen(controller.TrafficSpots(TrafficStatus)); } catch (Exception E) { controller.setCurrentScreen(traf); new Thread() { public void run() { controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO); } }.start(); } } catch (Exception e) { controller.setCurrentScreen(traf); new Thread() { public void run() { controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO); } }.start(); } }
public void authenticate(String authenticationKey, String password) { ActionRequestBase actionRequest = new ActionRequestBase(Api.V1.getAuthenticationURL()); actionRequest.setPostParam("authentication_key", authenticationKey); actionRequest.setPostParam("password", password); JSONObject actionResponse = actionRequest.post(); try { actionResponse = actionResponse.getJSONObject("responseObject"); switch (actionRequest.getResponseCode()) { case HttpStatus.SC_INTERNAL_SERVER_ERROR: mAuthenticationStatus = INTERNAL_SERVER_ERROR; break; case HttpStatus.SC_OK: User user = new User(actionResponse.getJSONObject("user")); if (user.save()) { Session.setUser(user); mAuthenticationStatus = AUTHENTICATED; } else { mAuthenticationStatus = INTERNAL_SERVER_ERROR; } break; case HttpStatus.SC_UNPROCESSABLE_ENTITY: mAuthenticationStatus = INVALID_CREDENTIALS; mAuthenticationErrors = actionResponse.getJSONObject("errors"); break; } } catch (JSONException jsone) { mAuthenticationStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; } }
@Test public void testGetAjugglerURLkeyDefault() throws JSONException { JSONObject actionJO = new JSONObject(); actionJO.put(Constant.JSON_KEY_FROM, Constant.KEY_ADJUGGLER_FROM_MAIN); actionJO.put(Constant.JSON_KEY_ISPREMIUMACCOUNT, 0); Object o = AdjugglerUtil.getAjugglerURLkeyDefault(actionJO); Assert.assertNotNull(o); }
@Test public void testHandleAdjugglerURL() throws JSONException { JSONObject actionJO = new JSONObject(); actionJO.put("keyword", ""); Object o = AdjugglerUtil.handleAdjugglerURL("http://", handler, actionJO); Assert.assertNotNull(o); }
@Test public void testDealWithExternalURL() throws JSONException { JSONObject action = new JSONObject(); action.put("type", Constant.KEY_ADJUGGLER_BROWSER); JSONObject adJo = new JSONObject(); adJo.put("action", action); Object o = AdjugglerUtil.dealWithExternalURL(adJo, handler); Assert.assertNotNull(o); }
@Test public void testGetPoiSearchRequest() throws JSONException { JSONObject locationJO = new JSONObject(); locationJO.put("lat", 3737453); locationJO.put("lon", -12199983); long categoryId = 703; int sortType = 4; PoiSearchRequest req = AdjugglerUtil.getPoiSearchRequest(handler, locationJO, categoryId, sortType, true); Assert.assertNotNull(req); }
@Test public void testSetImageUrlSuffix() throws JSONException { JSONObject backgroundImageJo = new JSONObject(); backgroundImageJo.put("focusUrl", "focusUrl"); backgroundImageJo.put("unfocusUrl", "unfocusUrl"); JSONObject adJo = new JSONObject(); adJo.put("backgroundImage", backgroundImageJo); Object o = AdjugglerUtil.setImageUrlSuffix(adJo, "suffix"); Assert.assertNotNull(o); }
@SuppressWarnings("rawtypes") private boolean isEqualsJsonObject(JSONObject a, JSONObject b) { if (policy == STRICT) { if (a.length() != b.length()) { return false; } } if (policy == SIMPLE) { if (a.length() > b.length()) { return false; } } Enumeration keys = a.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (!b.has(key)) { return false; } try { if (!isEquals(a.get(key), b.get(key))) { return false; } } catch (JSONException e) { return false; } } return true; }
public JSONArray serializeJSON() throws JSONException { JSONArray a = new JSONArray(); // Mandatory items for (int i = 0; i < contacts.length; i++) { Contact c = contacts[i]; JSONObject o = new JSONObject(); o.put("contact", c.serializeJSON()); a.put(o); } return a; }
public static Vector fromJsonArray(String jsonArray) { Vector vectorFacturas = new Vector(); try { JSONArray array = new JSONArray(jsonArray); for (int i = 0; i < array.length(); i++) { JSONObject json = array.getJSONObject(i); Facturas fac = Facturas.fromJson(json.toString()); vectorFacturas.addElement(fac); } } catch (JSONException e) { e.printStackTrace(); } return vectorFacturas; }
public String getAuthenticationError(String key) { try { return mAuthenticationErrors.getJSONArray(key).getString(0); } catch (JSONException jsone) { return ""; } }
public void unserializeJSON(JSONArray a) throws JSONException { Vector v = new Vector(); // Mandatory fields for (int i = 0; i < a.length(); i++) { JSONObject o = a.getJSONObject(i); Contact c = new Contact(); c.unserializeJSON(o.getJSONObject("contact")); v.addElement(c); } contacts = new Contact[v.size()]; v.copyInto(contacts); }
protected ActionForward doAction( ActionMapping mapping, HttpServletRequest request, HttpServletResponse response) { try { DataHandler handler = (DataHandler) request.getAttribute(BrowserFrameworkConstants.CLIENT_INFO); Long userId = PoiUtil.getUserId(handler); TnContext tc = PoiUtil.getTnContext(handler); TxNode body = handler.getAJAXBody(); String joString = body.msgAt(0); JSONObject jo = new JSONObject(joString); String firstName = jo.getString("firstName"); String lastName = jo.getString("lastName"); String email = jo.getString("email"); if (null != email) { email = email.toLowerCase(); } TxNode node = new TxNode(); node.addMsg(firstName); node.addMsg(lastName); node.addMsg(email); if (email.equals("")) { email = null; } TelepersonalizationFacade.updateUserProfile( userId.toString(), firstName, lastName, email, -1, -1, true, tc); /* TelePersonalize telePersonalize = new TelePersonalize(); telePersonalize.updateUserInfo(userId.toString(), firstName, lastName, email, -1, -1, false, tc.toContextString());*/ request.setAttribute("node", node); return mapping.findForward("success"); } catch (Exception e) { ActionMessages msgs = new ActionMessages(); msgs.add("UpdateUserInfofailed", new ActionMessage("errors.UpdateUserInfo.failed")); addErrors(request, msgs); return mapping.findForward("failure"); } }
@Test public void testGetMovieSearchRequestDTO() throws JSONException { JSONObject locationJO = new JSONObject(); locationJO.put("lat", 3737453); locationJO.put("lon", -12199983); JSONObject adJo = new JSONObject(); JSONObject actionJson = new JSONObject(); adJo.put("action", actionJson); actionJson.put("searchName", "Movie"); actionJson.put("searchDate", "2012-03-05"); actionJson.put("SortBy", AdjugglerUtil.MOVIE_SORT_BY_WEEKEND_GROSS); AdjugglerUtil.getMovieSearchRequestDTO(handler, locationJO, adJo); }
@Override public void parseBrowserResponse( HttpServletRequest httpRequest, ExecutorResponse executorResponse) { ShareAddressResponse response = (ShareAddressResponse) executorResponse; int status = response.getStatus(); boolean isRGC = response.isRGC(); String resultText = "N"; if (status == ExecutorResponse.STATUS_OK) { resultText = "Y"; } TxNode node = new TxNode(); node.addMsg(resultText); if (isRGC) { Stop stop = response.getAddress(); JSONObject stopJo = new JSONObject(); try { stopJo.put("firstLine", stop.firstLine); stopJo.put("city", stop.city); stopJo.put("state", stop.state); stopJo.put("country", stop.country); stopJo.put("lon", stop.lon); stopJo.put("zip", stop.zip); stopJo.put("lat", stop.lat); stopJo.put("lon", stop.lon); stopJo.put("label", stop.label); } catch (JSONException e) { // TODO Auto-generated catch block logger.error("JSONException occured when we want to put a string into it"); logger.error("cause:" + e.getCause() + ",message:" + e.getMessage()); } node.addMsg(stopJo.toString()); } httpRequest.setAttribute("node", node); // TODO save audio }
@Before public void setUp() throws Exception { JSONObject paramJSON = HtmlAdjugglerDefaultJSON.getDefaultJSONForPrem(); paramJSON.put("loginLocator", ""); paramJSON.put("ssoToken", ""); paramJSON.put("appCode", ""); paramJSON.put("clientInfoStr", ""); paramJSON.put("width", "480-800"); paramJSON.put("height", "800-480"); HtmlClientInfo htmlClientInfo = new HtmlClientInfo(); dataSource.addData(JSONObject.class.getName(), paramJSON); dataSource.addData(String.class.getName(), String.valueOf("1")); dataSource.addData(HtmlClientInfo.class.getName(), htmlClientInfo); }
private void parseResultSet(Properties prop, ResultSet rs, List<JSONObject> newNotification) throws SQLException, JSONException { if (!rs.isBeforeFirst()) { log.debug("No Data Available "); return; } else { while (rs.next()) { JSONObject notiObj = new JSONObject(); notiObj.put("title", rs.getString("tittle")); notiObj.put("auther", rs.getString("auther")); notiObj.put("publisher", rs.getString("publisher")); notiObj.put("release_date", rs.getDate("release_date").toString()); notiObj.put("list_price", rs.getString("list_price")); notiObj.put("id", rs.getString("id")); newNotification.add(notiObj); invalidate_record(rs.getString("id"), prop); log.debug("==New Notification Record=" + notiObj.toString()); } } }
public Object convertToUseForm(Object key, byte[] bytes) { JSONObject responseJson; try { responseJson = new JSONObject(new String(bytes)); } catch (JSONException ex) { // #debug L.e("bytes are not a JSON object", featURL, ex); return null; } JSONArray entries = new JSONArray(); final Vector vector = new Vector(); try { final JSONObject feed = ((JSONObject) responseJson).getJSONObject("feed"); entries = feed.getJSONArray("entry"); } catch (JSONException e) { vector.addElement(new PicasaImageObject("No Results", "", "", "")); // #debug L.e("JSON no result", featURL, e); } for (int i = 0; i < entries.length(); i++) { try { final JSONObject jsonObject = entries.getJSONObject(i); final String title = jsonObject.getJSONObject("title").getString("$t"); final String author = jsonObject .getJSONArray("author") .getJSONObject(0) .getJSONObject("name") .getString("$t"); final String thumbUrl = jsonObject .getJSONObject("media$group") .getJSONArray("media$thumbnail") .getJSONObject(0) .getString("url"); final String imageUrl = jsonObject .getJSONObject("media$group") .getJSONArray("media$content") .getJSONObject(0) .getString("url"); // #mdebug L.i("JSON parsed title: ", title); L.i("JSON parsed author: ", author); L.i("JSON parsed thumb url: ", thumbUrl); L.i("JSON parsed image url: ", imageUrl); // #enddebug vector.addElement(new PicasaImageObject(title, author, thumbUrl, imageUrl)); } catch (JSONException e) { // #debug L.e("JSON item parse error", featURL, e); } } if (entries.length() == 0) { vector.addElement(new PicasaImageObject("No Results", "", "", "")); } return vector; }
public void descargarDatos() { try { connectionURL = Strings.HTTP_SW + "getMunicipios/" + tipoConexion; // Dialog.alert(connectionURL+"<<URL"); conn = (HttpConnection) Connector.open(connectionURL); conn.setRequestProperty("Content-Type", "application/json"); // System.out.println("Response code : "+conn.getResponseCode()); if (conn.getResponseCode() == HttpConnection.HTTP_OK) { is = conn.openInputStream(); int ch = -1; bos = new ByteArrayOutputStream(); while ((ch = is.read()) != -1) { bos.write(ch); } response = new String(bos.toByteArray(), "UTF-8"); // JSONObject temporalError = new JSONObject ( response ); // errorCode = temporalError.getString("errotCode"); // errorMessage = temporalError.getString("errorMessage"); JSONObject objeto1 = new JSONObject(response); String resultado1 = objeto1.getString("response"); // Dialog.alert(resultado1+"<<"); JSONObject objeto2 = new JSONObject(resultado1); errorCode = objeto2.getString("errorCode"); errorMessage = objeto2.getString("errorMessage"); if (errorCode.equals("0")) { JSONArray jsonMainArr = objeto2.getJSONArray("msg"); for (int i = 0; i < jsonMainArr.length(); i++) { JSONObject childJSONObject = jsonMainArr.getJSONObject(i); IdMunicipio.addElement(childJSONObject.get("idMunicipio")); NombreMunicipio.addElement(childJSONObject.get("municipio")); } } else if (errorCode.equals("1")) { if (Display.getWidth() == 320) { errorMessage = "noData1_320.png"; } if (Display.getWidth() == 360) { errorMessage = "noData1_360.png"; } if (Display.getWidth() == 480) { errorMessage = "noData1_480.png"; } if (Display.getWidth() == 640) { errorMessage = "noData1.png"; } } } } catch (Exception e) { // TODO: handle exception if (Display.getWidth() == 320) { errorMessage = "noData1_320.png"; } if (Display.getWidth() == 360) { errorMessage = "noData1_360.png"; } if (Display.getWidth() == 480) { errorMessage = "noData1_480.png"; } if (Display.getWidth() == 640) { errorMessage = "noData1.png"; } } finally { if (conn != null) try { conn.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (is != null) try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (bos != null) try { bos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } municipiocompras.setIdMunicipio(IdMunicipio); municipiocompras.setNombreMunicipio(NombreMunicipio); municipiocompras.seterrorCode(errorCode); municipiocompras.seterrorMessage(errorMessage); }
public boolean hasAuthenticationErrorOn(String key) { return mAuthenticationErrors != null && mAuthenticationErrors.has(key); }
public static Facturas fromJson(String jsonText) { Facturas facs = new Facturas(); try { JSONObject json = new JSONObject(jsonText); if (json.has("id")) { facs.setId(json.getString("id")); } if (json.has("invoice_number")) { facs.setInvoiceNumber(json.getString("invoice_number")); } if (json.has("amount")) { facs.setAmount(json.getString("amount")); } if (json.has("nit")) { facs.setNit(json.getString("nit")); } if (json.has("name")) { facs.setName(json.getString("name")); } } catch (JSONException e) { } return facs; }
public SearchProductoCx(int idcategoria, String PalabraFiltro) { SearchProductoSG searchproducto = new SearchProductoSG(); try { connectionURL = Strings.HTTP_SW + "getListaDeProductosPorCategoriaPorNombre/" + idcategoria + "/" + PalabraFiltro + tipoConexion; conn = (HttpConnection) Connector.open(connectionURL); conn.setRequestProperty("Content-Type", "application/json"); // System.out.println("Response code : "+conn.getResponseCode()); if (conn.getResponseCode() == HttpConnection.HTTP_OK) { is = conn.openInputStream(); int ch = -1; bos = new ByteArrayOutputStream(); while ((ch = is.read()) != -1) { bos.write(ch); } response = new String(bos.toByteArray(), "UTF-8"); JSONObject objeto1 = new JSONObject(response); String resultado1 = objeto1.getString("response"); JSONObject objeto2 = new JSONObject(resultado1); errorCode = objeto2.getString("errorCode"); errorMessage = objeto2.getString("errorMessage"); JSONArray jsonMainArr = objeto2.getJSONArray("msg"); for (int i = 0; i < jsonMainArr.length(); i++) { JSONObject childJSONObject = jsonMainArr.getJSONObject(i); IdProducto.addElement(childJSONObject.get("idProducto")); Nombre.addElement(childJSONObject.get("nombre")); } } } catch (Exception e) { // TODO: handle exception } finally { if (conn != null) try { conn.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (is != null) try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (bos != null) try { bos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } searchproducto.setIdProducto(IdProducto); searchproducto.setNombre(Nombre); searchproducto.seterrorCode(errorCode); searchproducto.seterrorMessage(errorMessage); }