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:org.addhen.smssync.controllers.MessageResultsController.java

/**
 * This method for handling GET ?task=result
 *
 * @param syncUrl url to web server//from  www  .  j  a  v  a  2  s. c o m
 * @return MessagesUUIDSResponse parsed server response whit information about request success
 * or failure and list of message uuids
 */
public MessagesUUIDSResponse sendMessageResultGETRequest(SyncUrl syncUrl) {
    MessagesUUIDSResponse response = null;
    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.GET);
        client.execute();
    } catch (JSONException e) {
        mUtil.log(mContext.getString(R.string.message_processed_json_failed));
        Util.logActivities(mContext,
                mContext.getString(R.string.message_processed_json_failed) + " " + e.getMessage());
    } catch (Exception e) {
        mUtil.log(mContext.getString(R.string.message_processed_failed));
        Util.logActivities(mContext,
                mContext.getString(R.string.message_processed_failed) + " " + e.getMessage());
    } finally {
        if (client != null) {
            if (HttpStatus.SC_OK == client.responseCode()) {
                response = parseMessagesUUIDSResponse(client);
                response.setSuccess(true);
            } else {
                response = new MessagesUUIDSResponse(client.responseCode());
                Util.logActivities(mContext, mContext.getString(R.string.messages_result_request_status,
                        client.responseCode(), client.getResponse()));
            }
        }
    }
    return response;
}

From source file:org.nextlets.erc.defaults.http.ERCHttpInvokerImpl.java

protected URI createUri(ERCConfiguration configuration, String methodEndpoint, HttpRequestBase req,
        String contentType, Map<String, String> params) {
    String suri;//from   ww  w. j  a  v a2s .c o m
    try {
        suri = ERCUtils.buildUrlAndParameters(configuration, methodEndpoint, req, contentType, params);
        log.debug("URI: {}", suri);
    } catch (UnsupportedEncodingException ex) {
        throw new ERCClientException(ex.getMessage(), ex);
    }
    URI uri = null;
    try {
        uri = new URI(suri);
        req.setURI(uri);
    } catch (URISyntaxException ex) {
        throw new ERCClientException("Could not make URI from: " + suri, ex);
    }
    return uri;
}

From source file:de.liedtke.data.url.BasicDAOUrl.java

protected JSONObject requestUrl(final String daoName, final String methodName, final String jsonValue)
        throws JSONException {
    String jsonString = null;//from  w w w  .  j  a v  a 2  s  .c  o  m
    try {
        // Construct data
        final StringBuilder params = new StringBuilder();
        params.append(URLEncoder.encode("daoName", Constants.UTF8));
        params.append("=");
        params.append(URLEncoder.encode(daoName, Constants.UTF8));
        params.append("&");
        params.append(URLEncoder.encode("methodName", Constants.UTF8));
        params.append("=");
        params.append(URLEncoder.encode(methodName, Constants.UTF8));
        if (jsonValue != null) {
            params.append("&");
            params.append(URLEncoder.encode("jsonValue", Constants.UTF8));
            params.append("=");
            params.append(URLEncoder.encode(jsonValue, Constants.UTF8));
        }
        params.append("&");
        params.append(URLEncoder.encode("kind", Constants.UTF8));
        params.append("=");
        params.append(URLEncoder.encode(ResultKind.JSON.toString(), Constants.UTF8));

        // Send data
        URL url = new URL(address);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(params.toString());
        wr.flush();

        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        final StringBuilder sBuilder = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            sBuilder.append(line);
        }
        jsonString = sBuilder.toString();
        wr.close();
        rd.close();
    } catch (UnsupportedEncodingException e) {
        logger.warning("UnsupportedEncodingException occured: " + e.getMessage());
    } catch (IOException e) {
        logger.warning("IOException occured: " + e.getMessage());
    }
    JSONObject json = null;
    if (jsonString == null) {
        json = null;
    } else {
        json = new JSONObject(jsonString);
    }
    return json;
}

From source file:com.alibaba.dragoon.common.protocol.transport.socket.SocketSessionImpl.java

public SocketSessionImpl(Socket socket, AtomicLong receivedBytes, AtomicLong receivedMessages,
        AtomicLong sentBytes, AtomicLong sentMessages) {
    super();/*from www .ja v a2s .  c  o  m*/
    this.socket = socket;
    state = State.Established;

    this.receivedBytes = receivedBytes;
    this.receivedMessages = receivedMessages;
    this.sentBytes = sentBytes;
    this.sentMessages = sentMessages;

    try {
        dataInput = new DataInputStream(socket.getInputStream());
        writer = new DataOutputStream(socket.getOutputStream());
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e.getMessage(), e);
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:cn.ctyun.amazonaws.http.HttpRequestFactory.java

/**
 * Utility function for creating a new StringEntity and wrapping any errors
 * as an AmazonClientException./*from w  ww  . ja v  a2s. 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 AmazonClientException("Unable to create HTTP entity: " + e.getMessage(), e);
    }
}

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

protected String getUrlMessage(final String keyPrefix, final String targetUrl) {
    try {// w ww.j  ava 2s.co  m
        if (isUrl()) {
            StringBuilder buff = concatEntries(keyPrefix, "=", "&");
            if (targetUrl == null) {
                logger.warn("targetUrl method return null!");
            } else {
                if (targetUrl.contains("?")) {
                    buff.insert(0, "&");
                } else {
                    buff.insert(0, "?");
                }
                buff.insert(0, targetUrl);
            }
            return buff.toString();
        } else {
            throw new CoidiException("it's not Url message type, call different method.");
        }
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage(), e);
        throw new CoidiException(e.getMessage(), e);
    }
}

From source file:com.thomsonreuters.proxy.authentication.NTLMEngineImpl.java

/**
 * Creates the NTLMv2 Hash of the user's password.
 * /*w  ww  .j  a  v  a  2s . c  o m*/
 * @param target The authentication target (i.e., domain).
 * @param user The username.
 * @param password The password.
 * 
 * @return The NTLMv2 Hash, used in the calculation of the NTLMv2 and LMv2 Responses.
 */
private static byte[] ntlmv2Hash(String target, String user, String password) throws NTLMEngineException {
    try {
        byte[] ntlmHash = ntlmHash(password);
        HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
        // Upper case username, mixed case target!!
        hmacMD5.update(user.toUpperCase().getBytes("UnicodeLittleUnmarked"));
        hmacMD5.update(target.getBytes("UnicodeLittleUnmarked"));
        return hmacMD5.getOutput();
    } catch (java.io.UnsupportedEncodingException e) {
        throw new NTLMEngineException("Unicode not supported! " + e.getMessage(), e);
    }
}

From source file:com.moviejukebox.plugin.trailer.YouTubeTrailersPlugin.java

private String buildUrl(String title) {
    StringBuilder stringUrl = new StringBuilder(TRAILER_SEARCH_URL);
    try {//  w ww.  j  ava2  s  .  c  o  m
        stringUrl.append(URLEncoder.encode(title, "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        LOG.warn("Failed to encode movie title: {} - {}", title, ex.getMessage());
        // Something went wrong with the encoding, try the default string
        stringUrl.append(title);
    }
    stringUrl.append("+trailer");

    if (hdWanted) {
        stringUrl.append(TRAILER_HD_FLAG);
    }

    stringUrl.append(TRAILER_SAFE_SEARCH);
    stringUrl.append(TRAILER_MAX_RESULTS).append(maxTrailers);
    stringUrl.append(TRAILER_VERSION);
    stringUrl.append(TRAILER_KEY).append(API_KEY);

    LOG.debug("Trailer Search URL: {}", stringUrl.toString());
    return stringUrl.toString();
}

From source file:pt.lunacloud.http.HttpRequestFactory.java

/**
 * Utility function for creating a new StringEntity and wrapping any errors
 * as an AmazonClientException./*  w  ww .ja va  2s. 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 LunacloudClientException("Unable to create HTTP entity: " + e.getMessage(), e);
    }
}

From source file:com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator.java

protected void processAuthentication(AuthingableConnection conn, AuthenticationPacket autheticationPacket,
        AuthResponseData rdata) {//w  w  w  .jav a2s . c  o  m
    MysqlClientConnection mysqlConn = (MysqlClientConnection) conn;

    if (logger.isInfoEnabled()) {
        logger.info("Accepting conn=" + conn);
    }
    String errorMessage = "";

    if ((autheticationPacket.clientParam & CLIENT_COMPRESS) != 0) {
        rdata.code = AuthResponseData.ERROR;
        rdata.message = " cannot use COMPRESSED PROTOCOL over amoeba!";
        return;
    }

    if ((autheticationPacket.clientParam & CLIENT_PROTOCOL_41) == 0) {
        rdata.code = AuthResponseData.ERROR;
        rdata.message = " must use new protocol version 4.1 over amoeba";
        return;
    }

    try {
        mysqlConn.setCharset(CharsetMapping.INDEX_TO_CHARSET[autheticationPacket.charsetNumber & 0xff]);
        boolean passwordchecked = false;
        if (logger.isDebugEnabled()) {
            logger.debug("client charset="
                    + CharsetMapping.INDEX_TO_CHARSET[autheticationPacket.charsetNumber & 0xff]);
            if (conn.getInetAddress() != null && map.get(conn.getInetAddress().getHostAddress()) == null) {
                map.put(conn.getInetAddress().getHostAddress(), Boolean.TRUE);
                long clientParam = autheticationPacket.clientParam;
                StringBuilder builder = new StringBuilder();
                builder.append("\n");
                builder.append("===========").append(conn.getInetAddress().getHostAddress())
                        .append("   Client Flag ==============\n");
                builder.append("CLIENT_LONG_PASSWORD:").append(((clientParam & CLIENT_LONG_PASSWORD) != 0))
                        .append("\n");
                builder.append("CLIENT_FOUND_ROWS:").append(((clientParam & CLIENT_FOUND_ROWS) != 0))
                        .append("\n");
                builder.append("CLIENT_LONG_FLAG:").append(((clientParam & CLIENT_LONG_FLAG) != 0))
                        .append("\n");
                builder.append("CLIENT_CONNECT_WITH_DB:").append(((clientParam & CLIENT_CONNECT_WITH_DB) != 0))
                        .append("\n");
                builder.append("CLIENT_NO_SCHEMA:").append(((clientParam & CLIENT_NO_SCHEMA) != 0))
                        .append("\n");
                builder.append("CLIENT_COMPRESS:").append(((clientParam & CLIENT_COMPRESS) != 0)).append("\n");
                builder.append("CLIENT_ODBC:").append(((clientParam & CLIENT_ODBC) != 0)).append("\n");
                builder.append("CLIENT_LOCAL_FILES:").append(((clientParam & CLIENT_LOCAL_FILES) != 0))
                        .append("\n");
                builder.append("CLIENT_IGNORE_SPACE:").append(((clientParam & CLIENT_IGNORE_SPACE) != 0))
                        .append("\n");
                builder.append("CLIENT_PROTOCOL_41:").append(((clientParam & CLIENT_PROTOCOL_41) != 0))
                        .append("\n");
                builder.append("CLIENT_INTERACTIVE:").append(((clientParam & CLIENT_INTERACTIVE) != 0))
                        .append("\n");
                builder.append("CLIENT_SSL:").append(((clientParam & CLIENT_SSL) != 0)).append("\n");
                builder.append("CLIENT_IGNORE_SIGPIPE:").append(((clientParam & CLIENT_IGNORE_SIGPIPE) != 0))
                        .append("\n");
                builder.append("CLIENT_TRANSACTIONS:").append(((clientParam & CLIENT_TRANSACTIONS) != 0))
                        .append("\n");
                builder.append("CLIENT_RESERVED:").append(((clientParam & CLIENT_RESERVED) != 0)).append("\n");
                builder.append("CLIENT_SECURE_CONNECTION:")
                        .append(((clientParam & CLIENT_SECURE_CONNECTION) != 0)).append("\n");
                builder.append("CLIENT_MULTI_STATEMENTS:")
                        .append(((clientParam & CLIENT_MULTI_STATEMENTS) != 0)).append("\n");
                builder.append("CLIENT_MULTI_RESULTS:").append(((clientParam & CLIENT_MULTI_RESULTS) != 0))
                        .append("\n");
                builder.append("===========================END Client Flag===============================\n");
                logger.debug(builder.toString());
            }
        }

        if (!StringUtil.isEmpty(getPassword())) {
            String encryptPassword = new String(Security.scramble411(getPassword(), mysqlConn.getSeed()),
                    AuthenticationPacket.CODE_PAGE_1252);

            passwordchecked = StringUtils.equals(
                    new String(autheticationPacket.encryptedPassword, AuthenticationPacket.CODE_PAGE_1252),
                    encryptPassword);
        } else {
            if (autheticationPacket.encryptedPassword == null
                    || autheticationPacket.encryptedPassword.length == 0) {
                passwordchecked = true;
            }
        }
        if (StringUtil.equals(getUser(), autheticationPacket.user) && passwordchecked) {
            rdata.code = AuthResponseData.SUCCESS;
            if (logger.isDebugEnabled()) {
                logger.debug(autheticationPacket.toString());
            }
        } else {
            rdata.code = AuthResponseData.ERROR;
            rdata.message = "Access denied for user '" + autheticationPacket.user + "'@'" + conn.getSocketId()
                    + "'" + (autheticationPacket.encryptedPassword != null ? "(using password: YES)" : "");
        }

        mysqlConn.setSchema(autheticationPacket.database);
    } catch (UnsupportedEncodingException e) {
        errorMessage = e.getMessage();
        rdata.code = AuthResponseData.ERROR;
        rdata.message = errorMessage;
        logger.error("UnsupportedEncodingException error", e);
    } catch (NoSuchAlgorithmException e) {
        errorMessage = e.getMessage();
        rdata.code = AuthResponseData.ERROR;
        rdata.message = errorMessage;
        logger.error("NoSuchAlgorithmException error", e);
    } catch (Exception e) {
        errorMessage = e.getMessage();
        logger.error("processAuthentication error", e);
        rdata.code = AuthResponseData.ERROR;
        rdata.message = errorMessage;
    }

}