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:io.getlime.push.client.PushServerClient.java

/**
 * Get a campaign specified with campaignID.
 *
 * @param campaignId ID of campaign to get.
 * @return Details of campaign, defined in CampaignResponse
 *///from   w  w w . jav a2  s .c om
public ObjectResponse<CampaignResponse> getCampaign(Long campaignId) throws PushServerClientException {
    try {
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TypeReference<ObjectResponse<CampaignResponse>> typeReference = new TypeReference<ObjectResponse<CampaignResponse>>() {
        };
        return getObjectImpl("/push/campaign/" + campaignIdSanitized + "/detail", null, typeReference);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

From source file:org.ngrinder.script.controller.FileEntryController.java

/**
 * Download file entry of given path./*from www .j av  a  2  s.  c o  m*/
 *
 * @param user     current user
 * @param path     user
 * @param response response
 */
@RequestMapping("/download/**")
public void download(User user, @RemainedPath String path, HttpServletResponse response) {
    FileEntry fileEntry = fileEntryService.getOne(user, path);
    if (fileEntry == null) {
        LOG.error("{} requested to download not existing file entity {}", user.getUserId(), path);
        return;
    }
    response.reset();
    try {
        response.addHeader("Content-Disposition", "attachment;filename="
                + java.net.URLEncoder.encode(FilenameUtils.getName(fileEntry.getPath()), "utf8"));
    } catch (UnsupportedEncodingException e1) {
        LOG.error(e1.getMessage(), e1);
    }
    response.setContentType("application/octet-stream; charset=UTF-8");
    response.addHeader("Content-Length", "" + fileEntry.getFileSize());
    byte[] buffer = new byte[4096];
    ByteArrayInputStream fis = null;
    OutputStream toClient = null;
    try {
        fis = new ByteArrayInputStream(fileEntry.getContentBytes());
        toClient = new BufferedOutputStream(response.getOutputStream());
        int readLength;
        while (((readLength = fis.read(buffer)) != -1)) {
            toClient.write(buffer, 0, readLength);
        }
    } catch (IOException e) {
        throw processException("error while download file", e);
    } finally {
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(toClient);
    }
}

From source file:io.getlime.push.client.PushServerClient.java

/**
 * Delete a campaign specified with campaignId.
 *
 * @return True if campaign is removed, false otherwise.
 *//*  w w  w  .j  ava 2s . co m*/
public boolean deleteCampaign(Long campaignId) throws PushServerClientException {
    try {
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TypeReference<ObjectResponse<DeleteCampaignResponse>> typeReference = new TypeReference<ObjectResponse<DeleteCampaignResponse>>() {
        };
        ObjectResponse<?> response = postObjectImpl("/push/campaign/" + campaignIdSanitized + "/delete", null,
                typeReference);
        return response.getStatus().equals(Response.Status.OK);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

From source file:io.getlime.push.client.PushServerClient.java

/**
 * Send a specific campaign to users carrying this campaignID in PushCampaignUser model, but only once per device identified by token.
 *
 * @param campaignId Identifier of campaign.
 * @return True if sent, else otherwise.
 *///from   www . ja  va2s .  c  o  m
public boolean sendCampaign(Long campaignId) throws PushServerClientException {
    try {
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TypeReference<Response> typeReference = new TypeReference<Response>() {
        };
        ObjectResponse<?> response = postObjectImpl("/push/campaign/send/live/" + campaignIdSanitized, null,
                typeReference);
        return response.getStatus().equals(Response.Status.OK);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

From source file:io.getlime.push.client.PushServerClient.java

/**
 * Add a list of users to a specific campaign
 *
 * @param campaignId Identifier of campaign.
 * @param users List of users to add./*from   w w w .java  2s  . c  o  m*/
 * @return True if adding was successful, false otherwise.
 */
public boolean addUsersToCampaign(Long campaignId, List<String> users) throws PushServerClientException {
    try {
        ListOfUsers listOfUsers = new ListOfUsers();
        listOfUsers.addAll(users);
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TypeReference<Response> typeReference = new TypeReference<Response>() {
        };
        ObjectResponse<?> response = putObjectImpl("/push/campaign/" + campaignIdSanitized + "/user/add",
                new ObjectRequest<>(listOfUsers), typeReference);
        return response.getStatus().equals(Response.Status.OK);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

From source file:io.getlime.push.client.PushServerClient.java

/**
 * Get a list of users in paged format from specific campaign
 *
 * @param campaignId Identifier of campaign.
 * @param page Page number.//  www  .j a  v  a 2s.  c o  m
 * @param size Size of elements per page.
 * @return Page of users specified with params.
 */
public ObjectResponse<PagedResponse<ListOfUsersFromCampaignResponse>> getListOfUsersFromCampaign(
        Long campaignId, int page, int size) throws PushServerClientException {
    try {
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TypeReference<ObjectResponse<PagedResponse<ListOfUsersFromCampaignResponse>>> typeReference = new TypeReference<ObjectResponse<PagedResponse<ListOfUsersFromCampaignResponse>>>() {
        };
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("size", size);
        return getObjectImpl("/push/campaign/" + campaignIdSanitized + "/user/list", params, typeReference);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

From source file:io.getlime.push.client.PushServerClient.java

/**
 * Delete a list of users from specific campaign.
 *
 * @param campaignId Identifier of campaign.
 * @param users List of users' Identifiers to delete.
 * @return True if deletion was successful, false otherwise.
 *//*  w  w w.  jav a 2  s.  com*/
public boolean deleteUsersFromCampaign(Long campaignId, List<String> users) throws PushServerClientException {
    try {
        ListOfUsers listOfUsers = new ListOfUsers();
        listOfUsers.addAll(users);
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TypeReference<Response> typeReference = new TypeReference<Response>() {
        };
        ObjectResponse<?> response = postObjectImpl("/push/campaign/" + campaignIdSanitized + "/user/delete",
                new ObjectRequest<>(listOfUsers), typeReference);
        return response.getStatus().equals(Response.Status.OK);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

From source file:io.getlime.push.client.PushServerClient.java

/**
 * Send a campaign on test user for trying its correctness.
 *
 * @param campaignId Identifier of campaign.
 * @param userId Identifier of test user.
 * @return True if sent, else otherwise.
 *///from w w w  .  j  av  a 2  s.c  o m
public boolean sendTestCampaign(Long campaignId, String userId) throws PushServerClientException {
    try {
        String campaignIdSanitized = URLEncoder.encode(String.valueOf(campaignId), "utf-8");
        TestCampaignRequest testCampaignRequest = new TestCampaignRequest();
        testCampaignRequest.setUserId(userId);
        TypeReference<Response> typeReference = new TypeReference<Response>() {
        };
        ObjectResponse<?> response = postObjectImpl("/push/campaign/send/test/" + campaignIdSanitized,
                new ObjectRequest<>(testCampaignRequest), typeReference);
        return response.getStatus().equals(Response.Status.OK);
    } catch (UnsupportedEncodingException e) {
        throw new PushServerClientException(new Error("PUSH_SERVER_CLIENT_ERROR", e.getMessage()));
    }
}

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

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

    try {// ww  w .  j  a  va  2  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 (CHttpException e) {

        if (e.getStatus() == 403) {
            // object already exists, check if real folder or blob :
            CFile cfile = getFile(cpath);

            if (!cfile.isFolder()) {
                // a blob already exists at this path : error !
                throw new CInvalidFileTypeException(cpath, false);
            }
            // Already existing folder
            return false;
        }
        // Other exception :
        throw e;

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

From source file:org.ednovo.goorusearchwidget.WebService.java

public String webGet(String methodName, Map<String, String> params) {
    String getUrl = webServiceUrl + methodName;
    int i = 0;//  w w  w  .  j  a v  a  2  s .  c o m
    for (Map.Entry<String, String> param : params.entrySet()) {
        if (i == 0) {
            getUrl += "?";
        } else {
            getUrl += "&";
        }
        try {
            getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8");
        } catch (UnsupportedEncodingException e) { // TODO Auto-generated
            // catch block
            e.printStackTrace();
        }
        i++;
    }
    httpGet = new HttpGet(getUrl);
    Log.e("WebGetURL: ", getUrl);
    try {
        response = httpClient.execute(httpGet);
    } catch (Exception e) {
        Log.e("Groshie:", e.getMessage());
    }
    // we assume that the response body contains the error message
    try {
        ret = EntityUtils.toString(response.getEntity());
    } catch (IOException e) {
        Log.e("Groshie:", e.getMessage());
    }
    return ret;
}