Example usage for java.io UnsupportedEncodingException getMessage

List of usage examples for java.io UnsupportedEncodingException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.a2bsoft.buss.http.SendQuery.java

public static String sendQuery(String query) {

    try {/*from   w w w. j ava2 s.c om*/
        query = URLEncoder.encode(query, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return e.getMessage();
    }
    URL url = null;
    try {
        url = new URL(
                "http://www.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question="
                        + query);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    String result = null;
    HttpParams my_httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(my_httpParams, 30000);
    HttpConnectionParams.setSoTimeout(my_httpParams, 30000);
    HttpClient client = new DefaultHttpClient(my_httpParams);
    HttpGet get = new HttpGet(url.toString());
    HttpResponse resp;

    try {
        resp = client.execute(get);
        InputStream data = resp.getEntity().getContent();
        result = new BufferedReader(new InputStreamReader(data)).readLine();

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return sendQueryBusstuc(query);
        //         return e.getMessage();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return sendQueryBusstuc(query);
        //         return e.getMessage();
    }

    return result;
}

From source file:com.ksc.http.apache.utils.ApacheUtils.java

/**
 * Utility function for creating a new StringEntity and wrapping any errors
 * as an AmazonClientException./*from  w w  w.j  av  a 2 s.  c  o m*/
 *
 * @param s The string contents of the returned HTTP entity.
 * @return A new StringEntity with the specified contents.
 */
public static HttpEntity newStringEntity(String s) {
    try {
        return new StringEntity(s);
    } catch (UnsupportedEncodingException e) {
        throw new KscClientException("Unable to create HTTP entity: " + e.getMessage(), e);
    }
}

From source file:com.networknt.utility.Util.java

public static String urlEncode(String value) {
    if (value == null || value.length() == 0) {
        return "";
    }//from ww w  . j  a v a 2s  .  com
    try {
        return URLEncoder.encode(value, Constants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.networknt.utility.Util.java

public static String urlDecode(String value) {
    if (value == null || value.length() == 0) {
        return "";
    }/* w w w.j a v  a2 s. c om*/
    try {
        return URLDecoder.decode(value, Constants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:fr.itldev.koya.webscript.KoyaWebscript.java

/**
 * Extracts URL paramters./*  w  w w .j  a  v  a 2s . c  o  m*/
 *
 *
 * @param req
 * @return
 */
public static Map<String, String> getUrlParamsMap(WebScriptRequest req) {
    Map<String, String> params = new HashMap<>();
    params.putAll(req.getServiceMatch().getTemplateVars());
    for (String k : req.getParameterNames()) {
        String param;
        try {
            /**
             * Decode double encoded url parameter : ex string with accent
             * characters
             *
             * TODO charset permissive implementation
             */
            param = new String(req.getParameter(k).getBytes("iso-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            param = req.getParameter(k);
            LOGGER.error(ex.getMessage(), ex);

        }

        params.put(k, param);
    }
    return params;
}

From source file:com.spartasystems.holdmail.mime.MimeUtils.java

/**
 * Perform a {@link URLDecoder#decode(String, String)} but provide some null safety
 * @param value The value to decode//from  www  .  ja va  2 s  .  c o m
 * @param encoding The enconding
 * @return The decoded string, or the original string if either the value or encoding were invalid.
 */
public static String safeURLDecode(final String value, final String encoding) {

    if (StringUtils.isBlank(value)) {
        logger.warn("No value was provided for decoding");
        return value;
    }

    if (StringUtils.isBlank(encoding)) {
        logger.warn("No encoding name was provided for decoding, returning original value");
        return value;
    }

    try {
        return URLDecoder.decode(value, encoding);
    } catch (UnsupportedEncodingException e) {
        logger.error("Couldn't decode value with encoding '" + encoding + "': " + e.getMessage()
                + ", value was:" + value);
        return value;
    }
}

From source file:eu.sisob.uma.NPL.Researchers.Freebase.Utils.java

public static JsonArray getResultsFromAPISearchCall(String query, String key, String params) {
    String service_url = "https://www.googleapis.com/freebase/v1/search";
    String url = "";
    JsonObject json_data = null;//ww  w .j  ava  2s  .c o m
    try {
        url = service_url + "?query=" + URLEncoder.encode(query, "UTF-8") + params + "&key=" + key + "&limit=1";

        json_data = doRESTCall(url);
    } catch (UnsupportedEncodingException ex) {
        ProjectLogger.LOGGER.error(ex.getMessage());
        json_data = null;
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error(ex.getMessage());
        json_data = null;
    }

    JsonArray results = null;
    if (json_data != null) {
        results = (JsonArray) json_data.get("result");
    }

    return results;
}

From source file:com.liferay.util.Encryptor.java

public static String digest(String algorithm, String text) {
    MessageDigest mDigest = null;

    try {/*www  .  j  ava2  s.  c  om*/
        mDigest = MessageDigest.getInstance(algorithm);

        mDigest.update(text.getBytes(ENCODING));
    } catch (NoSuchAlgorithmException nsae) {
        Logger.error(Encryptor.class, nsae.getMessage(), nsae);

    } catch (UnsupportedEncodingException uee) {
        Logger.error(Encryptor.class, uee.getMessage(), uee);
    }

    byte raw[] = mDigest.digest();

    return Base64.encode(raw);
}

From source file:eu.sisob.uma.NPL.Researchers.Freebase.Utils.java

/**
* Get the results JsonArray of Freebase MQL Read API call
* 
* @param query/* www.j a  va2 s .c om*/
* @return
*/
public static JsonArray getResultsFromMQLReadCall(String query) {
    String service_url = "https://www.googleapis.com/freebase/v1/mqlread";
    String url;
    JsonObject json_data = null;
    try {
        url = service_url + "?query=" + URLEncoder.encode(query, "UTF-8")
                + "&key=AIzaSyBwYBI9bKtHDKRLfCjCx1p78-zsbGldD7Y";
        json_data = doRESTCall(url);
    } catch (UnsupportedEncodingException ex) {
        ProjectLogger.LOGGER.error(ex.getMessage());
        json_data = null;
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error(ex.getMessage());
        json_data = null;
    }

    JsonArray results = null;
    if (json_data != null) {
        results = (JsonArray) json_data.get("result");
    }

    return results;
}

From source file:org.akvo.flow.api.FlowApi.java

private static String getPhoneNumber(Context context) {
    try {/*  ww  w .  ja va 2  s  .  c o  m*/
        String phoneNumber = StatusUtil.getPhoneNumber(context);
        if (phoneNumber != null) {
            return URLEncoder.encode(phoneNumber, "UTF-8");
        }
        return "";
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.getMessage());
        return null;
    }
}