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.streamreduce.core.service.EmailServiceImpl.java

@Override
public void sendInviteUserActivationEmail(User user) {
    try {/*ww  w  .  ja  va 2s  . c om*/
        String id = URLEncoder.encode(user.getAccount().getId().toString(), DEFAULT_ENCODING);
        String key = URLEncoder.encode(user.getSecretKey(), DEFAULT_ENCODING);
        String secretyKey = key + "/" + id;

        String from = (String) emailProperties.get("email.from");
        String urlPrefix = (String) emailProperties.get("email.urlprefix");
        String subject = (String) emailProperties.get("email.inviteUser.subject");

        VelocityContext context = new VelocityContext();
        context.put("urlPrefix", urlPrefix);
        context.put("secretKey", secretyKey);

        logger.debug("[SES EMAIL] send invited user activation email for " + user.getUsername());

        sendEmail(user.getUsername(), from, subject, "invite_user_activation_email", context);

    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage());
    }
}

From source file:com.criticalsoftware.mobics.presentation.extension.DefaultExceptionHandler.java

/**
 * If there's an ActionBean present, send the user back where they came from with a stern warning, otherwise send
 * them to the global error page./*from w  w  w .j  a v a 2  s.c  o  m*/
 * 
 * @param UnsupportedEncodingException A generic exception
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @return A ForwardResolution
 */
public Resolution handle(UnsupportedEncodingException exception, HttpServletRequest request,
        HttpServletResponse response) {
    LOGGER.error(exception.getMessage(), exception);
    return insideJobToError("error.UnsupportedEncodingException", request, response);
}

From source file:com.streamreduce.core.service.EmailServiceImpl.java

@Override
public void sendPasswordResetEmail(User user, boolean mobile) {
    try {/*ww w . j a  v  a  2s .c  o m*/
        String userId = URLEncoder.encode(user.getId().toString(), DEFAULT_ENCODING);
        String key = URLEncoder.encode(user.getSecretKey(), DEFAULT_ENCODING);
        String secretKey = key + "/" + userId;

        String from = (String) emailProperties.get("email.from");
        String urlPrefix = mobile ? (String) emailProperties.get("email.mobile.urlprefix")
                : (String) emailProperties.get("email.urlprefix");
        String subject = (String) emailProperties.get("email.resetPassword.subject");

        VelocityContext context = new VelocityContext();
        context.put("urlPrefix", urlPrefix);
        context.put("secretKey", secretKey);

        logger.debug("[SES EMAIL] sending password reset email for " + user.getUsername());

        // send the email
        sendEmail(user.getUsername(), from, subject, "password_reset_email", context);

    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage());
    }
}

From source file:io.moj.mobile.android.sdk.networking.MojioRequest.java

@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {//from   w  w  w . j  a  v  a  2  s .  c o  m
        // Check result
        if (response.statusCode != HttpStatus.SC_OK) { // TODO is this the correct enum?
            // TODO Error.
        }

        T result = null;

        String responseString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        Log.i("MOJIO", "Response for " + mUrl);
        Log.i("MOJIO", responseString);

        if (responseString.isEmpty()) {
            // Body was empty, no need to parse.
            return Response.success(result, HttpHeaderParser.parseCacheHeaders(response));
        }

        // Else attempt to parse into the expected class.

        /*
        if ((this.mMethod == Method.PUT)
            || (this.mMethod == Method.DELETE)
            || (this.mMethod == Method.POST)) {
        // Response body will be empty, no need to parse.
        return Response.success(result, HttpHeaderParser.parseCacheHeaders(response));
        }
        */

        // If we want just a String, simply return the response.data casted as such.
        if (this.clazz == String.class) {
            result = (T) responseString;
            return Response.success(result, HttpHeaderParser.parseCacheHeaders(response));
        }

        JSONObject testObject = new JSONObject(responseString);

        if (testObject.has("Data")) {
            // Result contains Data object (array).
            result = mGson.fromJson(testObject.getString("Data"), clazz);
        } else {
            // Result does not contain the Data object - assumed to be a single result.
            result = mGson.fromJson(responseString, clazz);
        }

        return Response.success(result, HttpHeaderParser.parseCacheHeaders(response));

    } catch (UnsupportedEncodingException e) {
        Log.e("MOJIO", "MojioRequest UnsupportedEncodingException error");
        return Response.error(new ParseError(e));

    } catch (JsonSyntaxException e) {
        Log.e("MOJIO", "MojioRequest JsonSyntaxException error" + e.getMessage());
        return Response.error(new ParseError(e));

    } catch (JSONException e) {
        Log.e("MOJIO", "MojioRequest JSONException error: " + e.getMessage());
        return Response.error(new ParseError(e));

    } catch (com.google.gson.JsonParseException e) {
        Log.e("MOJIO", "MojioRequest JSONException error: " + e.getMessage());
        return Response.error(new ParseError(e));
    }
}

From source file:com.streamreduce.core.service.EmailServiceImpl.java

@Override
public void sendNewUserActivationEmail(User user) {
    try {/* w  w  w  . j a  v  a2s  .c  om*/

        // body
        String id = URLEncoder.encode(user.getId().toString(), DEFAULT_ENCODING);
        String key = URLEncoder.encode(user.getSecretKey(), DEFAULT_ENCODING);
        // append to the url
        String secretyKey = key + "/" + id;

        String from = (String) emailProperties.get("email.from");
        String urlPrefix = (String) emailProperties.get("email.urlprefix");
        String subject = (String) emailProperties.get("email.newUser.subject");

        VelocityContext context = new VelocityContext();
        context.put("urlPrefix", urlPrefix);
        context.put("secretKey", secretyKey);

        logger.debug("[SES EMAIL] send new user activation email for " + user.getUsername());

        // send the email
        sendEmail(user.getUsername(), from, subject, "new_user_activation_email", context);

    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage());
    }
}

From source file:io.personium.test.jersey.PersoniumRestAdapter.java

/**
 * GET/POST/PUT/DELETE ?.//  w  ww  . j av a  2 s  .  c  o m
 * @param method Http
 * @param url URL
 * @param body 
 * @param headers ??
 * @return DcResponse
 * @throws PersoniumException DAO
 */
public PersoniumResponse request(final String method, String url, String body, HashMap<String, String> headers)
        throws PersoniumException {
    HttpEntityEnclosingRequestBase req = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return method;
        }
    };
    req.setURI(URI.create(url));
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        req.setHeader(entry.getKey(), entry.getValue());
    }
    req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());

    if (body != null) {
        HttpEntity httpEntity = null;
        try {
            String bodyStr = toUniversalCharacterNames(body);
            httpEntity = new StringEntity(bodyStr);
        } catch (UnsupportedEncodingException e) {
            throw PersoniumException.create("error while request body encoding : " + e.getMessage(), 0);
        }
        req.setEntity(httpEntity);
    }
    debugHttpRequest(req, body);
    return this.request(req);
}

From source file:com.telefonica.iot.cygnus.utils.auth.keystone.KeyStoneUtilsImpl.java

@Override
public String updateSessionToken(String user, String password, String fiwareService, String fiwareServicePath)
        throws CygnusRuntimeError, CygnusPersistenceError {
    try {//from   ww w . ja  v a 2 s .c  o  m
        LOGGER.info("Requesting new token from Keystone Server.");
        // create the relative URL
        String relativeURL = KEYSTONE_RELATIVE_URL;

        // create the http headers
        ArrayList<Header> headers = getHeaders(null, fiwareService, fiwareServicePath);

        // generate JSON Body
        String bodyJSON = getAuthRequestJSON(user, password, fiwareService, fiwareServicePath);
        LOGGER.debug("Request bodyJSON: " + bodyJSON);

        StringEntity entity = new StringEntity(bodyJSON);

        // do the request
        JsonResponse response = doRequest("POST", relativeURL, true, headers, entity);

        // check the status
        if (response.getStatusCode() != 201) {
            LOGGER.error("Auth Error, HttpFS response:: " + response.getStatusCode() + " "
                    + response.getReasonPhrase() + "\n");
            LOGGER.error("response.toString :: " + response.getStatusCode() + " " + response.toString() + "\n");
            Header[] hders = response.getHeaders();
            String cabeceras = "";
            for (Header header : hders) {
                cabeceras += header.getName() + "  " + header.getValue() + "\n";
            }
            LOGGER.error("response.headers :: " + response.getStatusCode() + "\n" + cabeceras + "\n");

            throw new CygnusRuntimeError("Auth Error, HttpFS response:: " + response.getStatusCode() + " "
                    + response.getReasonPhrase() + "\n");
        } else {
            String token = "";
            // Get Token of headers
            for (Header header : response.getHeaders()) {
                if (header.getName().equals("X-Subject-Token")) {
                    token = header.getValue();
                }
            }
            if (!token.equals("")) {
                tokenCache.addToken(fiwareService, fiwareServicePath, token);
                LOGGER.info("Token succesfully received.");
                return token;
            } else {
                LOGGER.error("Token not Found, HttpFS response:: " + response.getStatusCode() + " "
                        + response.getReasonPhrase());
                throw new CygnusRuntimeError("Token not Found, HttpFS response:: " + response.getStatusCode()
                        + " " + response.getReasonPhrase());
            }
        } // if Check Status
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Unsupported encodding:: " + e.getMessage());
        throw new CygnusRuntimeError("Unsupported encodding:: " + e.getMessage());
    }
}

From source file:custom.application.login.java

public void execute(String provider) throws ApplicationException {
    HttpServletRequest http_request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST");
    HttpServletResponse http_response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");

    Reforward reforward = new Reforward(http_request, http_response);
    this.setVariable("from", reforward.getFromURL());
    System.out.println("From:" + reforward.getFromURL());
    try {//from ww w. j a va 2 s  . com
        HttpSession session = http_request.getSession();
        if (session.getAttribute("usr") == null)
            reforward.setDefault(createRequestString(oAuth2Provider.valueOf(provider.toUpperCase())));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        throw new ApplicationException(e.getMessage(), e);
    }
    reforward.forward();
}

From source file:net.netheos.pcsapi.providers.dropbox.Dropbox.java

@Override
public boolean delete(final CPath cpath) throws CStorageException {
    String url = buildUrl("fileops/delete");
    HttpPost request = new HttpPost(url);

    try {//from   w  w  w  .  j av  a2 s . c om
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        parameters.add(new BasicNameValuePair("root", scope));
        parameters.add(new BasicNameValuePair("path", cpath.getPathName()));

        request.setEntity(new UrlEncodedFormEntity(parameters, PcsUtils.UTF8.name()));

    } catch (UnsupportedEncodingException ex) {
        throw new CStorageException(ex.getMessage(), ex);
    }

    RequestInvoker<CResponse> invoker = getApiRequestInvoker(request, cpath);

    CResponse response = null;
    try {
        response = retryStrategy.invokeRetry(invoker);
        return true;

    } catch (CFileNotFoundException e) {
        // Non existing file
        return false;

    } finally {
        PcsUtils.closeQuietly(response);
    }
}