Example usage for java.io UnsupportedEncodingException printStackTrace

List of usage examples for java.io UnsupportedEncodingException printStackTrace

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:marytts.util.string.StringUtils.java

public static String urlDecode(String strRequest) {
    //decoded = StringUtils.replace(strRequest, "%20", " ");  

    String decoded = strRequest;//from  w w  w .j  a  va  2s .co m
    try {
        decoded = URLDecoder.decode(decoded, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //decoded = StringUtils.replace(decoded, "_HTTPREQUESTLINEBREAK_", System.getProperty("line.separator"));

    return decoded;
}

From source file:cn.usually.common.pay.union.sdk.SecureUtil.java

/**
 * md5?16?// www  .  j a  va  2 s  .com
 * 
 * @param datas
 *            ?
 * @param encoding
 *            ?
 * @return 
 */
public static byte[] md5X16(String datas, String encoding) {
    byte[] bytes = md5(datas, encoding);
    StringBuilder md5StrBuff = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        if (Integer.toHexString(0xFF & bytes[i]).length() == 1) {
            md5StrBuff.append("0").append(Integer.toHexString(0xFF & bytes[i]));
        } else {
            md5StrBuff.append(Integer.toHexString(0xFF & bytes[i]));
        }
    }
    try {
        return md5StrBuff.toString().getBytes(encoding);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:cn.usually.common.pay.union.sdk.SecureUtil.java

/**
 * sha1?16?/* w w w  . java2  s.  com*/
 * 
 * @param data
 *            ?
 * @param encoding
 *            ?
 * @return 
 */
public static byte[] sha1X16(String data, String encoding) {
    byte[] bytes = sha1(data, encoding);
    StringBuilder sha1StrBuff = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        if (Integer.toHexString(0xFF & bytes[i]).length() == 1) {
            sha1StrBuff.append("0").append(Integer.toHexString(0xFF & bytes[i]));
        } else {
            sha1StrBuff.append(Integer.toHexString(0xFF & bytes[i]));
        }
    }
    try {
        return sha1StrBuff.toString().getBytes(encoding);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.mobile.blue.util.payyl.SDKUtil.java

/**
 * ???customerInfo???? pinphoneNocvn2expired <br>
 *  <br>//  w w  w .  j  a v  a 2s.c om
 * 
 * @param customerInfoMap
 *            ?? key???value?,? <br>
 *            customerInfoMap.put("certifTp", "01"); //? <br>
 *            customerInfoMap.put("certifId", "341126197709218366"); //???
 *            <br>
 *            customerInfoMap.put("customerNm", "?"); //?? <br>
 *            customerInfoMap.put("smsCode", "123456"); //?? <br>
 *            customerInfoMap.put("pin", "111111"); //? <br>
 *            customerInfoMap.put("phoneNo", "13552535506"); //? <br>
 *            customerInfoMap.put("cvn2", "123"); //??cvn2? <br>
 *            customerInfoMap.put("expired", "1711"); // ?? <br>
 * @param accNo
 *            customerInfoMap?????,customerInfoMap??PIN???<br>
 * @param encoding
 *            ?encoding
 * @return base64???? <br>
 */
public static String getCustomerInfoWithEncrypt(Map<String, String> customerInfoMap, String accNo,
        String encoding) {

    StringBuffer sf = new StringBuffer("{");
    // ??
    StringBuffer encryptedInfoSb = new StringBuffer("");

    for (Iterator<String> it = customerInfoMap.keySet().iterator(); it.hasNext();) {
        String key = it.next();
        String value = customerInfoMap.get(key);
        if (key.equals("phoneNo") || key.equals("cvn2") || key.equals("expired")) {
            encryptedInfoSb.append(key + SDKConstants.EQUAL + value + SDKConstants.AMPERSAND);
        } else {
            if (key.equals("pin")) {
                if (null == accNo || "".equals(accNo.trim())) {
                    LogUtil.writeLog(
                            "??PINgetCustomerInfoWithEncrypt???");
                    return "{}";
                } else {
                    value = SDKUtil.encryptPin(accNo, value, encoding);
                }
            }
            if (it.hasNext())
                sf.append(key + SDKConstants.EQUAL + value + SDKConstants.AMPERSAND);
            else
                sf.append(key + SDKConstants.EQUAL + value);
        }
    }

    if (!encryptedInfoSb.toString().equals("")) {
        // ?&?
        encryptedInfoSb.setLength(encryptedInfoSb.length() - 1);

        LogUtil.writeLog("customerInfo encryptedInfo" + encryptedInfoSb.toString());
        if (sf.toString().equals("{")) // phoneNocvn2expired?&
            sf.append("encryptedInfo" + SDKConstants.EQUAL);
        else
            sf.append(SDKConstants.AMPERSAND + "encryptedInfo" + SDKConstants.EQUAL);

        sf.append(SDKUtil.encryptEpInfo(encryptedInfoSb.toString(), encoding));
    }
    sf.append("}");

    String customerInfo = sf.toString();
    LogUtil.writeLog("customerInfo" + customerInfo);
    try {
        return new String(SecureUtil.base64Encode(sf.toString().getBytes(encoding)));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return customerInfo;
}

From source file:com.haoqee.chatsdk.net.Utility.java

public static String encodeUrl(BaseParameters parameters) {
    if (parameters == null) {
        return "";
    }/*  w w  w .j  a v a2  s.  com*/

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (int loc = 0; loc < parameters.size(); loc++) {
        if (first)
            first = false;
        else {
            sb.append("&");
        }
        try {
            sb.append(URLEncoder.encode(parameters.getKey(loc), "UTF-8") + "="
                    + URLEncoder.encode(parameters.getValue(loc), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return sb.toString();
}

From source file:com.imaginary.home.controller.CloudService.java

static CloudService pair(@Nonnull String name, @Nonnull String endpoint, @Nullable String proxyHost,
        int proxyPort, @Nonnull String pairingToken) throws CommunicationException, ControllerException {
    HttpClient client = getClient(endpoint, proxyHost, proxyPort);
    HttpPost method = new HttpPost(endpoint + "/relay");

    method.addHeader("Content-Type", "application/json");
    method.addHeader("x-imaginary-version", VERSION);
    method.addHeader("x-imaginary-timestamp", String.valueOf(System.currentTimeMillis()));

    HashMap<String, Object> body = new HashMap<String, Object>();

    body.put("pairingCode", pairingToken);
    body.put("name", HomeController.getInstance().getName());
    try {/*w  ww .ja v a 2s .  c  om*/
        //noinspection deprecation
        method.setEntity(new StringEntity((new JSONObject(body)).toString(), "application/json", "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new ControllerException(e);
    }
    HttpResponse response;
    StatusLine status;

    try {
        response = client.execute(method);
        status = response.getStatusLine();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CommunicationException(e);
    }
    if (status.getStatusCode() == HttpServletResponse.SC_CREATED) {
        HttpEntity entity = response.getEntity();

        if (entity == null) {
            throw new CommunicationException(status.getStatusCode(), "No error, but no body");
        }
        String json;

        try {
            json = EntityUtils.toString(entity);
        } catch (IOException e) {
            throw new ControllerException(e);
        }
        try {
            JSONObject ob = new JSONObject(json);
            String apiKeyId = null, apiSecret = null;

            if (ob.has("apiKeyId") && !ob.isNull("apiKeyId")) {
                apiKeyId = ob.getString("apiKeyId");
            }
            if (ob.has("apiKeySecret") && !ob.isNull("apiKeySecret")) {
                apiSecret = ob.getString("apiKeySecret");
            }
            if (apiKeyId == null || apiSecret == null) {
                throw new CommunicationException(status.getStatusCode(),
                        "Invalid JSON response to pairing request");
            }
            return new CloudService(apiKeyId, apiSecret, name, endpoint, proxyHost, proxyPort);
        } catch (JSONException e) {
            throw new CommunicationException(e);
        }

    } else {
        HttpEntity entity = response.getEntity();

        if (entity == null) {
            throw new CommunicationException(status.getStatusCode(),
                    "An error was returned without explanation");
        }
        String json;

        try {
            json = EntityUtils.toString(entity);
        } catch (IOException e) {
            throw new ControllerException(e);
        }
        throw new CommunicationException(status.getStatusCode(), json);
    }
}

From source file:com.ibm.devops.dra.AbstractDevOpsAction.java

public static String getAppId(String token, String appName, String orgName, String spaceName,
        String environment, Boolean debug_mode) {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    String apps_url = chooseAppsUrl(environment);
    if (debug_mode) {
        LOGGER.info("GET APPS_GUID URL:" + apps_url + appName + ORG + orgName + SPACE + spaceName);
    }/*  w  ww. j  a v a2 s .c  om*/

    try {
        HttpGet httpGet = new HttpGet(apps_url + URLEncoder.encode(appName, "UTF-8").replaceAll("\\+", "%20")
                + ORG + URLEncoder.encode(orgName, "UTF-8").replaceAll("\\+", "%20") + SPACE
                + URLEncoder.encode(spaceName, "UTF-8").replaceAll("\\+", "%20"));

        httpGet = addProxyInformation(httpGet);

        httpGet.setHeader("Authorization", token);
        CloseableHttpResponse response = null;

        response = httpClient.execute(httpGet);
        String resStr = EntityUtils.toString(response.getEntity());

        if (debug_mode) {
            LOGGER.info("RESPONSE FROM APPS API:" + response.getStatusLine().toString());
        }
        if (response.getStatusLine().toString().contains("200")) {
            // get 200 response
            JsonParser parser = new JsonParser();
            JsonElement element = parser.parse(resStr);
            JsonObject obj = element.getAsJsonObject();
            JsonArray resources = obj.getAsJsonArray("resources");

            if (resources.size() > 0) {
                JsonObject resource = resources.get(0).getAsJsonObject();
                JsonObject metadata = resource.getAsJsonObject("metadata");
                if (debug_mode) {
                    LOGGER.info("APP_ID:" + String.valueOf(metadata.get("guid")).replaceAll("\"", ""));
                }
                return String.valueOf(metadata.get("guid")).replaceAll("\"", "");
            } else {
                if (debug_mode) {
                    LOGGER.info("RETURNED NO APPS.");
                }
                return null;
            }

        } else {
            if (debug_mode) {
                LOGGER.info("RETURNED STATUS CODE OTHER THAN 200. RESPONSE: "
                        + response.getStatusLine().toString());
            }
            return null;
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.ibm.devops.dra.AbstractDevOpsAction.java

/**
 * Get a list of policies that belong to an org
 * @param token//from   w  w w . ja v  a2  s . c o m
 * @param orgName
 * @return
 */

public static ListBoxModel getPolicyList(String token, String orgName, String toolchainName, String environment,
        Boolean debug_mode) {

    // get all jenkins job
    ListBoxModel emptybox = new ListBoxModel();
    emptybox.add("", "empty");

    String url = choosePoliciesUrl(environment);

    try {
        url = url.replace("{org_name}", URLEncoder.encode(orgName, "UTF-8").replaceAll("\\+", "%20"));
        url = url.replace("{toolchain_name}",
                URLEncoder.encode(toolchainName, "UTF-8").replaceAll("\\+", "%20"));
        if (debug_mode) {
            LOGGER.info("GET POLICIES URL:" + url);
        }

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);

        httpGet = addProxyInformation(httpGet);

        httpGet.setHeader("Authorization", token);
        CloseableHttpResponse response = null;
        response = httpClient.execute(httpGet);
        String resStr = EntityUtils.toString(response.getEntity());

        if (debug_mode) {
            LOGGER.info("RESPONSE FROM GET POLICIES URL:" + response.getStatusLine().toString());
        }
        if (response.getStatusLine().toString().contains("200")) {
            // get 200 response
            JsonParser parser = new JsonParser();
            JsonElement element = parser.parse(resStr);
            JsonArray jsonArray = element.getAsJsonArray();

            ListBoxModel model = new ListBoxModel();

            for (int i = 0; i < jsonArray.size(); i++) {
                JsonObject obj = jsonArray.get(i).getAsJsonObject();
                String name = String.valueOf(obj.get("name")).replaceAll("\"", "");
                model.add(name, name);
            }
            if (debug_mode) {
                LOGGER.info("POLICY LIST:" + model);
                LOGGER.info("#######################");
            }
            return model;
        } else {
            if (debug_mode) {
                LOGGER.info("RETURNED STATUS CODE OTHER THAN 200. RESPONSE: "
                        + response.getStatusLine().toString());
            }
            return emptybox;
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return emptybox;
}

From source file:org.umit.icm.mobile.utils.ProfilerRun.java

private static void profileAggrGetSuperPeerList() {
    Profiler profiler = new Profiler();
    profiler.runProfiler(new TaskInterface() {
        public void task() {

            GetSuperPeerList getSuperPeerList = GetSuperPeerList.newBuilder().build();

            try {
                boolean bool = AggregatorRetrieve.getSuperPeerList(getSuperPeerList);
                if (bool == true)
                    Log.w(taskName(), "true");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();// w w  w .j a va  2  s. c  o m
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public String taskName() {
            return "AggrComm GetSuperPeerList";
        }
    });
}

From source file:org.umit.icm.mobile.utils.ProfilerRun.java

private static void profileAggrGetPeerList() {
    Profiler profiler = new Profiler();
    profiler.runProfiler(new TaskInterface() {
        public void task() {

            GetPeerList getPeerList = GetPeerList.newBuilder().build();

            try {
                boolean bool = AggregatorRetrieve.getPeerList(getPeerList);
                if (bool == true)
                    Log.w(taskName(), "true");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();/*www.j  av a  2s .com*/
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public String taskName() {
            return "AggrComm GetPeerList";
        }
    });
}