List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:ca.ualberta.cs.swapmyride.Misc.SaveUserRunnable.java
public void run() { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpAdd = new HttpPost(url); HttpResponse response;//ww w.j av a 2s.co m StringEntity stringEntity = null; try { stringEntity = new StringEntity(gson.toJson(user)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } httpAdd.setEntity(stringEntity); httpAdd.setHeader("Accept", "application/json"); //possible IO Error and an HTTP apache error try { response = httpClient.execute(httpAdd); String status = response.getStatusLine().toString(); Log.i("NetworkDataManager", status); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.umass.cs.nio.AbstractJSONPacketDemultiplexer.java
protected JSONObject processHeader(byte[] message, int offset, NIOHeader header, boolean cacheStringified) { try {/*from ww w . j a v a 2 s. c o m*/ if (JSONPacket.couldBeJSON(message, offset)) // quick reject if not return MessageExtractor.stampAddressIntoJSONObject(header.sndr, header.rcvr, MessageExtractor.parseJSON( MessageExtractor.decode(message, offset, message.length - offset), cacheStringified)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:jp.ambrosoli.http.server.action.IndexAction.java
@Execute(validator = false) public String helloWorld() { String name = this.request.getParameter("name"); String queryString = this.requestScope.get("javax.servlet.forward.query_string"); String[] query = StringUtils.split(queryString, "="); if (ArrayUtils.isNotEmpty(query)) { try {//from www .ja v a 2 s .co m name = URLDecoder.decode(query[1], this.request.getCharacterEncoding()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if (StringUtils.isEmpty(name)) { this.response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } ResponseUtil.write("Hello, " + name + "!", "UTF-8"); return null; }
From source file:JsonParser.java
public JSONObject getJSONFromUrl(String url) { // make HTTP request try {/*from w ww .jav a 2 s . c om*/ DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); InputStream inputStream = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8); JSONObject jsonObject = createJsonObject(reader); inputStream.close(); return jsonObject; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.l2jfree.network.ReceivableBasePacket.java
protected final String readS() { String result = null;/*from w w w. j a va2s . co m*/ try { result = new String(_data, _off, _data.length - _off, "UTF-16LE"); result = result.substring(0, result.indexOf(0x00)); _off += result.length() * 2 + 2; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; }
From source file:com.spectralogic.ds3cli.views.json.CommandExceptionJsonView.java
@Override public String render(final CommandException obj) throws JsonProcessingException { final CommonJsonView view = CommonJsonView.newView(CommonJsonView.Status.ERROR); final Map<String, String> jsonBackingMap = new TreeMap<>(); view.message(obj.getMessage());// w ww .j a v a 2s . c o m try { final ObjectMapper mapper = new ObjectMapper(); if (obj.getCause() != null) { if (obj.getCause() instanceof FailedRequestException) { final FailedRequestException ce = (FailedRequestException) obj.getCause(); jsonBackingMap.put("StatusCode", Integer.toString(ce.getStatusCode())); jsonBackingMap.put("ApiErrorMessage", ce.getResponseString()); } else { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final PrintWriter pOut = new PrintWriter(out); obj.printStackTrace(pOut); try { jsonBackingMap.put("StackTrace", out.toString("utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(view.data(jsonBackingMap)); } catch (final Exception e) { return "Failed to render error: " + e.getMessage(); } }
From source file:com.savvywits.wethepeople.RESTService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w w w .java2s . c o m*/ ResultReceiver receiver = extras.getParcelable("receiver"); String data = extras.getString("zipcode"); String url = ZIP_CODE_BASE + data; Bundle bundle = new Bundle(); receiver.send(STATUS_RUNNING, Bundle.EMPTY); try { String json = EntityUtils.toString(new DefaultHttpClient().execute(new HttpGet(url)).getEntity()); if (!validateJSON(json)) { receiver.send(STATUS_ERROR, Bundle.EMPTY); } else { bundle.putString("rest_result", json); receiver.send(STATUS_FINISHED, bundle); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { bundle.putString(Intent.EXTRA_TEXT, e.toString()); receiver.send(STATUS_ERROR, bundle); } }
From source file:com.rastating.droidbeard.net.SearchTvDBTask.java
@Override protected TvDBResult[] doInBackground(String... strings) { String name = null;/*w w w.jav a 2 s . com*/ try { name = URLEncoder.encode(strings[0], "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); name = strings[0]; } try { String json = getJson("sb.searchtvdb", "name", name); List<TvDBResult> list = new ArrayList<TvDBResult>(); if (json != null && !json.equals("")) { JSONArray results = new JSONObject(json).getJSONObject("data").getJSONArray("results"); for (int i = 0; i < results.length(); i++) { JSONObject result = results.getJSONObject(i); TvDBResult tvDBResult = new TvDBResult(); tvDBResult.setFirstAired(result.getString("first_aired")); tvDBResult.setName(result.getString("name")); tvDBResult.setId(result.getLong("tvdbid")); list.add(tvDBResult); } return list.toArray(new TvDBResult[list.size()]); } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.l2jfree.network.SendableBasePacket.java
protected final void writeS(String text) { if (text != null) { try {//from w w w . ja va 2 s. com final byte[] bytes = text.getBytes("UTF-16LE"); _bao.write(bytes, 0, bytes.length); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } _bao.write(0); _bao.write(0); }
From source file:com.QuarkLabs.BTCeClientJavaFX.networking.App.java
public void getTransactionsHistory() { try {//from ww w . j ava 2 s .c o m authRequest.makeRequest("TransHistory", null); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }