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:com.longtime.ajy.support.weixin.HttpsKit.java

/**
 * @param url//from w w  w  .ja va 2 s .  co m
 * @param params
 * @return
 */
private static String initParams(String url, Map<String, String> params) {
    if (null == params || params.isEmpty()) {
        return url;
    }
    StringBuilder sb = new StringBuilder(url);
    if (url.indexOf("?") == -1) {
        sb.append("?");
    } else {
        sb.append("&");
    }
    boolean first = true;
    for (Entry<String, String> entry : params.entrySet()) {
        if (first) {
            first = false;
        } else {
            sb.append("&");
        }
        String key = entry.getKey();
        String value = entry.getValue();
        sb.append(key).append("=");
        if (StringUtils.isNotEmpty(value)) {
            try {
                sb.append(URLEncoder.encode(value, DEFAULT_CHARSET));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                logger.error(url, e);
            }
        }
    }
    return sb.toString();
}

From source file:com.piusvelte.hydra.HydraRequest.java

public static HydraRequest fromPost(HttpServletRequest request) throws Exception {
    HydraRequest hydraRequest;/*from   w w  w.  j  a  v  a 2 s  .c om*/
    try {
        hydraRequest = new HydraRequest(request);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new Exception("bad parameter encoding");
    }
    if (!hydraRequest.hasDatabase())
        throw new Exception("no database");
    if (hydraRequest.hasColumns())
        hydraRequest.action = ACTION_INSERT;
    else if (hydraRequest.hasArguments())
        hydraRequest.action = ACTION_SUBROUTINE;
    else if (hydraRequest.hasCommand())
        hydraRequest.action = ACTION_EXECUTE;
    else
        throw new Exception("invalid request");
    return hydraRequest;
}

From source file:com.cnksi.core.web.utils.Servlets.java

/**
 * ???Request Parameters, copy from spring WebUtils.
 * //w  ww .  java2  s .co m
 * Parameter???.
 * 
 * @param dwzExport true|false ?ExcelValue???
 */
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix,
        boolean dwzExport) {

    Validate.notNull(request, "Request must not be null");
    Enumeration paramNames = request.getParameterNames();
    Map<String, Object> params = new TreeMap<String, Object>();
    if (prefix == null) {
        prefix = "";
    }
    while (paramNames != null && paramNames.hasMoreElements()) {
        String paramName = (String) paramNames.nextElement();
        if ("".equals(prefix) || paramName.startsWith(prefix)) {
            String unprefixed = paramName.substring(prefix.length());
            String[] values = request.getParameterValues(paramName);
            if (values == null || values.length == 0) {
                // Do nothing, no values found at all.
            } else if (values.length > 1) {
                params.put(unprefixed, values);
            } else {
                params.put(unprefixed, values[0]);
            }
        }
    }

    if (dwzExport) {
        Iterator<String> it = params.keySet().iterator();

        while (it.hasNext()) {
            try {
                String key = it.next();
                String value = params.get(key).toString();
                String encodedValue = new String(value.getBytes("ISO8859-1"), "UTF-8");

                params.put(key, encodedValue);

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

    return params;
}

From source file:com.justinbull.ichnaeachecker.IchnaeaRestClient.java

/**
 * Make a HTTP POST request to a URL with optional parameters
 * @param url URL to make to POST request to
 * @param payload The POST parameters/*from   w  ww .  j a  va 2 s.c o m*/
 * @param responseHandler The callback object that will handle request results
 */
private static RequestHandle jsonPost(String url, JSONObject payload,
        AsyncHttpResponseHandler responseHandler) {
    try {
        StringEntity entity = new StringEntity(payload.toString());
        entity.setContentType("application/json");
        return client.post(null, getAbsoluteUrl(url), entity, "application/json", responseHandler);
    } catch (UnsupportedEncodingException e) {
        // TODO deal with it
        Log.e(TAG, "jsonPost: Unable to serialize JSON payload. Silently failing");
        e.printStackTrace();
    }
    return null;
}

From source file:de.dakror.villagedefense.util.SaveHandler.java

public static String urlencode(String s) {
    try {//from   w w  w  . ja  v a 2  s. c  o  m
        return URLEncoder.encode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:edu.tum.cs.ias.knowrob.BarcodeWebLookup.java

public static String lookUpUpcDatabase(String ean) {

    String res = "";
    if (ean != null && ean.length() > 0) {

        HttpClient httpclient = new DefaultHttpClient();

        try {//from   w ww . j av a 2 s .co m

            HttpGet httpget = new HttpGet("http://www.upcdatabase.com/item/" + ean);
            httpget.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

            // Create a response handler

            ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
                public byte[] handleResponse(HttpResponse response)
                        throws ClientProtocolException, IOException {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        return EntityUtils.toByteArray(entity);
                    } else {
                        return null;
                    }
                }
            };

            String responseBody = new String(httpclient.execute(httpget, handler), "UTF-8");

            // return null if not found
            if (responseBody.contains("Item Not Found"))
                return null;
            else if (responseBody.contains("Item Record")) {

                // Parse response document
                Matcher matcher = Pattern.compile("<tr><td>Description<\\/td><td><\\/td><td>(.*)<\\/td><\\/tr>")
                        .matcher(responseBody);
                if (matcher.find()) {
                    res = matcher.group(1);
                }

            }

        } catch (UnsupportedEncodingException uee) {
            uee.printStackTrace();
        } catch (ClientProtocolException cpe) {
            cpe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            if (httpclient != null) {
                httpclient.getConnectionManager().shutdown();
            }
        }

    }
    return res;
}

From source file:example.DecrypterException.java

/**
 * Base64?/*from  w ww  .  j  a va2s. co  m*/
 * 
 * @param webString
 * @param encryptionKey
 *            KEY
 * @param integrityKey
 *            ??KEY
 * @return
 * @throws DecrypterException
 */
public static byte[] decryptSafeWebString(String webString, SecretKey encryptionKey, SecretKey integrityKey)
        throws DecrypterException {
    String unSafeString = unWebSafeAndPad(webString);
    byte[] ciphertext = {};
    try {
        ciphertext = Base64.decodeBase64(unSafeString.getBytes("utf-8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return decrypt(ciphertext, encryptionKey, integrityKey);
}

From source file:com.carltondennis.glassphysicalweb.MetadataResolver.java

public static String createUrlProxyGoLink(String url) {
    try {//from   w  w  w  .j a va 2 s .  c  om
        url = mContext.getString(R.string.proxy_go_link_base_url) + URLEncoder.encode(url, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return url;
}

From source file:eionet.gdem.conversion.ConversionService.java

private static final Vector<Object> convertResult(ConversionResultDto dto) {
    Vector<Object> result = new Vector<Object>();

    result.add(dto.getStatusCode());//from ww w  . j  a va  2 s . c o  m
    result.add(dto.getStatusDescription());

    if (dto.getConvertedXmls() != null) {
        for (Map.Entry<String, byte[]> entry : dto.getConvertedXmls().entrySet()) {
            result.add(entry.getKey());
            try {
                result.add(new String(entry.getValue(), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }

    return result;
}

From source file:com.lifetime.util.TimeOffUtil.java

public static HttpEntity getTimeoffRequestEntity(int page, int pagesize) {
    if ((page <= 0) || (pagesize <= 0)) {
        return null;
    }/*  ww w  .  ja v  a 2 s  . c o  m*/

    JSONObject jsonObject = new JSONObject();

    jsonObject.put("page", String.valueOf(page));
    jsonObject.put("pagesize", String.valueOf(pagesize));

    JSONArray columnUris = new JSONArray();

    columnUris.add("urn:replicon:time-off-list-column:time-off");
    columnUris.add("urn:replicon:time-off-list-column:time-off-type");
    columnUris.add("urn:replicon:time-off-list-column:department-of-time-off-owner");

    jsonObject.put("columnUris", columnUris);

    JSONArray sort = new JSONArray();

    JSONObject sortObject = new JSONObject();

    sortObject.put("columnUri", "urn:replicon:time-off-list-column:time-off");
    sortObject.put("isAscending", "false");

    sort.add(sortObject);

    JSONObject filter = new JSONObject();

    JSONObject leftExpression = new JSONObject();

    leftExpression.put("filterDefinitionUri", "urn:replicon:time-off-list-filter:time-off-type");

    filter.put("leftExpression", leftExpression);

    filter.put("operatorUri", "urn:replicon:filter-operator:equal");

    JSONObject value = new JSONObject();

    value.put("string", "us-pto");

    JSONObject rightExpression = new JSONObject();

    rightExpression.put("value", value);

    filter.put("rightExpression", rightExpression);

    jsonObject.put("filterExpression", filter);

    HttpEntity entity = null;

    String jsonString = jsonObject.toJSONString();

    try {
        entity = new StringEntity(jsonString);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return entity;
}