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.flozano.socialauth.util.HttpUtil.java

public static String encodeURIComponent(final String value) throws Exception {
    if (value == null) {
        return "";
    }/*ww w  .  ja v  a2  s. co  m*/

    try {
        return URLEncoder.encode(value, "utf-8")
                // 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 SocialAuthException(wow.getMessage(), wow);
    }
}

From source file:de.xwic.sandbox.base.model.StringUtil.java

/**
 * @param s//w ww .  j av a  2s.co  m
 * @return
 */
public static int getUtf8BytesLength(String s) {

    if (s == null) {
        return 0;
    }

    try {
        return s.getBytes("UTF-8").length;
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage(), e);
    }

    return -1;
}

From source file:com.amalto.workbench.utils.HttpClientUtil.java

public static String invokeModelService(String protocol, String host, String port, String contextPath,
        String username, String password, String modelName, String xsd, boolean isUpdate, Boolean force)
        throws XtentisException {
    try {//from   w  ww  . j av  a 2  s  .c om
        String url = protocol + host + ":" + port + contextPath + "/services/rest/system/models/" + modelName; //$NON-NLS-1$ //$NON-NLS-2$ 
        if (force != null) {
            url += "?force=" + force.toString(); //$NON-NLS-1$
        }
        HttpUriRequest request = null;
        request = createModelRequest(url, username, isUpdate, xsd);
        DefaultHttpClient httpClient = wrapAuthClient(url, username, password);
        String errMessage = Messages.Util_21 + "%s" + Messages.Util_22 + "%s"; //$NON-NLS-1$//$NON-NLS-2$
        String content = getTextContent(httpClient, request, null, errMessage);

        return content;
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage(), e);
    } catch (SecurityException e) {
        log.error(e.getMessage(), e);
    }
    return null;
}

From source file:com.amalto.workbench.utils.HttpClientUtil.java

public static String invokeMatchSimulation(String protocol, String host, int port, String contextPath,
        String userName, String password, String modelName, String entityName, String records)
        throws XtentisException {
    String url = protocol + host + ":" + port + contextPath + "/services/rest/tasks/matching/explain/?model=" //$NON-NLS-1$//$NON-NLS-2$
            + modelName + "&type=" //$NON-NLS-1$
            + entityName;/*from w w  w.  j a v  a2 s .  c o  m*/
    String contentType = "application/xml;charset=UTF-8"; //$NON-NLS-1$
    try {
        HttpPost request = new HttpPost(url);
        request.setHeader(HTTP.CONTENT_TYPE, contentType);
        addStudioToken(request, userName);

        StringEntity entity = new StringEntity(records, HTTP.UTF_8);
        request.setEntity(entity);

        DefaultHttpClient client = wrapAuthClient(url, userName, password);
        String errMessage = Messages.Util_21 + "%s" + Messages.Util_22 + "%s"; //$NON-NLS-1$//$NON-NLS-2$
        String content = getTextContent(client, request, null, errMessage);
        return content;
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage(), e);
    } catch (SecurityException e) {
        log.error(e.getMessage(), e);
    }

    return null;
}

From source file:com.silverpeas.gallery.ImageHelper.java

public static void setMetaData(final FileHandler fileHandler, final PhotoDetail photo, final String lang)
        throws ImageMetadataException, IOException {
    final String photoId = photo.getPhotoPK().getId();
    final String name = photo.getImageName();
    final String mimeType = photo.getImageMimeType();

    if ("image/jpeg".equals(mimeType) || "image/pjpeg".equals(mimeType)) {
        final HandledFile handledFile = fileHandler.getHandledFile(BASE_PATH, photo.getInstanceId(),
                settings.getString("imagesSubDirectory") + photoId, name);
        if (handledFile.exists()) {
            try {
                final ImageMetadataExtractor extractor = new DrewImageMetadataExtractor(photo.getInstanceId());
                for (final MetaData meta : extractor.extractImageExifMetaData(handledFile.getFile(), lang)) {
                    photo.addMetaData(meta);
                }/*  w  w w. j  av a  2  s. co m*/
                for (final MetaData meta : extractor.extractImageIptcMetaData(handledFile.getFile(), lang)) {
                    photo.addMetaData(meta);
                }
            } catch (UnsupportedEncodingException e) {
                SilverTrace.error("gallery", "ImageHelper.computeWatermarkText", "root.MSG_BAD_ENCODING",
                        "Bad metadata encoding in image " + photo.getTitle() + ": " + e.getMessage());
            }
        }
    }
}

From source file:com.core.util.wx.PayUtils.java

/**
 * post???xml?url//from  w  w w .  j  a  v  a 2 s.  com
 * 
 * @param xml
 * @param url
 * @return
 */
public static String postXmlCurl(String xml, String url) {
    HttpClient client = HttpClients.createSystem();
    HttpPost post = new HttpPost(url);
    String result = null;
    try {
        post.setEntity(new StringEntity(xml));
        HttpResponse httpResponse = client.execute(post);
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            HttpEntity httpEntity = httpResponse.getEntity();
            result = EntityUtils.toString(httpEntity);// ?
        }
    } catch (UnsupportedEncodingException e) {
        LOG.error(e.getMessage(), e);
    } catch (ClientProtocolException e) {
        LOG.error(e.getMessage(), e);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
    return result;
}

From source file:com.core.util.wx.PayUtils.java

/**
 * ?????/*w  w w .  j  a va  2 s . co  m*/
 */
public static String formatBizQueryParaMap(Map<String, String> paraMap, boolean urlencode) {
    StringBuilder sb = new StringBuilder();
    TreeMap<String, String> sortMap = new TreeMap<String, String>(paraMap);
    if (urlencode) {
        try {
            for (String key : sortMap.keySet()) {
                sb.append(key).append("=").append(URLEncoder.encode(sortMap.get(key), "UTF-8")).append("&");
            }
        } catch (UnsupportedEncodingException e) {
            LOG.error(e.getMessage(), e);
        }
    } else {
        for (String key : sortMap.keySet()) {
            sb.append(key).append("=").append(sortMap.get(key)).append("&");
        }
    }

    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * Parses the adresslist./*from   w  w w.  j  av a2s. c o  m*/
 * 
 * @param addresslist
 * @param charset
 * @return
 */
public static InternetAddress[] parseInternetAddress(String addresslist, String charset)
        throws MessagingException {

    if (addresslist != null) {
        addresslist = addresslist.replace(';', ',');
        InternetAddress[] addressArray = InternetAddress.parse(addresslist);

        if (addressArray != null) {
            for (InternetAddress address : addressArray) {
                String personal = address.getPersonal();
                if (personal != null) {
                    try {
                        address.setPersonal(personal, charset);
                    } catch (UnsupportedEncodingException e) {
                        log.error(e.getMessage(), e);
                    }
                }
            }
        }

        return addressArray;
    }

    return null;
}

From source file:com.silverpeas.gallery.ImageHelper.java

private static String computeWatermarkText(final String watermarkHD, final boolean watermark, final String type,
        final HandledFile image, final PhotoDetail photo, final int percentSize, final String watermarkOther)
        throws Exception {
    String nameAuthor = "";
    String nameForWatermark = "";
    if (ImageType.isIPTCCompliant(type) && watermark) {
        final ImageMetadataExtractor extractor = new DrewImageMetadataExtractor(photo.getInstanceId());
        final List<MetaData> iptcMetadata;
        try {/*from  ww  w . ja va  2 s .  co m*/
            iptcMetadata = extractor.extractImageIptcMetaData(image.getFile());
            final BufferedImage bufferedImage = ImageLoader.loadImage(image.getFile());
            if (StringUtil.isDefined(watermarkHD)) {
                // cration d'un duplicata de l'image originale avec intgration du
                // watermark
                final String value = getWatermarkValue(watermarkHD, iptcMetadata);
                if (value != null) {
                    nameAuthor = value;
                }
                if (!nameAuthor.isEmpty()) {
                    OutputStream watermarkStream = null;
                    try {
                        watermarkStream = image.getParentHandledFile()
                                .getHandledFile(photo.getId() + "_watermark.jpg").openOutputStream();
                        createWatermark(watermarkStream, nameAuthor, bufferedImage, percentSize);
                    } finally {
                        IOUtils.closeQuietly(watermarkStream);
                    }
                }
            }
            if (StringUtil.isDefined(watermarkOther)) {
                final String value = getWatermarkValue(watermarkOther, iptcMetadata);
                if (value != null) {
                    nameAuthor = value;
                }
                if (!nameAuthor.isEmpty()) {
                    nameForWatermark = nameAuthor;
                }
            }
        } catch (UnsupportedEncodingException e) {
            SilverTrace.error("gallery", "ImageHelper.computeWatermarkText", "root.MSG_BAD_ENCODING",
                    "Bad metadata encoding in image " + image.getFile().getPath() + ": " + e.getMessage());
        }
    }
    return nameForWatermark;
}

From source file:org.escidoc.browser.elabsmodul.service.ELabsService.java

private static boolean sendStartRequest(final List<String[]> propertyList) {
    LOG.info("Service> Send configuration to start...");

    boolean hasError = false;

    Preconditions.checkNotNull(propertyList, "Config list is null");
    final String configURLPart = "/configuration";

    for (final String[] configurationArray : propertyList) {
        String esyncEndpoint = configurationArray[0];
        LOG.debug("Service> sending start request for " + esyncEndpoint);
        while (esyncEndpoint.endsWith("/")) {
            esyncEndpoint = esyncEndpoint.substring(0, esyncEndpoint.length() - 1);
        }/*from   ww w.  j a va 2  s  .c  o m*/

        if (!esyncEndpoint.endsWith(configURLPart)) {
            esyncEndpoint = esyncEndpoint + configURLPart;
        }

        try {
            LOG.debug("Service> called HttpClient.");
            // FIXME set proxy
            final DefaultHttpClient httpClient = new DefaultHttpClient();
            httpClient.setKeepAliveStrategy(null);
            final HttpPut putMethod = new HttpPut(esyncEndpoint);
            putMethod.setEntity(new StringEntity(configurationArray[1], HTTP.UTF_8));
            final HttpResponse response = httpClient.execute(putMethod);
            final StatusLine statusLine = response.getStatusLine();
            if (isNotSuccessful(statusLine.getStatusCode())) {
                LOG.error("Service> wrong method call: " + statusLine.getReasonPhrase());
                hasError = true;
            } else {
                LOG.info("Service> configuration is successfully sent!");
            }
        } catch (final UnsupportedEncodingException e) {
            LOG.error("Service> UnsupportedEncodingException: " + e.getMessage());
            hasError = true;
            continue;
        } catch (final ClientProtocolException e) {
            LOG.error("Service> ClientProtocolException: " + e.getMessage());
            hasError = true;
            continue;
        } catch (final IOException e) {
            LOG.error("Service> IOException: " + e.getMessage());
            hasError = true;
            continue;
        }
    }
    return hasError;
}