List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:edu.gmu.csiss.automation.pacs.utils.BaseTool.java
/** * Get classpath/*from w w w. j a v a2 s .c o m*/ * @return * class path */ public static String getClassPath() { if (isNull(_classpath)) { String dir = new BaseTool().getClass().getClassLoader().getResource("").getPath(); // dir = dir.replaceAll("\\%20", " "); //commented by Ziheng on 8/29/2015 try { dir = URLDecoder.decode(dir, "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } _classpath = dir; } return _classpath; }
From source file:com.pti.mates.ServerUtilities.java
/** * Register this account/device pair within the server. *//*w w w.j a v a2 s. c o m*/ public static void register(String fbid, String regId, Context ctx) { Utils utils = new Utils(ctx); DefaultHttpClient client = new MyHttpClient(ctx); HttpPost post = new HttpPost("https://54.194.14.115:443/register"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("matesid", fbid)); Log.d("REGISTERBACK", "matesId = " + fbid); nameValuePairs.add(new BasicNameValuePair("gcmid", regId)); Log.d("regIdBACK", regId); try { post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Execute the Post call and obtain the response HttpResponse postResponse; try { Log.d("REGISTERBACK", "ENTRO TRY"); postResponse = client.execute(post); HttpEntity responseEntity = postResponse.getEntity(); InputStream is = responseEntity.getContent(); s = utils.convertStreamToString(is); Log.d("S REGISTER", s); } catch (ClientProtocolException e) { Log.e("ERROR", e.toString()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); Log.e("ERROR", e.toString()); s = "ERROR: " + e.toString() + " :("; } Log.d("CHIVATO registe", "FIN THREAD"); //doRegister = new DoRegister(fbid,regId,ctx); //doRegister.execute(); Intent intent = new Intent(ctx, LogOk.class); ctx.startActivity(intent); }
From source file:com.pti.mates.ServerUtilities.java
public static void sendPreferences(SharedPreferences prefs, Context ctx) { //enviar preferencies al server Log.v(LogConstants.LOG_SERVERUTILITIES, "radius = " + prefs.getString(Common.RADIUS_KEY, "Empty")); Log.v(LogConstants.LOG_SERVERUTILITIES, "gender = " + prefs.getString(Common.GENDER_KEY, "Empty")); Log.v(LogConstants.LOG_SERVERUTILITIES, "interested in = " + prefs.getString(Common.INTERESTED_IN_KEY, "Empty")); String fbid = Common.getFBID(); DefaultHttpClient client = new MyHttpClient(ctx); HttpPost post = new HttpPost("https://54.194.14.115:443/user"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("id", fbid)); try {/*from w ww.j a va 2 s.c om*/ post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Execute the Post call and obtain the response HttpResponse postResponse; JSONObject user; try { postResponse = client.execute(post); HttpEntity responseEntity = postResponse.getEntity(); InputStream is = responseEntity.getContent(); try { user = new JSONObject(convertStreamToString(is)); user.put("gender", prefs.getString(Common.GENDER_KEY, "Empty")); user.put("interested_in", prefs.getString(Common.INTERESTED_IN_KEY, "Empty")); user.put("distance", prefs.getString(Common.RADIUS_KEY, "Empty")); updatePreferences(user, ctx, fbid); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (ClientProtocolException e) { Log.e("ERROR", e.toString()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); Log.e("ERROR", e.toString()); s = "ERROR: " + e.toString() + " :("; } Log.d("CHIVATO", "FIN THREAD"); }
From source file:com.ushahidi.android.app.net.MainHttpClient.java
public static String GetText(InputStream in) { String text = ""; BufferedReader reader = null; try {// w w w . j a v a 2 s . c om reader = new BufferedReader(new InputStreamReader(in, "UTF-8"), 1024); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } final StringBuilder sb = new StringBuilder(); String line = null; try { if (reader != null) { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } text = sb.toString(); } } catch (final Exception ex) { } finally { try { in.close(); } catch (final Exception ex) { } } return text; }
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
public static HTTPResponse sendHTTPPostWithURLParams(String url, List<NameValuePair> params, HashMap<String, String> headers) { HttpPost post = null;/*w w w.j av a 2 s .co m*/ HttpResponse response = null; CloseableHttpClient httpclient = null; HTTPResponse httpResponse = new HTTPResponse(); try { httpclient = (CloseableHttpClient) createHttpClient(); post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(params)); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } response = httpclient.execute(post); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); } catch (IOException e) { e.printStackTrace(); } StringBuffer result = new StringBuffer(); String line = ""; try { while ((line = rd.readLine()) != null) { result.append(line); } } catch (IOException e) { e.printStackTrace(); } httpResponse.setResponseCode(response.getStatusLine().getStatusCode()); httpResponse.setResponse(result.toString()); return httpResponse; }
From source file:setiquest.renderer.Utils.java
/** * Send a random BSON file.// www .j a v a2 s.c o m * @return the response from the web server. */ public static String sendRandomBsonFile() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(getOfflineSubjectsURL()); String filename = getRandomFile(getBsonDataDir()); File f = new File(filename); if (!f.exists()) { Log.log("sendRandonBsonFile(): File \"" + filename + "\" does not exists."); return "sendRandonBsonFile(): File \"" + filename + "\" does not exists."; } //Parse info from the name. //Old file = act1207.1.5.bson = actId, pol, subchannel //New file name: act1207.1.0.5.bson = actid, pol, obsType, subchannel int actId = 0; int obsId = 0; int pol = 0; String subchannel = "0"; String shortName = f.getName(); String[] parts = shortName.split("\\."); if (parts.length == 4) //Old name type { actId = Integer.parseInt(parts[0].substring(3)); obsId = 0; //Default to this. pol = Integer.parseInt(parts[1]); subchannel = parts[2]; } else if (parts.length == 5) //New name type { actId = Integer.parseInt(parts[0].substring(3)); pol = Integer.parseInt(parts[1]); obsId = Integer.parseInt(parts[2]); subchannel = parts[3]; } else { Log.log("sendRandonBsonFile(): bad bson file name: " + shortName); return "sendRandonBsonFile(): bad bson file name: " + shortName; } Log.log("Sending " + filename + ", Act:" + actId + ", Obs type:" + obsId + ", Pol" + pol + ", subchannel:" + subchannel); FileBody bin = new FileBody(new File(filename)); try { StringBody comment = new StringBody("Filename: " + filename); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("file", bin); reqEntity.addPart("type", new StringBody("data/bson")); reqEntity.addPart("subject[activity_id]", new StringBody("" + actId)); reqEntity.addPart("subject[observation_id]", new StringBody("" + obsId)); reqEntity.addPart("subject[pol]", new StringBody("" + pol)); reqEntity.addPart("subject[subchannel]", new StringBody("" + subchannel)); httppost.setEntity(reqEntity); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); //Log.log(response.toString()); String sendResult = "Sending: " + shortName + "\n"; sendResult += "subject[activity_id]: " + actId + "\n"; sendResult += "subject[observation_id]: " + obsId + "\n"; sendResult += "subject[pol]: " + pol + "\n"; sendResult += "subject[subchannel]: " + subchannel + "\n"; sendResult += response.toString() + "|\n"; return sendResult; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return "undefined"; }
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
public static HTTPResponse sendHTTPPost(String url, String payload, HashMap<String, String> headers) { HttpPost post = null;//from w w w . j av a 2 s . c o m HttpResponse response = null; HTTPResponse httpResponse = new HTTPResponse(); CloseableHttpClient httpclient = null; try { httpclient = (CloseableHttpClient) createHttpClient(); StringEntity requestEntity = new StringEntity(payload, Constants.UTF_8); post = new HttpPost(url); post.setEntity(requestEntity); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } response = httpclient.execute(post); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); } catch (IOException e) { e.printStackTrace(); } StringBuffer result = new StringBuffer(); String line = ""; try { while ((line = rd.readLine()) != null) { result.append(line); } } catch (IOException e) { e.printStackTrace(); } httpResponse.setResponseCode(response.getStatusLine().getStatusCode()); httpResponse.setResponse(result.toString()); try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } return httpResponse; }
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, HttpEntity entity, HashMap<String, String> headers) { HttpPost post = null;/*from w ww.ja v a 2 s . c o m*/ HttpResponse response = null; HTTPResponse httpResponse = new HTTPResponse(); CloseableHttpClient httpclient = null; try { httpclient = (CloseableHttpClient) createHttpClient(); post = new HttpPost(url); post.setEntity(entity); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken); response = httpclient.execute(post); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); } catch (IOException e) { e.printStackTrace(); } StringBuffer result = new StringBuffer(); String line = ""; try { while ((line = rd.readLine()) != null) { result.append(line); } } catch (IOException e) { e.printStackTrace(); } httpResponse.setResponseCode(response.getStatusLine().getStatusCode()); httpResponse.setResponse(result.toString()); try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } return httpResponse; }
From source file:tradeok.HttpTool.java
@SuppressWarnings("deprecation") public static String invokeGet(String url, Map<String, String> params, String encode, int connectTimeout) throws Exception { String responseString = null; RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(connectTimeout) .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(connectTimeout) .setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build(); StringBuilder sb = new StringBuilder(); sb.append(url);/* ww w .jav a2 s.c o m*/ int i = 0; if (params != null) { for (Entry<String, String> entry : params.entrySet()) { if (i == 0 && !url.contains("?")) { sb.append("?"); } else { sb.append("&"); } sb.append(entry.getKey()); sb.append("="); String value = entry.getValue(); try { sb.append(URLEncoder.encode(value, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.out.printf("\nwarn:encode http get params error, value is " + value, e); sb.append(URLEncoder.encode(value)); } i++; } } // System.out.printf("\ninfo:[HttpUtils Get] begin invoke:" // + sb.toString()); HttpGet get = new HttpGet(sb.toString()); get.setConfig(requestConfig); get.setHeader("Connection", "keep-alive"); try { CloseableHttpResponse response = httpclient.execute(get); try { HttpEntity entity = response.getEntity(); try { if (entity != null) { responseString = EntityUtils.toString(entity, encode); } } finally { if (entity != null) { entity.getContent().close(); } } } finally { if (response != null) { response.close(); } } } finally { get.releaseConnection(); } return responseString; }
From source file:com.breadwallet.tools.security.RequestHandler.java
private static boolean tryAndProcessRequestURL(RequestObject requestObject) { String theURL = null;//from w w w . j av a2 s. c o m String url = requestObject.r; synchronized (lockObject) { try { theURL = URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return false; } new PaymentProtocolTask().execute(theURL, requestObject.label); } return true; }