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:com.hybris.datahub.outbound.utils.CommonUtils.java

/**
 * @param filePath/*from   w  w  w  .  j  a  v  a  2  s  .c o m*/
 * @param suffix
 * @param content
 */
public static void writeFile(final String filePath, String suffix, final String content) {

    suffix = StringUtils.isEmpty(suffix) ? "json" : suffix;

    final File file = new File(filePath + "." + suffix);
    FileOutputStream out = null;
    try {
        if (!file.exists()) {
            file.createNewFile();
        } else {
            file.delete();
            file.createNewFile();
        }
        out = new FileOutputStream(file, true);
        out.write(content.getBytes("utf-8"));
    } catch (final UnsupportedEncodingException e) {
        LOGGER.error(e.getMessage());
    } catch (final FileNotFoundException e) {
        LOGGER.error(e.getMessage());
    } catch (final IOException e) {
        LOGGER.error(e.getMessage());
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final IOException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
}

From source file:com.liferay.portal.security.pwd.PwdEncryptor.java

private static byte[] _getSaltFromBCrypt(String bcryptString) throws PwdEncryptorException {

    byte[] saltBytes = null;

    try {//  w  ww  .j av  a 2  s  .c  om
        //if (Validator.isNull(bcryptString)) {
        if (StringUtils.isEmpty(bcryptString)) {
            String salt = null; // BCrypt.gensalt();

            //saltBytes = salt.getBytes(StringPool.UTF8);
            saltBytes = salt.getBytes("UTF8");
        } else {
            String salt = bcryptString.substring(0, 29);

            //saltBytes = salt.getBytes(StringPool.UTF8);
            saltBytes = salt.getBytes("UTF8");
        }
    } catch (UnsupportedEncodingException uee) {
        throw new PwdEncryptorException("Unable to extract salt from encrypted password: " + uee.getMessage());
    }

    return saltBytes;
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

/**
 * Performs a POST method against the API
 * @param url -> This URL is going to be converted to API_URL:BONFIRE_PORT/url
 * @param payload message sent in the post method
 * @return Response object encapsulation all the HTTP information, it returns <code>null</code> if there was an error.
 *//*w  w w  .  ja v a 2s. c o  m*/
public static Response executePutMethod(String url, String payload, String username, String password) {
    Response response = null;

    try {
        PutMethod put = new PutMethod(url);

        // We define the request entity
        RequestEntity requestEntity = new StringRequestEntity(payload, BONFIRE_XML, null);
        put.setRequestEntity(requestEntity);

        response = executeMethod(put, BONFIRE_XML, username, password, url);

    } catch (UnsupportedEncodingException exception) {
        System.out.println("THE PAYLOAD ENCODING IS NOT SUPPORTED");
        System.out.println("ERROR: " + exception.getMessage());
        System.out.println("ERROR: " + exception.getStackTrace());
    }

    return response;
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

/**
 * Performs a POST method against the API
 * @param url -> This URL is going to be converted to API_URL:BONFIRE_PORT/url
 * @param payload message sent in the post method
 * @param type specifies the content type of the request
 * @return Response object encapsulation all the HTTP information, it returns <code>null</code> if there was an error.
 *///  w  w w  . ja  v  a 2  s. c o  m
public static Response executePostMethod(String url, String username, String password, String payload,
        String type) {
    Response response = null;

    try {
        PostMethod post = new PostMethod(url);

        // We define the request entity
        RequestEntity requestEntity = new StringRequestEntity(payload, type, null);
        post.setRequestEntity(requestEntity);

        response = executeMethod(post, BONFIRE_XML, username, password, url);

    } catch (UnsupportedEncodingException exception) {
        System.out.println("THE PAYLOAD ENCODING IS NOT SUPPORTED");
        System.out.println("ERROR: " + exception.getMessage());
        System.out.println("ERROR: " + exception.getStackTrace());
    }

    return response;
}

From source file:CertStreamCallback.java

private static void invokeActions(String url, String params, byte[] data, Part[] parts, String accept,
        String contentType, String sessionID, String language, String method, Callback callback) {

    if (params != null && !"".equals(params)) {
        if (url.contains("?")) {
            url = url + "&" + params;
        } else {//from  w w w  .  ja  va  2  s. co m
            url = url + "?" + params;
        }
    }

    if (language != null && !"".equals(language)) {
        if (url.contains("?")) {
            url = url + "&language=" + language;
        } else {
            url = url + "?language=" + language;
        }
    }

    HttpMethod httpMethod = null;

    try {
        HttpClient httpClient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
        httpMethod = getHttpMethod(url, method);
        if ((httpMethod instanceof PostMethod) || (httpMethod instanceof PutMethod)) {
            if (null != data)
                ((EntityEnclosingMethod) httpMethod).setRequestEntity(new ByteArrayRequestEntity(data));
            if (httpMethod instanceof PostMethod && null != parts)
                ((PostMethod) httpMethod)
                        .setRequestEntity(new MultipartRequestEntity(parts, httpMethod.getParams()));
        }

        if (sessionID != null) {
            httpMethod.addRequestHeader("Cookie", "JSESSIONID=" + sessionID);
        }

        if (!(httpMethod instanceof PostMethod && null != parts)) {
            if (null != accept && !"".equals(accept))
                httpMethod.addRequestHeader("Accept", accept);
            if (null != contentType && !"".equals(contentType))
                httpMethod.addRequestHeader("Content-Type", contentType);
        }

        int statusCode = httpClient.executeMethod(httpMethod);
        if (statusCode != HttpStatus.SC_OK) {
            throw ActionException.create(ClientMessages.CON_ERROR1, httpMethod.getStatusLine());
        }

        contentType = null != httpMethod.getResponseHeader("Content-Type")
                ? httpMethod.getResponseHeader("Content-Type").getValue()
                : accept;

        InputStream o = httpMethod.getResponseBodyAsStream();
        if (callback != null) {
            callback.execute(o, contentType, sessionID);
        }

    } catch (Exception e) {
        String result = BizClientUtils.doError(e, contentType);
        ByteArrayInputStream in = null;
        try {
            in = new ByteArrayInputStream(result.getBytes("UTF-8"));
            if (callback != null) {
                callback.execute(in, contentType, null);
            }

        } catch (UnsupportedEncodingException e1) {
            throw new RuntimeException(e1.getMessage() + "", e1);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e1) {
                }
            }
        }
    } finally {
        // 
        if (httpMethod != null) {
            httpMethod.releaseConnection();
        }
    }
}

From source file:annis.libgui.Helper.java

public static List<String> citationFragment(String aql, Set<String> corpora, int contextLeft, int contextRight,
        String segmentation, int start, int limit) {
    List<String> result = new ArrayList<String>();
    try {//from  w  w  w .j  a  va  2  s .  com
        result.add("_q=" + encodeBase64URL(aql));
        result.add("_c=" + encodeBase64URL(StringUtils.join(corpora, ",")));
        result.add("cl=" + URLEncoder.encode("" + contextLeft, "UTF-8"));
        result.add("cr=" + URLEncoder.encode("" + contextRight, "UTF-8"));
        result.add("s=" + URLEncoder.encode("" + start, "UTF-8"));
        result.add("l=" + URLEncoder.encode("" + limit, "UTF-8"));
        if (segmentation != null) {
            result.add("_seg=" + encodeBase64URL(segmentation));
        }
    } catch (UnsupportedEncodingException ex) {
        log.warn(ex.getMessage(), ex);
    }

    return result;
}

From source file:com.liferay.portal.security.pwd.PwdEncryptor.java

private static byte[] _getSaltFromCrypt(String cryptString) throws PwdEncryptorException {

    byte[] saltBytes = null;

    try {//from ww w.  java  2 s.c o  m
        //if (Validator.isNull(cryptString)) {
        if (StringUtils.isEmpty(cryptString)) {

            // Generate random salt

            Random random = new Random();

            int numSaltChars = saltChars.length;

            StringBuilder sb = new StringBuilder();

            int x = random.nextInt(Integer.MAX_VALUE) % numSaltChars;
            int y = random.nextInt(Integer.MAX_VALUE) % numSaltChars;

            sb.append(saltChars[x]);
            sb.append(saltChars[y]);

            String salt = sb.toString();

            //saltBytes = salt.getBytes(Digester.ENCODING);
            saltBytes = salt.getBytes("UTF8");
        } else {

            // Extract salt from encrypted password

            String salt = cryptString.substring(0, 2);

            //saltBytes = salt.getBytes(Digester.ENCODING);
            saltBytes = salt.getBytes("UTF8");
        }
    } catch (UnsupportedEncodingException uee) {
        throw new PwdEncryptorException("Unable to extract salt from encrypted password: " + uee.getMessage());
    }

    return saltBytes;
}

From source file:com.gallatinsystems.common.util.S3Util.java

public static String getBrowserLink(String bucketName, String objectKey, String awsAccessId,
        String awsSecretKey) {/*  w  w w  .ja  v a 2 s .  c  o m*/

    final String payload = String.format(BROWSER_GET_PAYLOAD, bucketName, objectKey);
    final String signature = MD5Util.generateHMAC(payload, awsSecretKey);

    final StringBuffer sb = new StringBuffer(String.format(S3_URL, bucketName, objectKey));
    sb.append("?AWSAccessKeyId=").append(awsAccessId);
    sb.append("&Expires=").append(EXPIRE_DATE);

    try {
        sb.append("&Signature=").append(URLEncoder.encode(signature, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        log.log(Level.SEVERE, "Error generating signature for browser URL: " + e.getMessage());
    }

    return sb.toString();
}

From source file:com.jaspersoft.jasperserver.core.util.StringUtil.java

private static String getDecodedValue(String value, String encoding, String errorMessage) {
    try {//from   w  w w.j  a  v  a 2  s . c  o m
        value = URLDecoder.decode(value, encoding);
    } catch (UnsupportedEncodingException e) {
        logger.warn((errorMessage != null && errorMessage.trim().length() > 0 ? errorMessage + ": " : "")
                + e.getMessage());
    } catch (IllegalArgumentException iae) {
        logger.warn(
                "Decoded value contained illegal characters (eg. %).  Decoding was aborted and original value was used. Encoding: "
                        + encoding + ", Original Input: " + value.replaceAll("\n", ""));
    } catch (Exception e) {
        logger.error(errorMessage, e);
    }

    return value;
}

From source file:com.flame.core.pay.union.common.SDKUtil.java

/**
 * ???(SHA-1?)<br>/*from   w w  w  .  j a v a  2 s .  c o m*/
 * @param rspData ?<br>
 * @param encoding ?encoding<br>
 * @return true  false <br>
 */
public static boolean validate(Map<String, String> rspData, String encoding) {
    LogUtil.writeLog("?");
    if (SDKUtil.isEmpty(encoding)) {
        encoding = "UTF-8";
    }
    String stringSign = rspData.get(SDKConstants.param_signature);

    // ?certId ????Map?
    String certId = rspData.get(SDKConstants.param_certId);

    LogUtil.writeLog("??[" + certId + "]");

    // Map???key1=value1&key2=value2?
    String stringData = SDKUtil.coverMap2String(rspData);

    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;
}