List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:com.atomicleopard.thundr.gae.channels.ChannelService.java
private static final String limitTo64Bytes(String clientId) { try {//from w w w. j ava 2s. c o m byte[] bytes = clientId.getBytes("UTF-8"); byte[] newBytes = Arrays.copyOfRange(bytes, Math.max(0, bytes.length - 64), bytes.length); return new String(newBytes, "UTF-8"); } catch (UnsupportedEncodingException e) { Logger.warn( "Unsupported encoding exception while determining clientId, making a best guess and continuing: %s", e.getMessage()); return StringUtils.reverse(StringUtils.reverse(clientId).substring(0, 64)); } }
From source file:org.bfr.querytools.google.GoogleSpectrumQuery.java
public static void query(double latitude, double longitude) { HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost("https://www.googleapis.com/rpc"); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10 * 1000); HttpConnectionParams.setSoTimeout(client.getParams(), 10 * 1000); request.addHeader("Content-Type", "application/json"); try {/* ww w . ja v a 2 s . co m*/ request.setEntity(new StringEntity(createQuery(latitude, longitude).toString(), HTTP.UTF_8)); Logger.log(String.format("google-query-execute %.4f %.4f", latitude, longitude)); HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; boolean first = true; while ((line = rd.readLine()) != null) { if (first) { Logger.log("google-query-first-data"); first = false; } Logger.log(line); } } catch (UnsupportedEncodingException e) { Logger.log("google-query-error Unsupported Encoding: " + e.getMessage()); } catch (JSONException e) { Logger.log("google-query-error JSON exception: " + e.getMessage()); } catch (IOException e) { Logger.log("google-query-error i/o exception: " + e.getMessage()); } Logger.log("google-query-done"); }
From source file:org.wso2.carbon.ganalytics.publisher.GoogleAnalyticsDataPublisher.java
private static String encodeString(String queryString) { try {/*from ww w. j av a 2 s . c om*/ return URLEncoder.encode(queryString, "UTF-8"); } catch (UnsupportedEncodingException e) { log.warn("Error while percent encoding analytics payload string. Using unencoded string. " + e.getMessage()); } return queryString; }
From source file:acp.sdk.SDKUtil.java
/** * key=value&key=value?Map/* w w w. j a va 2 s.c om*/ * * @param result * @return */ public static Map<String, String> convertResultStringToMap(String result) { Map<String, String> map = null; try { if (StringUtils.isNotBlank(result)) { if (result.startsWith("{") && result.endsWith("}")) { System.out.println(result.length()); result = result.substring(1, result.length() - 1); } map = parseQString(result); } } catch (UnsupportedEncodingException e) { LogUtil.writeErrorLog(e.getMessage(), e); } return map; }
From source file:com.brobwind.brodm.NetworkUtils.java
public static void runCommand(HttpClient client, String token, String url, String cmd, OnMessage callback) { HttpPost request = new HttpPost(url); request.addHeader("Authorization", "Basic " + token); request.addHeader("Content-Type", "application/json"); try {/*from ww w .ja v a2s.c om*/ StringEntity content = new StringEntity(cmd); request.setEntity(content); } catch (UnsupportedEncodingException e) { e.printStackTrace(); callback.onMessage(null, e.getMessage()); return; } try { HttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK) { Log.v(TAG, " -> ABORT: " + response.getStatusLine()); request.abort(); callback.onMessage(null, "ABORT: " + response.getStatusLine()); return; } String result = EntityUtils.toString(response.getEntity()); Log.v(TAG, " -> RESULT: " + result); callback.onMessage(result, null); return; } catch (Exception e) { e.printStackTrace(); callback.onMessage(null, e.getMessage()); } }
From source file:org.echocat.jomon.net.http.HttpUtils.java
@Nonnull public static String urlDecode(@Nonnull String encodedString) { try {//w w w .j ava 2s . c o m return URLDecoder.decode(encodedString, "UTF-8"); } catch (final UnsupportedEncodingException e) { // Should never happen. throw new RuntimeException(e.getMessage(), e); } }
From source file:cn.mrdear.pay.util.WebUtils.java
/** * POST//from www . ja v a 2s . com * * @param url * URL * @param inputStreamEntity * * @return */ public static String post(String url, InputStreamEntity inputStreamEntity) { String result = null; try { HttpPost httpPost = new HttpPost(url); inputStreamEntity.setContentEncoding("UTF-8"); httpPost.setEntity(inputStreamEntity); CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpPost); result = consumeResponse(httpResponse); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } catch (ClientProtocolException e) { throw new RuntimeException(e.getMessage(), e); } catch (ParseException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return result; }
From source file:com.bacic5i5j.framework.toolbox.web.WebUtils.java
/** * ??//from w w w.j ava 2 s . co m * * @param params * @param url * @return */ public static String post(Map<String, String> params, String url) { String result = ""; CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); List<NameValuePair> nvps = generateURLParams(params); try { httpPost.setEntity(new UrlEncodedFormEntity(nvps)); } catch (UnsupportedEncodingException e) { log.error(e.getMessage() + " : " + e.getCause()); } CloseableHttpResponse response = null; try { response = httpClient.execute(httpPost); } catch (IOException e) { log.error(e.getMessage() + " : " + e.getCause()); } if (response != null) { StatusLine statusLine = response.getStatusLine(); log.info("??: " + statusLine.getStatusCode()); if (statusLine.getStatusCode() == 200 || statusLine.getStatusCode() == 302) { try { InputStream is = response.getEntity().getContent(); int count = is.available(); byte[] buffer = new byte[count]; is.read(buffer); result = new String(buffer); } catch (IOException e) { log.error("???: " + e.getMessage()); } } } return result; }
From source file:cn.mrdear.pay.util.WebUtils.java
/** * POST/*w w w . jav a 2s.co m*/ * * @param url * URL * @param parameterMap * ? * @return */ public static String post(String url, Map<String, Object> parameterMap) { String result = null; try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Map.Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = String.valueOf(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpPost); result = consumeResponse(httpResponse); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } catch (ClientProtocolException e) { throw new RuntimeException(e.getMessage(), e); } catch (ParseException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return result; }
From source file:cn.mrdear.pay.util.WebUtils.java
/** * GET// w w w . j a va2 s . c o m * * @param url * URL * @param parameterMap * ? * @return */ public static String get(String url, Map<String, Object> parameterMap) { String result = null; try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Map.Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = String.valueOf(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } HttpGet httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"))); CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpGet); result = consumeResponse(httpResponse); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } catch (ParseException e) { throw new RuntimeException(e.getMessage(), e); } catch (ClientProtocolException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return result; }