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:xtuaok.sharegyazo.HttpMultipartPostRequest.java

private String convertToString(InputStream stream) {
    InputStreamReader streamReader = null;
    BufferedReader bufferReader = null;
    try {/*from   w w w  .  jav a  2  s. c om*/
        streamReader = new InputStreamReader(stream, "UTF-8");
        bufferReader = new BufferedReader(streamReader);
        StringBuilder builder = new StringBuilder();
        for (String line = null; (line = bufferReader.readLine()) != null;) {
            builder.append(line).append("\n");
        }
        return builder.toString();
    } catch (UnsupportedEncodingException e) {
        Log.e(LOG_TAG, e.getMessage());
    } catch (IOException e) {
        Log.e(LOG_TAG, e.toString());
    } finally {
        try {
            stream.close();
            if (bufferReader != null) {
                bufferReader.close();
            }
        } catch (IOException e) {
            // IOError
            Log.e(LOG_TAG, e.toString());
        }
    }
    return null;
}

From source file:cn.isif.util_plus.http.client.entity.BodyParamsEntity.java

private void refreshContent() {
    if (dirty) {/*from ww w  . j  a v a2s .  co m*/
        try {
            this.content = URLEncodedUtils.format(params, charset).getBytes(charset);
        } catch (UnsupportedEncodingException e) {
            LogUtils.e(e.getMessage(), e);
        }
        dirty = false;
    }
}

From source file:net.noday.cat.listener.ArticleSaveNotifier.java

@Override
public void onApplicationEvent(ArticleSaveEvent e) {
    //https://github.com/b3log/b3log-symphony/blob/master/src/main/java/org/b3log/symphony/processor/ArticleProcessor.java
    //https://github.com/b3log/b3log-solo/blob/master/core/src/main/java/org/b3log/solo/event/rhythm/ArticleSender.java
    System.out.println(e.getArticle().getTitle());
    try {//from   w  w  w.  ja v a  2  s  .com
        Article a = e.getArticle();
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(ADD_ARTICLE_URL);
        post.setEntity(new StringEntity(toPostString(a), "UTF-8"));
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = client.execute(post, responseHandler);
        log.info(responseBody);
    } catch (UnsupportedEncodingException ex) {
        log.error(ex.getMessage(), ex);
    } catch (ClientProtocolException ex) {
        log.error(ex.getMessage(), ex);
    } catch (IOException ex) {
        log.error(ex.getMessage(), ex);
    }
}

From source file:cn.vlabs.duckling.api.umt.sso.configable.servlet.LogoutServlet.java

private String buildLogoutURL(String defaultRetoLocalAppUrl, String sid) {
    String url;/*from  w ww  .ja va  2 s.c o  m*/
    try {
        url = SSOProperties.getInstance().getProperty(ILoginHandle.UMT_LOGOUT_URL_KEY) + "?appname="
                + URLEncoder.encode(SSOProperties.getInstance().getProperty(ILoginHandle.UMT_AUTH_APPNAME_KEY),
                        DEFAULT_CHARSET)
                + "&sid=" + sid + "&WebServerURL=" + URLEncoder.encode(defaultRetoLocalAppUrl, DEFAULT_CHARSET);
        return url;
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}

From source file:fi.laverca.Pkcs1.java

/**
 * Get the MSS Signature value//  www . j a  v  a  2s .  c  o m
 * @return MSS Signature as a String
 */
public String getMssSignatureValue() {
    String signature = null;
    try {
        signature = new String(Base64.encode(pkcs1.getSignatureValue()), "ASCII");
    } catch (UnsupportedEncodingException e) {
        log.error("Unable to decode signature: " + e.getMessage());
    }
    return signature;
}

From source file:biz.netcentric.bitbucket.plugins.jenkins.JenkinsBuildTrigger.java

/**
 * Notifies Jenkins of a new commit assuming Jenkins is configured to connect to Stash via SSH.
 *//*  w w  w.java 2s .com*/
public void postReceive(final RepositoryHookContext context, final Collection<RefChange> refChanges) {
    String url = context.getSettings().getString(PROPERTY_URL);
    if (StringUtils.isBlank(url)) {
        url = (String) transactionTemplate.execute(new TransactionCallback() {
            public Object doInTransaction() {
                return pluginSettingsFactory.createGlobalSettings().get(ConfigResource.PLUGIN_KEY_URL);
            }
        });
    }

    try {
        final RepositoryCloneLinksRequest linksRequest = new RepositoryCloneLinksRequest.Builder()
                .protocol("ssh").repository(context.getRepository()).build();
        final Set<NamedLink> links = repositoryService.getCloneLinks(linksRequest);
        if (links.isEmpty()) {
            LOG.error("Unable to calculate clone link for repository [{}]", context.getRepository());
        } else {
            url = String.format("%s/git/notifyCommit?url=%s", url,
                    URLEncoder.encode(links.iterator().next().getHref(), "UTF-8"));
        }
    } catch (UnsupportedEncodingException e) {
        LOG.error(e.getMessage(), e);
    }

    LOG.debug("Notifying Jenkins via URL: [{}]", url);

    if (url != null) {
        try {
            new URL(url).openConnection().getInputStream().close();
        } catch (Exception e) {
            LOG.error("Unable to connect to Jenkins at [" + url + "]", e);
        }
    }
}

From source file:net.duckling.ddl.service.export.impl.ExportAttachSaver.java

/**
 * @param group/*  w  w  w. j av a2 s. c  o m*/
 * @return string coded by utf8
 */
private String code2Utf8(String group) {
    byte bss[] = new byte[group.length() / 3];
    byte bs[];
    String ss = "";
    try {
        bs = group.getBytes("utf8");
        int j = 0;
        byte b1 = 0, b2 = 0;
        for (int i = 1; i < bs.length; i += 2) {
            b1 = b2 = 0;
            if (bs[i] < 60) {
                b1 = (byte) (bs[i] - 48);
            } else {
                b1 = (byte) (bs[i] - 55);
            }
            i++;
            if (bs[i] < 60) {
                b2 = (byte) (bs[i] - 48);
            } else {
                b2 = (byte) (bs[i] - 55);
            }
            bss[j++] = (byte) (b1 << 4 | (b2 & 0x0f));
        }
        ss = new String(bss, "utf8");
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getMessage() + ";group=" + group, e);
    }
    return ss;
}

From source file:edu.jhu.pha.vospace.node.VospaceId.java

public VospaceId(String idStr) throws URISyntaxException {
    URI voURI = new URI(idStr);

    if (!validId(voURI)) {
        throw new URISyntaxException(idStr, "InvalidURI");
    }//from   w  w  w .j  a v a 2 s  .  c o m

    if (!StringUtils.contains(idStr, "vospace")) {
        throw new URISyntaxException(idStr, "InvalidURI");
    }

    this.uri = StringUtils.substringBetween(idStr, "vos://", "!vospace");

    if (this.uri == null)
        throw new URISyntaxException(idStr, "InvalidURI");

    try {
        String pathStr = URLDecoder.decode(StringUtils.substringAfter(idStr, "!vospace"), "UTF-8");
        this.nodePath = new NodePath(pathStr);
    } catch (UnsupportedEncodingException e) {
        // should not happen
        logger.error(e.getMessage());
    }

}

From source file:ru.elifantiev.yandex.oauth.AsyncContinuationHandler.java

@Override
protected AuthResult doInBackground(Uri... params) {

    String code, error;//w w w.j a v  a2s  .  c o m

    if (params.length == 3) {
        // TODO: Add redir URL checking
        if ((code = params[2].getQueryParameter("code")) == null) {
            if ((error = params[2].getQueryParameter("error")) == null) {
                return new AuthResult("Unknown error");
            } else {
                return new AuthResult(error);
            }
        }
    } else
        return new AuthResult("Wrong parameters count");

    HttpClient client = SSLHttpClientFactory.getNewHttpClient();
    HttpPost method = new HttpPost(params[0].buildUpon().path("/oauth/token").build().toString());

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
    nameValuePairs.add(new BasicNameValuePair("code", code));
    nameValuePairs.add(new BasicNameValuePair("client_id", clientId));
    nameValuePairs.add(new BasicNameValuePair("grant_type", "authorization_code"));
    nameValuePairs.add(new BasicNameValuePair("redirect_uri", params[1].toString()));
    try {
        method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        return new AuthResult(e.getMessage());
    }

    String token = null;
    try {
        HttpResponse httpResponse = client.execute(method);
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode == 200 || statusCode == 400) {
            JSONObject response = (JSONObject) (new JSONTokener(EntityUtils.toString(httpResponse.getEntity()))
                    .nextValue());
            if (response.has("access_token"))
                token = response.getString("access_token");
            else if (response.has("error"))
                return new AuthResult(response.getString("error"));
        } else
            return new AuthResult("Call failed. Returned HTTP response code " + String.valueOf(statusCode));
    } catch (IOException e) {
        return new AuthResult(e.getMessage());
    } catch (JSONException e) {
        return new AuthResult(e.getMessage());
    }

    return new AuthResult(new AccessToken(token));
}

From source file:com.restfiddle.handler.http.builder.RfRequestBuilder.java

private void setRequestEntity(RfRequestDTO requestDTO, RequestBuilder requestBuilder) {
    List<FormDataDTO> formParams = requestDTO.getFormParams();
    if (requestDTO.getApiBody() != null && !requestDTO.getApiBody().isEmpty()) {
        try {/*  ww  w  .j  a  v a 2 s .c o m*/
            requestBuilder.setEntity(new StringEntity(requestDTO.getApiBody()));

        } catch (UnsupportedEncodingException e) {
            logger.error(e.getMessage(), e);
        }
    } else if (formParams != null && !formParams.isEmpty()) {
        // NOTE : http://stackoverflow.com/questions/12745710/apache-httpclient-4-2-1-post-request-to-fill-form-after-successful-login
        requestBuilder.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        List<NameValuePair> nvps2 = new ArrayList<NameValuePair>();
        for (FormDataDTO formDataDTO : formParams) {
            nvps2.add(new BasicNameValuePair(formDataDTO.getKey(), formDataDTO.getValue()));
        }
        try {
            requestBuilder.setEntity(new UrlEncodedFormEntity(nvps2));
        } catch (UnsupportedEncodingException e) {
        }
    }
}