List of usage examples for org.json JSONException printStackTrace
public void printStackTrace(PrintStream s)
From source file:edu.stanford.junction.provider.irc.Junction.java
protected void handleScriptRequest(String from, JSONObject req) { if (mActivityScript == null) return;// w w w .j a va2 s. c o m try { JSONObject response = new JSONObject(); response.put("scriptResponse", true); response.put("requestId", req.optString("requestId")); response.put("script", mActivityScript.getJSON()); sendMessageToActor(from, response); } catch (JSONException e) { e.printStackTrace(System.err); } }
From source file:edu.stanford.junction.provider.irc.Junction.java
@Override public ActivityScript getActivityScript() { scriptQ.clear();/*w w w . ja v a 2s .co m*/ JSONObject req = new JSONObject(); String requestId = UUID.randomUUID().toString(); try { req.put("scriptRequest", "true"); req.put("requestId", requestId); sendMessageToSession(req); } catch (JSONException e) { e.printStackTrace(System.err); return null; } try { int maxTries = 5; long maxWaitPerTry = 2000L; for (int i = 0; i < maxTries; i++) { JSONObject response = scriptQ.poll(maxWaitPerTry, TimeUnit.MILLISECONDS); if (response == null) { return null; } else if (response.optString("requestId").equals(requestId)) { JSONObject script = response.optJSONObject("script"); return new ActivityScript(script); } } } catch (InterruptedException e) { return null; } return null; }
From source file:org.nuclearbunny.icybee.net.impl.BitlyImpl.java
public String shrinkURL(String url) throws IOException { /**/* w w w . j a v a2 s . co m*/ * bit.ly provides an elegant REST API that returns results in either JSON * or XML format. See http://bitly.com/app/developers for more information. */ StringBuilder buffer = new StringBuilder(BITLY_URL); buffer.append("?version=2.0.1").append("&format=json").append("&login=").append(BITLY_API_LOGIN) .append("&apiKey=").append(BITLY_API_KEY).append("&longUrl=") .append(URLEncoder.encode(url, "UTF-8")); URL bitlyURL = new URL(buffer.toString()); URLConnection connection = bitlyURL.openConnection(); String newURL = url; try { BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); JSONObject jsonObject = new JSONObject(new JSONTokener(in)); if ("OK".equals(jsonObject.opt("statusCode"))) { JSONObject results = (JSONObject) jsonObject.get("results"); results = (JSONObject) results.get(url); newURL = results.get("shortUrl").toString(); } } catch (JSONException e) { e.printStackTrace(System.err); throw new IOException(e.getMessage()); } return newURL; }