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.surevine.alfresco.connector.AlfrescoHttpConnector.java

/**
 * Adds the get paramters to a string url
 *//* w w w .  j ava 2s .co m*/
private String addUrlParameters(final String url, final Map<String, String> parameters) {
    if (parameters == null) {
        return url;
    }

    boolean questionMark = !url.contains("?");

    final StringBuilder output = new StringBuilder(url);

    for (final Entry<String, String> entry : parameters.entrySet()) {
        if (questionMark) {
            output.append("?");
            questionMark = false;
        } else {
            output.append("&");
        }

        try {
            output.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
            output.append("=");
            output.append(entry.getValue());
        } catch (final UnsupportedEncodingException eUE) {
            LOG.error(eUE.getMessage(), eUE);
        }
    }

    return output.toString();
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.java

@Override
public Map<String, String> verify(Map<String, String> postData) {
    String username = postData.get("username");
    if (username == null)
        throw new NoSuchElementException();
    if (username.equals("error"))
        throw new RuntimeException();
    User userAttributes;/*from  ww w  . ja  v a2s.co m*/
    userAttributes = getUsersByName().get(username);
    if (userAttributes == null)
        throw new NoSuchElementException();
    String pw = null;
    String postDataPassword = postData.get("password");
    if (isHashedPassword(userAttributes.getPassword())) {
        String userHash = userAttributes.getPassword();
        if (userHash == null)
            throw new NoSuchElementException();
        String[] userHashSplit = userHash.split(Pattern.quote("$"));
        String algo = userHashSplit[1];
        String salt = userHashSplit[2];
        try {
            pw = createPasswdCompatibleHash(algo, postDataPassword, salt);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage());
        }
    } else
        pw = postDataPassword;
    String pw2;
    pw2 = userAttributes.getPassword();
    if (pw2 == null || !pw2.equals(pw))
        throw new NoSuchElementException();
    return userAttributes.getAttributes();
}

From source file:com.jana.android.net.HttpPostConnection.java

private void updateParamsFromJson(HttpPost httpPost) {
    try {//from w ww.  ja  va2s.c om

        StringEntity entity = new StringEntity(paramsFromJson, HTTP.UTF_8);
        //         entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
        //               "application/json"));
        httpPost.setEntity(entity);

    } catch (UnsupportedEncodingException e) {

        Logger.w("Failure while establishing url connection as unsupported encoding error > " + e.getMessage());

        e.printStackTrace();
    }
}

From source file:org.addhen.smssync.controllers.MessageResultsController.java

/**
 * This method is handling POST ?task=result message_result
 *
 * @param syncUrl url to web server//  ww w.  ja  v  a  2 s.  c  o m
 * @param results list of message result data
 */
public void sendMessageResultPOSTRequest(SyncUrl syncUrl, List<MessageResult> results) {
    String newEndPointURL = syncUrl.getUrl().concat(TASK_RESULT_URL_PARAM);

    final String urlSecret = syncUrl.getSecret();

    if (!TextUtils.isEmpty(urlSecret)) {
        String urlSecretEncoded = urlSecret;
        newEndPointURL = newEndPointURL.concat("&secret=");
        try {
            urlSecretEncoded = URLEncoder.encode(urlSecret, "UTF-8");
        } catch (java.io.UnsupportedEncodingException e) {
            mUtil.log(e.getMessage());
        }
        newEndPointURL = newEndPointURL.concat(urlSecretEncoded);
    }

    MainHttpClient client = new MainHttpClient(newEndPointURL, mContext);
    try {

        client.setMethod(HttpMethod.POST);
        client.setStringEntity(createMessageResultJSON(results));
        client.setHeader("Accept", "application/json");
        client.setHeader("Content-type", "application/json");
        client.execute();
    } catch (Exception e) {
        mUtil.log(mContext.getString(R.string.message_processed_failed));
    } finally {
        if (client != null) {
            if (HttpStatus.SC_OK == client.responseCode()) {
                mUtil.log(mContext.getString(R.string.message_processed_success));
            }
        }
    }
}

From source file:com.coroptis.coidi.core.message.AbstractMessage.java

protected String getPrefixedMessage(final String keyPrefix) {
    try {//  w  w w.  j a  va  2  s  .  co m
        return concatEntries(keyPrefix, ":", "\n").toString();
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage(), e);
        throw new CoidiException(e.getMessage(), e);
    }
}

From source file:io.cloudslang.content.httpclient.consume.HttpResponseConsumer.java

private void consumeToDestinationFile() throws IOException {
    BufferedReader reader;/*  w  ww  .  j a  va 2 s .  c  o  m*/
    BufferedWriter fileWriter = null;
    FileOutputStream fos = null;
    try {
        try {
            reader = new BufferedReader(
                    new InputStreamReader(httpResponse.getEntity().getContent(), responseCharacterSet));
            fos = new FileOutputStream(new File(destinationFile));
            fileWriter = new BufferedWriter(new OutputStreamWriter(fos, responseCharacterSet));
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException(
                    "Could not parse '" + HttpClientInputs.RESPONSE_CHARACTER_SET + "'. " + e.getMessage(), e);
        }
        char[] buffer = new char[1024];
        int b;
        while ((b = reader.read(buffer, 0, buffer.length)) != -1) {
            fileWriter.write(buffer, 0, b);
        }
        fileWriter.flush();
    } finally {
        if (fos != null) {
            safeClose(fos);
        }
        if (fileWriter != null) {
            safeClose(fileWriter);
        }
    }
}

From source file:iristk.cfg.ABNFGrammar.java

@Override
public String toString() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshal(baos);/* w  ww.ja va 2s  .co m*/
    try {
        return new String(baos.toByteArray(), "utf-8");
    } catch (UnsupportedEncodingException e) {
        return e.getMessage();
    }
}

From source file:com.sinacloud.scs.http.HttpRequestFactory.java

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

From source file:org.dcache.spi.dCacheStorageBackend.java

@Override
public void updateCdmiObject(String path, String targetCapabilityUri) throws BackEndException {
    LOG.debug("QoS Update of {} to target capability {}", path, targetCapabilityUri);
    String url = DCACHE_SERVER + apiPrefix + (isRestApiNew ? qosPrefixNew : "qos-management/" + "namespace")
            + path;//from  w ww . j  a v a 2 s  . com
    try {
        HttpPost post = new HttpPost(url);
        post.setEntity(new StringEntity(isRestApiNew ? JsonUtils.targetCapUriToJsonNew(targetCapabilityUri)
                : JsonUtils.targetCapUriToJsonOld(targetCapabilityUri)));
        List<Header> headers = new ArrayList<>();
        headers.add(new BasicHeader("Content-Type", "application/json"));
        headers.add(new BasicHeader("Accept", "application/json"));
        JSONObject response = HttpUtils.execute(post, headers);
        LOG.info("QoS Update of {} to {}: {}", path, targetCapabilityUri,
                response.getString(isRestApiNew ? "status" : "message"));
    } catch (SpiException se) {
        LOG.error("Error Updating Capability of {} to {}: {}", path, targetCapabilityUri, se.getMessage());
        throw new BackEndException(se.getMessage(), se.getCause());
    } catch (UnsupportedEncodingException ue) {
        LOG.error("Error creating request to update capability of {} to {}: {}", path, targetCapabilityUri,
                ue.getMessage());
        throw new BackEndException(ue.getMessage(), ue.getCause());
    }
}

From source file:edu.hawaii.soest.kilonalu.ctd.CTDFrame.java

/** 
 * Get the CTD sample field as a String/*w  ww.j a va2 s.  com*/
 * @return sample - the sample as a String
 */
public String getSample() {

    this.sample.flip();
    String sampleString;

    try {
        sampleString = new String(this.sample.array(), "US-ASCII");
        // strip leading command and trailing null characters
        int spaceIndex = sampleString.indexOf(" ");
        int nullIndex = sampleString.indexOf(0);

        if (spaceIndex > 0) {
            // has leading and trailing
            return sampleString.substring(spaceIndex, nullIndex);

        } else if (spaceIndex == 0) {
            // has trailing
            return sampleString.substring(0, nullIndex);

        } else {
            return sampleString;

        }

    } catch (UnsupportedEncodingException uee) {
        logger.debug("The string encoding was not recognized: " + uee.getMessage());
        return null;
    }

}