List of usage examples for org.json JSONException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.neuron.trafikanten.dataProviders.trafikanten.TrafikantenRealtime.java
@Override public void run() { try {/*from w w w . j av a 2 s. c o m*/ final String urlString = Trafikanten.getApiUrl() + "/reisrest/realtime/GetAllDepartures/" + stationId; Log.i(TAG, "Loading realtime data : " + urlString); final StreamWithTime streamWithTime = HelperFunctions.executeHttpRequest(context, new HttpGet(urlString), true); ThreadHandleTimeData(streamWithTime.timeDifference); /* * Parse json */ //long perfSTART = System.currentTimeMillis(); //Log.i(TAG,"PERF : Getting realtime data"); final JSONArray jsonArray = new JSONArray(HelperFunctions.InputStreamToString(streamWithTime.stream)); final int arraySize = jsonArray.length(); for (int i = 0; i < arraySize; i++) { final JSONObject json = jsonArray.getJSONObject(i); RealtimeData realtimeData = new RealtimeData(); try { realtimeData.expectedDeparture = HelperFunctions .jsonToDate(json.getString("ExpectedDepartureTime")); } catch (org.json.JSONException e) { realtimeData.expectedDeparture = HelperFunctions .jsonToDate(json.getString("ExpectedArrivalTime")); } try { realtimeData.lineId = json.getInt("LineRef"); } catch (org.json.JSONException e) { realtimeData.lineId = -1; } try { realtimeData.vehicleMode = json.getInt("VehicleMode"); } catch (org.json.JSONException e) { realtimeData.vehicleMode = 0; // default = bus } try { realtimeData.destination = json.getString("DestinationName"); } catch (org.json.JSONException e) { realtimeData.destination = "Ukjent"; } try { realtimeData.departurePlatform = json.getString("DeparturePlatformName"); if (realtimeData.departurePlatform.equals("null")) { realtimeData.departurePlatform = ""; } } catch (org.json.JSONException e) { realtimeData.departurePlatform = ""; } try { realtimeData.realtime = json.getBoolean("Monitored"); } catch (org.json.JSONException e) { realtimeData.realtime = false; } try { realtimeData.lineName = json.getString("PublishedLineName"); } catch (org.json.JSONException e) { realtimeData.lineName = ""; } try { if (json.has("InCongestion")) { realtimeData.inCongestion = json.getBoolean("InCongestion"); } } catch (org.json.JSONException e) { // can happen when incongestion is empty string. } try { if (json.has("VehicleFeatureRef")) { realtimeData.lowFloor = json.getString("VehicleFeatureRef").equals("lowFloor"); } } catch (org.json.JSONException e) { // lowfloor = false by default } try { if (json.has("TrainBlockPart") && !json.isNull("TrainBlockPart")) { JSONObject trainBlockPart = json.getJSONObject("TrainBlockPart"); if (trainBlockPart.has("NumberOfBlockParts")) { realtimeData.numberOfBlockParts = trainBlockPart.getInt("NumberOfBlockParts"); } } } catch (org.json.JSONException e) { // trainblockpart is initialized by default } ThreadHandlePostData(realtimeData); } //Log.i(TAG,"PERF : Parsing web request took " + ((System.currentTimeMillis() - perfSTART)) + "ms"); } catch (Exception e) { if (e.getClass() == InterruptedException.class) { ThreadHandlePostExecute(null); return; } ThreadHandlePostExecute(e); return; } ThreadHandlePostExecute(null); }
From source file:org.mapfish.print.map.readers.WMSMapReader.java
public void render(Transformer transformer, ParallelMapTileLoader parallelMapTileLoader, String srs, boolean first) { PJsonObject customParams = params.optJSONObject("customParams"); // store the rotation to not change for other layers double oldAngle = transformer.getRotation(); // native WMS rotation - only works in singleTile mode if (customParams != null && customParams.optString("angle") != null) { // For GeoServer transformer.setRotation(0);// w w w . ja va 2 s . c o m } if (params.optBool("useNativeAngle", false)) { String angle = String.valueOf(-Math.toDegrees(transformer.getRotation())); try { if (customParams != null) { customParams.getInternalObj().put("angle", angle); // For GeoServer customParams.getInternalObj().put("map_angle", angle); // For MapServer } else { Map<String, String> customMap = new HashMap<String, String>(); customMap.put("angle", angle); // For GeoServer customMap.put("map_angle", angle); // For MapServer params.getInternalObj().put("customParams", customMap); } transformer.setRotation(0); } catch (org.json.JSONException e) { LOGGER.error("Unable to set angle: " + e.getClass().getName() + " - " + e.getMessage()); } } super.render(transformer, parallelMapTileLoader, srs, first); // restore the rotation for other layers transformer.setRotation(oldAngle); }
From source file:org.jwebsocket.plugins.sharedobjects.SharedObjectsPlugIn.java
@Override public void processToken(PlugInResponse aResponse, WebSocketConnector aConnector, Token aToken) { String lType = aToken.getType(); String lNS = aToken.getNS();//w ww.jav a 2s .co m String lID = aToken.getString("id"); String lDataType = aToken.getString("datatype"); String lValue = aToken.getString("value"); if (lType != null && (lNS == null || lNS.equals(NS_SHARED_OBJECTS))) { Token lResponse = getServer().createResponse(aToken); // create if (lType.equals("create")) { if (log.isDebugEnabled()) { log.debug("Processing 'create'..."); } if (!isDataTypeValid(lDataType, aConnector, lResponse)) { return; } if (alreadyExists(lID, aConnector, lResponse)) { return; } sharedObjects.put(lID, string2Object(lDataType, lValue)); Token lBCT = new Token(lNS, "event"); lBCT.put("name", "created"); lBCT.put("id", lID); lBCT.put("datatype", lDataType); lBCT.put("value", lValue); getServer().broadcastToken(aConnector, lBCT); // destroy } else if (lType.equals("destroy")) { if (log.isDebugEnabled()) { log.debug("Processing 'destroy'..."); } if (!doesContain(lID, aConnector, lResponse)) { return; } sharedObjects.remove(lID); Token lBCT = new Token(lNS, "event"); lBCT.put("name", "destroyed"); lBCT.put("id", lID); getServer().broadcastToken(aConnector, lBCT); // get } else if (lType.equals("get")) { if (log.isDebugEnabled()) { log.debug("Processing 'get'..."); } if (!doesContain(lID, aConnector, lResponse)) { return; } Object lObj = sharedObjects.get(lID); lResponse.put("id", lID); lResponse.put("result", lObj.toString()); // put } else if (lType.equals("update")) { if (log.isDebugEnabled()) { log.debug("Processing 'update'..."); } if (!isDataTypeValid(lDataType, aConnector, lResponse)) { return; } sharedObjects.put(lID, string2Object(lDataType, lValue)); Token lBCT = new Token(lNS, "event"); lBCT.put("name", "updated"); lBCT.put("id", lID); lBCT.put("datatype", lDataType); lBCT.put("value", lValue); getServer().broadcastToken(aConnector, lBCT); // init } else if (lType.equals("init")) { if (log.isDebugEnabled()) { log.debug("Processing 'init'..."); } Token lBCT = new Token(lNS, "event"); lBCT.put("name", "init"); String lData = null; try { JSONStringer jsonStringer = new JSONStringer(); // start main object jsonStringer.object(); // iterate through all items (fields) of the token Iterator<String> lIterator = sharedObjects.getKeys().iterator(); while (lIterator.hasNext()) { String lKey = lIterator.next(); Object lVal = sharedObjects.get(lKey); if (lVal instanceof Collection) { jsonStringer.key(lKey).array(); for (Object item : (Collection) lVal) { jsonStringer.value(item); } jsonStringer.endArray(); } else { jsonStringer.key(lKey).value(lVal); } } // end main object jsonStringer.endObject(); lData = jsonStringer.toString(); } catch (JSONException ex) { log.error(ex.getClass().getSimpleName() + ": " + ex.getMessage()); } lBCT.put("value", lData); getServer().sendToken(aConnector, lBCT); } else { log.warn("Invalid command " + lType + " received..."); lResponse.put("code", -1); lResponse.put("msg", "invalid type '" + lType + "'"); } getServer().sendToken(aConnector, lResponse); } }
From source file:org.mapfish.print.map.readers.WMSCMapReader.java
public void render(Transformer transformer, ParallelMapTileLoader parallelMapTileLoader, String srs, boolean first) { PJsonObject customParams = params.optJSONObject("customParams"); // store the rotation to not change for other layers double oldAngle = transformer.getRotation(); // native WMS rotation - only works in singleTile mode if (customParams != null && customParams.optString("angle") != null) { // For GeoServer transformer.setRotation(0);//from ww w. j a v a2 s . com } if (params.optBool("useNativeAngle", false)) { String angle = String.valueOf(-Math.toDegrees(transformer.getRotation())); try { if (customParams != null) { customParams.getInternalObj().put("angle", angle); // For GeoServer customParams.getInternalObj().put("map_angle", angle); // For MapServer } else { Map customMap = new HashMap(); customMap.put("angle", angle); // For GeoServer customMap.put("map_angle", angle); // For MapServer params.getInternalObj().put("customParams", customMap); } transformer.setRotation(0); } catch (org.json.JSONException e) { LOGGER.error("Unable to set angle: " + e.getClass().getName() + " - " + e.getMessage()); } } super.render(transformer, parallelMapTileLoader, srs, first); // restore the rotation for other layers transformer.setRotation(oldAngle); }