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.openkm.extension.servlet.ZohoServlet.java

@Override
public String getTicket() throws OKMException {
    log.debug("getTicket()");
    updateSessionManager();/*from   w  w  w .j a v a 2  s  . co  m*/
    String ticket = "";

    try {
        // Construct data
        // String data = URLEncoder.encode("LOGIN_ID", "UTF-8") + "=" + URLEncoder.encode(Config.ZOHO_USER, "UTF-8");
        // data += "&" + URLEncoder.encode("PASSWORD", "UTF-8") + "=" + URLEncoder.encode(Config.ZOHO_PASSWORD, "UTF-8");
        // data += "&" + URLEncoder.encode("FROM_AGENT", "UTF-8") + "=" + URLEncoder.encode("true", "UTF-8");
        // data += "&" + URLEncoder.encode("servicename", "UTF-8") + "=" + URLEncoder.encode("ZohoWriter", "UTF-8");

        // Send data
        URL url;
        url = new URL("https://accounts.zoho.com/login");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);

        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;

        while ((line = rd.readLine()) != null) {
            if (line.startsWith("TICKET=")) {
                ticket = line.substring(7);
            }
        }
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage(), e);
        throw new OKMException(
                ErrorCode.get(ErrorCode.ORIGIN_OKMZohoService, ErrorCode.CAUSE_UnsupportedEncoding),
                e.getMessage());
    } catch (MalformedURLException e) {
        log.error(e.getMessage(), e);
        throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMZohoService, ErrorCode.CAUSE_MalformedURL),
                e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMZohoService, ErrorCode.CAUSE_IO),
                e.getMessage());
    }

    log.debug("getTicket: {}", ticket);
    return ticket;
}

From source file:org.androdyne.StacktraceUploader.java

/**
 * Post the trace file specified by the parameter to the androdyne service.
 **///from   ww  w. j  a v a 2s . com
private boolean postStacktrace(File file) {
    List<NameValuePair> trace = readStacktrace(file);
    if (null == trace) {
        android.util.Log.e(LTAG, "Could not read " + file.getAbsolutePath() + ", purging.");
        return true;
    }

    boolean ret = false;

    trace.add(new BasicNameValuePair("signature", createSignature(trace)));
    HttpPost post = new HttpPost(mAPIUrl);

    try {
        post.setEntity(new UrlEncodedFormEntity(trace, HTTP.UTF_8));
        HttpResponse response = mClient.execute(post);

        if (200 == response.getStatusLine().getStatusCode()) {
            // All ok.
            // android.util.Log.d(LTAG, "Trace submitted");
            ret = true;
        } else {
            String content = readStream(response.getEntity().getContent());
            android.util.Log.e(LTAG, "Submission error: " + content);
        }

    } catch (UnsupportedEncodingException ex) {
        android.util.Log.e(LTAG, "Fatal: " + ex.getMessage());
    } catch (IOException ex) {
        android.util.Log.e(LTAG, "IO Exception while transmitting, trying again next time: " + ex.getMessage());
    }

    return ret;
}

From source file:com.talent.nio.communicate.receive.DecodeRunnable.java

/**
 * ??/*  ww  w. j av a2s. c  o  m*/
 * 
 * @param datas
 */
public void addMsg(ByteBuf datas) {
    if (DebugUtils.isNeedDebug(channelContext)) {
        log.error("com.talent.nio.communicate.receive.DecodeRunnable.addMsg(byte[]):"
                + ArrayUtils.toString(datas));
        try {
            log.error("com.talent.nio.communicate.receive.DecodeRunnable.addMsg(byte[]):"
                    + new String(datas.array(), "utf-8"));
        } catch (UnsupportedEncodingException e) {
            log.error(e.getMessage(), e);
        }
    }

    getMsgQueue().add(datas);
}

From source file:com.oakhole.auth.web.FileController.java

@RequestMapping(value = "download/{id}", method = RequestMethod.GET)
public void download(@PathVariable("id") Long id, HttpServletRequest request, HttpServletResponse response) {

    File file = this.fileService.get(id);
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    // ????//  w ww  .  java 2s.com
    if (auth(file, "rx")) {
        java.io.File realFile = new java.io.File(file.getUrl());

        String realName = file.getName();
        long fileLength = realFile.length();

        // ??
        response.setContentType("text/plain");
        try {
            response.setHeader("Content-disposition",
                    "attachment; filename=" + new String(realName.getBytes("utf-8"), "ISO8859-1"));
        } catch (UnsupportedEncodingException e) {
            logger.error("???: {}", e.getMessage());
        }
        response.setHeader("Content-Length", String.valueOf(fileLength));

        try {
            bis = new BufferedInputStream(new FileInputStream(realFile));
        } catch (FileNotFoundException e) {
            logger.error(": {}", e.getMessage());
        }
        try {
            bos = new BufferedOutputStream(response.getOutputStream());
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (IOException e) {
            logger.error("?io{}", e.getMessage());
        } finally {
            try {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:ca.ualberta.CMPUT301W15T06.ESClient.java

/**
 * Consumes the POST/Insert operation of the service
 * @throws IOException // w w w.  j av a  2  s.com
 * @throws IllegalStateException 
 */
public void pushUser(User user) throws IllegalStateException, IOException {
    HttpPost httpPost = new HttpPost(USER + user.getUserName());
    StringEntity stringentity = null;
    try {
        stringentity = new StringEntity(gson.toJson(user));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException(e.getMessage());
    }
    httpPost.setHeader("Accept", "application/json");

    httpPost.setEntity(stringentity);
    HttpResponse response = null;
    try {
        response = httpclient.execute(httpPost);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException(e.getMessage());
    }

    String status = response.getStatusLine().toString();
    Log.i("insert", status);
}

From source file:ca.ualberta.CMPUT301W15T06.ESClient.java

public void pushUserList(UserList userList) throws IllegalStateException, IOException {
    // TODO Auto-generated method stub
    HttpPost httpPost = new HttpPost(USER_LIST);
    StringEntity stringentity = null;//from w w  w.j  a  v a2  s .c  o m
    try {
        stringentity = new StringEntity(gson.toJson(userList));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException(e.getMessage());
    }
    httpPost.setHeader("Accept", "application/json");

    httpPost.setEntity(stringentity);
    HttpResponse response = null;
    try {
        response = httpclient.execute(httpPost);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        throw new RuntimeException(e.getMessage());
    }

    String status = response.getStatusLine().toString();
    Log.i("insert", status);
}

From source file:com.lidroid.xutils.http.client.RequestParams.java

/**
 * Returns an HttpEntity containing all request parameters
 *///w w w  .ja  v  a 2s .  c  o  m
public HttpEntity getEntity() {

    if (bodyEntity != null) {
        return bodyEntity;
    }

    HttpEntity result = null;

    if (fileParams != null && !fileParams.isEmpty()) {

        MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        if (bodyParams != null) {
            for (NameValuePair param : bodyParams) {
                try {
                    multipartEntity.addPart(param.getName(), new StringBody(param.getValue()));
                } catch (UnsupportedEncodingException e) {
                    LogUtils.e(e.getMessage(), e);
                }
            }
        }

        for (ConcurrentHashMap.Entry<String, ContentBody> entry : fileParams.entrySet()) {
            multipartEntity.addPart(entry.getKey(), entry.getValue());
        }

        result = multipartEntity;
    } else if (bodyParams != null) {
        result = new BodyParamsEntity(bodyParams, charset);
    }

    return result;
}

From source file:com.orig.gls.security.Encode.java

public String decrypt(String value) {
    try {/*from   w w  w .  jav  a  2 s  .  c  o m*/
        Cipher dcipher = Cipher.getInstance("DESede/CBC/PKCS5Padding", "SunJCE");
        dcipher.init(Cipher.DECRYPT_MODE, key, iv);
        if (value == null) {
            return null;
        }
        //Decode Base 64 to get Bytes
        byte[] dec = Base64.decodeBase64(value.getBytes());
        //Decrypt
        byte[] utf8 = dcipher.doFinal(dec);
        //Decode String using utf8
        return new String(utf8, "UTF-8");
    } catch (UnsupportedEncodingException asd) {
        System.out.println(asd.getMessage());
    } catch (InvalidAlgorithmParameterException asd) {
        System.out.println(asd.getMessage());
    } catch (InvalidKeyException asd) {
        System.out.println(asd.getMessage());
    } catch (NoSuchAlgorithmException asd) {
        System.out.println(asd.getMessage());
    } catch (NoSuchProviderException asd) {
        System.out.println(asd.getMessage());
    } catch (BadPaddingException asd) {
        System.out.println(asd.getMessage());
    } catch (IllegalBlockSizeException asd) {
        System.out.println(asd.getMessage());
    } catch (NoSuchPaddingException asd) {
        System.out.println(asd.getMessage());
    }
    return null;
}

From source file:com.osafe.services.sagepay.SagePayTokenServices.java

public static Map<String, Object> paymentAuthorisation(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay Token -  Entered paymentAuthorisation", module);
    //        Debug.logInfo("SagePay Token - paymentAuthorisation context : " + context, module);

    Delegator delegator = ctx.getDelegator();
    Map<String, Object> resultMap = new HashMap<String, Object>();

    Map<String, String> props = buildSagePayProperties(context, delegator);

    String vendorTxCode = (String) context.get("vendorTxCode");
    String vpsTxId = (String) context.get("vpsTxId");
    String securityKey = (String) context.get("securityKey");
    String txAuthNo = (String) context.get("txAuthNo");
    String amount = (String) context.get("amount");
    String token = (String) context.get("token");
    String currency = (String) context.get("currency");
    String description = (String) context.get("description");
    String billingSurname = (String) context.get("billingSurname");
    String billingFirstnames = (String) context.get("billingFirstnames");
    String billingAddress = (String) context.get("billingAddress");
    String billingAddress2 = (String) context.get("billingAddress2");
    String billingCity = (String) context.get("billingCity");
    String billingPostCode = (String) context.get("billingPostCode");
    String billingCountry = (String) context.get("billingCountry");
    String billingState = (String) context.get("billingState");
    String billingPhone = (String) context.get("billingPhone");

    HttpClient httpClient = SagePayUtil.getHttpClient();
    HttpHost host = SagePayUtil.getHost(props);

    //start - authorization parameters
    Map<String, String> parameters = new HashMap<String, String>();

    String vpsProtocol = props.get("protocolVersion");
    String vendor = props.get("vendor");
    String txType = props.get("authoriseTransType");

    parameters.put("VPSProtocol", vpsProtocol);
    parameters.put("TxType", txType);
    parameters.put("Vendor", vendor);
    parameters.put("VendorTxCode", vendorTxCode);
    parameters.put("VPSTxId", vpsTxId);
    parameters.put("SecurityKey", securityKey);
    parameters.put("TxAuthNo", txAuthNo);
    parameters.put("Amount", amount);
    parameters.put("Token", token);
    parameters.put("Currency", currency);

    if (description != null) {
        parameters.put("Description", description);
    }//from   w  w w. j  a  va  2s .  c  o  m
    if (billingSurname != null) {
        parameters.put("BillingSurname", billingSurname);
    }
    if (billingFirstnames != null) {
        parameters.put("BillingFirstnames", billingFirstnames);
    }
    if (billingAddress != null) {
        parameters.put("BillingAddress1", billingAddress);
    }
    if (billingAddress2 != null) {
        parameters.put("BillingAddress2", billingAddress2);
    }
    if (billingCity != null) {
        parameters.put("BillingCity", billingCity);
    }
    if (billingPostCode != null) {
        parameters.put("BillingPostCode", billingPostCode);
    }
    if (billingCountry != null) {
        parameters.put("BillingCountry", billingCountry);
    }
    if (billingState != null) {
        parameters.put("BillingState", billingState);
    }
    if (billingPhone != null) {
        parameters.put("BillingPhone", billingPhone);
    }

    //        Debug.logInfo("authorization parameters -> " + parameters, module);
    //end - authorization parameters

    try {
        String successMessage = null;
        HttpPost httpPost = SagePayUtil.getHttpPost(props.get("authoriseUrl"), parameters);
        HttpResponse response = httpClient.execute(host, httpPost);

        Map<String, String> responseData = SagePayUtil.getResponseData(response);
        String status = responseData.get("Status");
        String statusDetail = responseData.get("StatusDetail");

        resultMap.put("status", status);
        resultMap.put("statusDetail", statusDetail);

        //start - payment refunded
        if ("OK".equals(status)) {
            successMessage = "Payment Authorised";
        }
        //end - payment refunded

        //start - refund request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = "Released request not formed properly or parameters missing";
        }
        //end - refund request not formed properly or parameters missing

        //start - invalid information passed in parameters
        if ("INVALID".equals(status)) {
            successMessage = "Invalid information passed in parameters";
        }
        //end - invalid information passed in parameters

        //start - problem at Sagepay
        if ("ERROR".equals(status)) {
            successMessage = "Problem at SagePay";
        }
        //end - problem at Sagepay

        resultMap.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
        resultMap.put(ModelService.SUCCESS_MESSAGE, successMessage);

    } catch (UnsupportedEncodingException uee) {
        //exception in encoding parameters in httpPost
        String errorMsg = "Error occured in encoding parameters for HttpPost (" + uee.getMessage() + ")";
        Debug.logError(uee, errorMsg, module);
        resultMap = ServiceUtil.returnError(errorMsg);
    } catch (ClientProtocolException cpe) {
        //from httpClient execute
        String errorMsg = "Error occured in HttpClient execute(" + cpe.getMessage() + ")";
        Debug.logError(cpe, errorMsg, module);
        resultMap = ServiceUtil.returnError(errorMsg);
    } catch (IOException ioe) {
        //from httpClient execute or getResponsedata
        String errorMsg = "Error occured in HttpClient execute or getting response (" + ioe.getMessage() + ")";
        Debug.logError(ioe, errorMsg, module);
        resultMap = ServiceUtil.returnError(errorMsg);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
    return resultMap;
}

From source file:com.osafe.services.sagepay.SagePayTokenServices.java

public static Map<String, Object> paymentVoid(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay Token -  Entered paymentVoid", module);
    //        Debug.logInfo("SagePay Token - paymentVoid context : " + context, module);

    Delegator delegator = ctx.getDelegator();
    Map<String, Object> resultMap = new HashMap<String, Object>();

    Map<String, String> props = buildSagePayProperties(context, delegator);

    String vendorTxCode = (String) context.get("vendorTxCode");
    String vpsTxId = (String) context.get("vpsTxId");
    String securityKey = (String) context.get("securityKey");
    String txAuthNo = (String) context.get("txAuthNo");
    String amount = (String) context.get("amount");
    String token = (String) context.get("token");
    String currency = (String) context.get("currency");
    String description = (String) context.get("description");
    String billingSurname = (String) context.get("billingSurname");
    String billingFirstnames = (String) context.get("billingFirstnames");
    String billingAddress = (String) context.get("billingAddress");
    String billingAddress2 = (String) context.get("billingAddress2");
    String billingCity = (String) context.get("billingCity");
    String billingPostCode = (String) context.get("billingPostCode");
    String billingCountry = (String) context.get("billingCountry");
    String billingState = (String) context.get("billingState");
    String billingPhone = (String) context.get("billingPhone");

    HttpClient httpClient = SagePayUtil.getHttpClient();
    HttpHost host = SagePayUtil.getHost(props);

    //start - void parameters
    Map<String, String> parameters = new HashMap<String, String>();

    String vpsProtocol = props.get("protocolVersion");
    String vendor = props.get("vendor");
    String txType = props.get("voidTransType");

    parameters.put("VPSProtocol", vpsProtocol);
    parameters.put("TxType", txType);
    parameters.put("Vendor", vendor);
    parameters.put("VendorTxCode", vendorTxCode);
    parameters.put("VPSTxId", vpsTxId);
    parameters.put("SecurityKey", securityKey);
    parameters.put("TxAuthNo", txAuthNo);
    parameters.put("Amount", amount);
    parameters.put("Description", description);
    parameters.put("Token", token);
    parameters.put("Currency", currency);

    if (description != null) {
        parameters.put("Description", description);
    }/*from   w ww.j av  a  2s.  c  o m*/
    if (billingSurname != null) {
        parameters.put("BillingSurname", billingSurname);
    }
    if (billingFirstnames != null) {
        parameters.put("BillingFirstnames", billingFirstnames);
    }
    if (billingAddress != null) {
        parameters.put("BillingAddress1", billingAddress);
    }
    if (billingAddress2 != null) {
        parameters.put("BillingAddress2", billingAddress2);
    }
    if (billingCity != null) {
        parameters.put("BillingCity", billingCity);
    }
    if (billingPostCode != null) {
        parameters.put("BillingPostCode", billingPostCode);
    }
    if (billingCountry != null) {
        parameters.put("BillingCountry", billingCountry);
    }
    if (billingState != null) {
        parameters.put("BillingState", billingState);
    }
    if (billingPhone != null) {
        parameters.put("BillingPhone", billingPhone);
    }
    //end - void parameters

    try {
        String successMessage = null;

        HttpPost httpPost = SagePayUtil.getHttpPost(props.get("voidUrl"), parameters);
        HttpResponse response = httpClient.execute(host, httpPost);
        Map<String, String> responseData = SagePayUtil.getResponseData(response);

        String status = responseData.get("Status");
        String statusDetail = responseData.get("StatusDetail");

        resultMap.put("status", status);
        resultMap.put("statusDetail", statusDetail);

        //start - payment void
        if ("OK".equals(status)) {
            successMessage = "Payment Voided";
        }
        //end - payment void

        //start - void request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = "Void request not formed properly or parameters missing";
        }
        //end - void request not formed properly or parameters missing

        //start - invalid information passed in parameters
        if ("INVALID".equals(status)) {
            successMessage = "Invalid information passed in parameters";
        }
        //end - invalid information passed in parameters

        //start - problem at Sagepay
        if ("ERROR".equals(status)) {
            successMessage = "Problem at SagePay";
        }
        //end - problem at Sagepay

        resultMap.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
        resultMap.put(ModelService.SUCCESS_MESSAGE, successMessage);

    } catch (UnsupportedEncodingException uee) {
        //exception in encoding parameters in httpPost
        String errorMsg = "Error occured in encoding parameters for HttpPost (" + uee.getMessage() + ")";
        Debug.logError(uee, errorMsg, module);
        resultMap = ServiceUtil.returnError(errorMsg);
    } catch (ClientProtocolException cpe) {
        //from httpClient execute
        String errorMsg = "Error occured in HttpClient execute(" + cpe.getMessage() + ")";
        Debug.logError(cpe, errorMsg, module);
        resultMap = ServiceUtil.returnError(errorMsg);
    } catch (IOException ioe) {
        //from httpClient execute or getResponsedata
        String errorMsg = "Error occured in HttpClient execute or getting response (" + ioe.getMessage() + ")";
        Debug.logError(ioe, errorMsg, module);
        resultMap = ServiceUtil.returnError(errorMsg);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
    return resultMap;
}