List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:net.oauth.v2.example.provider.servlets.AccessTokenServlet2Test.java
public static String decodePercent(String s) { try {//from ww w. ja va 2s . c o m return URLDecoder.decode(s, "UTF-8"); // This implements http://oauth.pbwiki.com/FlexibleDecoding } catch (java.io.UnsupportedEncodingException wow) { throw new RuntimeException(wow.getMessage(), wow); } }
From source file:com.sforce.cd.apexUnit.client.codeCoverage.WebServiceInvoker.java
public static JSONObject doGet(String relativeServiceURL, String soql, String accessToken) { if (soql != null && !soql.equals("")) { try {//from w ww.ja va 2 s. c o m relativeServiceURL += "/query/?q=" + encode(soql, "UTF-8"); } catch (UnsupportedEncodingException e) { ApexUnitUtils.shutDownWithDebugLog(e, "Error encountered while trying to encode the query string using UTF-8 format. The error says: " + e.getMessage()); } } return doGet(relativeServiceURL, accessToken); }
From source file:com.vanda.beivandalibnetwork.utils.HttpUtils.java
/** * Encode url to specific character set/*from w w w . jav a 2 s . co m*/ * * @param str * @param charset * @return */ public static String encodeUrl(String str, String charset) { String url = str; try { url = URLEncoder.encode(str, charset); } catch (UnsupportedEncodingException e) { Logger.warn(TAG, "[encodeUrl]Could not encode url. Error >>> " + e.getMessage()); } return url; }
From source file:com.steeleforge.aem.ironsites.wcm.WCMUtil.java
/** * URL encode a given String, per a given encoding * /*from w w w. jav a 2s . c o m*/ * @param token * @param encoding, default to UTF-8 * @return URL encoded String * @throws UnsupportedEncodingException */ public static String getURLEncoded(String token, String encoding) throws UnsupportedEncodingException { if (StringUtils.isNotEmpty(token)) { try { if (StringUtils.isNotEmpty(encoding)) { return URLEncoder.encode(token, encoding); } return URLEncoder.encode(token, CharEncoding.UTF_8); } catch (UnsupportedEncodingException uee) { LOG.debug(uee.getMessage()); throw uee; } } return token; }
From source file:com.vanda.beivandalibnetwork.utils.HttpUtils.java
/** * Create a url encoded form with a given character encoding code. * //from w w w.j av a 2 s .c o m * @param enc * Encoding code * @param request * Post request * @param keyVals * @return */ public static HttpUriRequest urlEncodedForm(String enc, HttpPost request, Object... keyVals) { enc = ValidationUtils.isEmpty(enc) ? ENC_UTF8 : enc; if (request == null || ValidationUtils.isEmpty(keyVals)) return request; ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>(); for (int i = 0; i < keyVals.length; i += 2) { pairs.add(new BasicNameValuePair(CommonUtils.str(keyVals[i]), i + 1 < keyVals.length ? CommonUtils.str(keyVals[i + 1]) : ValidationUtils.EMPTY_STR)); } try { request.setEntity(new UrlEncodedFormEntity(pairs, enc)); } catch (UnsupportedEncodingException e) { Logger.warn(TAG, "[urlEncodedForm]Fill data to form entity failed. Caused by " + e.getMessage()); } return request; }
From source file:ddf.catalog.source.opensearch.OpenSearchSiteUtil.java
/** * Fills in the OpenSearch query URL with contextual information (Note: Section 2.2 - Query: The * OpenSearch specification does not define a syntax for its primary query parameter, * searchTerms, but it is generally used to support simple keyword queries.) * * @param client/*from w w w.j ava 2 s. co m*/ * @param searchPhrase */ public static void populateContextual(WebClient client, final String searchPhrase, List<String> parameters) { String queryStr = searchPhrase; if (queryStr != null) { try { queryStr = URLEncoder.encode(queryStr, "UTF-8"); } catch (UnsupportedEncodingException uee) { LOGGER.warn("Could not encode contextual string: {}", uee.getMessage()); } } checkAndReplace(client, queryStr, SEARCH_TERMS, parameters); }
From source file:cn.usually.common.pay.union.sdk.SDKUtil.java
/** * ???(SHA-1?)//from w w w .j ava 2s . co m * * @param resData * ? * @param encoding * ?? * @return */ public static boolean validate(Map<String, String> resData, String encoding) { LogUtil.writeLog("?"); if (isEmpty(encoding)) { encoding = "UTF-8"; } String stringSign = resData.get(SDKConstants.param_signature); // ?certId ????Map? String certId = resData.get(SDKConstants.param_certId); LogUtil.writeLog("??[" + certId + "]"); // Map???key1=value1&key2=value2? String stringData = coverMap2String(resData); LogUtil.writeLog("[" + stringData + "]"); try { // ???????. return SecureUtil.validateSignBySoft(CertUtil.getValidateKey(certId), SecureUtil.base64Decode(stringSign.getBytes(encoding)), SecureUtil.sha1X16(stringData, encoding)); } catch (UnsupportedEncodingException e) { LogUtil.writeErrorLog(e.getMessage(), e); } catch (Exception e) { LogUtil.writeErrorLog(e.getMessage(), e); } return false; }
From source file:com.jims.oauth2.common.utils.OAuthUtils.java
public static String decodePercent(String s) { try {/*from w w w . jav a2s . co m*/ return URLDecoder.decode(s, ENCODING); // This implements http://oauth.pbwiki.com/FlexibleDecoding } catch (UnsupportedEncodingException wow) { throw new RuntimeException(wow.getMessage(), wow); } }
From source file:com.jims.oauth2.common.utils.OAuthUtils.java
public static String percentEncode(String s) { if (s == null) { return ""; }//from w w w .ja v a 2 s . co m try { return URLEncoder.encode(s, ENCODING) // OAuth encodes some characters differently: .replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); // This could be done faster with more hand-crafted code. } catch (UnsupportedEncodingException wow) { throw new RuntimeException(wow.getMessage(), wow); } }
From source file:com.taobao.ad.easyschedule.commons.utils.JobUtil.java
/** * //from ww w. ja va 2 s. c om * @param jobId * @param jobDetail * @param target * @return */ public static JobResult executeRemoteJob(Long jobId, JobDetail jobDetail, String[] target) { JobResult result = JobResult.errorResult(JobResult.RESULTCODE_OTHER_ERR, " "); try { JobDataMap data = jobDetail.getJobDataMap(); HttpClient client = new HttpClient(); int retries = JobUtil.getJobRetries(data.getString(Constants.JOBDATA_RETRIES)); client.getHttpConnectionManager().getParams().setConnectionTimeout(Constants.JOB_MIN_CONN_TIMEOUT); client.getHttpConnectionManager().getParams().setSoTimeout(Constants.JOB_MAX_SO_TIMEOUT); GetMethod getMethod = null; for (int i = 1; i <= retries + 1; i++) { try { getMethod = new GetMethod(JobUtil.getJobTargetUrl(jobId, jobDetail, target)); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); } catch (UnsupportedEncodingException e) { logger.error("ShellJob.execute,jobCommand:URL", e); result = JobResult.errorResult(JobResult.RESULTCODE_PARAMETER_ILLEGAL, "URL" + e.getMessage()); return result; } try { int statusCode = client.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { ignoreLogger.warn(jobDetail.getFullName() + "" + i + "statuscode:" + statusCode); /*logger.warn(jobDetail.getFullName() + "" + i + "statuscode:" + statusCode);*/ result = JobResult.errorResult(JobResult.RESULTCODE_JOB_REQUEST_FAILURE, "? " + statusCode); Thread.sleep(Constants.JOB_RETRY_WAITTIME); if (i > 1) { result.getData().put(JobResult.JOBRESULT_DATA_RETRYCOUNT, String.valueOf(i)); } continue; } if (Constants.JOBDATA_CHECKRESULT_VAL_FALSE .equals(data.getString(Constants.JOBDATA_CHECKRESULT))) { result = new JobResult(true, JobResult.RESULTCODE_JOBRESULT_IGNORE, "" + i + "??"); break; } try { result = JSONObject.parseObject(getMethod.getResponseBodyAsString(), JobResult.class); if (i > 1) { result.getData().put(JobResult.JOBRESULT_DATA_RETRYCOUNT, String.valueOf(i)); } } catch (Exception e) { ignoreLogger.error(jobDetail.getFullName() + "?:" + e.getMessage()); /*logger.error(jobDetail.getFullName() + "?:" + e.getMessage());*/ result = JobResult.errorResult(JobResult.RESULTCODE_JOBRESULT_ILLEGAL, "?" + StringUtil.html(e.getMessage())); Thread.sleep(Constants.JOB_RETRY_WAITTIME); continue; } break; } catch (Exception e) { ignoreLogger.error(jobDetail.getFullName() + "" + i + "" + e); /*logger.error(jobDetail.getFullName() + "" + i + "" + e);*/ result = JobResult.errorResult(JobResult.RESULTCODE_JOB_REQUEST_FAILURE, "" + i + "" + e.getMessage()); try { Thread.sleep(Constants.JOB_RETRY_WAITTIME); } catch (InterruptedException e1) { } continue; } } } catch (Exception e) { logger.error("Job", e); result.setResultMsg(result.getResultMsg() + e.getMessage()); } return result; }