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.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

private static byte[] getBytes(final String string, final String encoding) throws NTLMException {
    try {/*from   w w w.j  a v  a 2  s . com*/
        return string.getBytes(encoding);
    } catch (final UnsupportedEncodingException e) {
        throw new NTLMException(e.getMessage(), e);
    }
}

From source file:org.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentVoid(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentVoid", module);
    Debug.logInfo("SagePay 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");

    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");

    parameters.put("VPSProtocol", vpsProtocol);
    parameters.put("TxType", "VOID");
    parameters.put("Vendor", vendor);
    parameters.put("VendorTxCode", vendorTxCode);
    parameters.put("VPSTxId", vpsTxId);
    parameters.put("SecurityKey", securityKey);
    parameters.put("TxAuthNo", txAuthNo);
    //end - void parameters

    try {//from w w w .  ja v a2  s.  com
        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;
}

From source file:org.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentRelease(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentRelease", module);
    Debug.logInfo("SagePay paymentRelease 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");

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

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

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

    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);
    //end - release parameters

    try {/*from www.  j av a2 s . c  o  m*/

        String successMessage = null;
        HttpPost httpPost = SagePayUtil.getHttpPost(props.get("releaseUrl"), 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 released
        if ("OK".equals(status)) {
            successMessage = "Payment Released";
        }
        //end - payment released

        //start - release request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = "Release request not formed properly or parameters missing";
        }
        //end - release 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:org.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentAuthorisation(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentAuthorisation", module);
    Debug.logInfo("SagePay 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");

    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("ReleaseAmount", amount);

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

    try {/*from   w w w . ja va  2 s.  c om*/
        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 Released";
        }
        //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:org.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentRefund(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentRefund", module);
    Debug.logInfo("SagePay paymentRefund 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 amount = (String) context.get("amount");
    String currency = (String) context.get("currency");
    String description = (String) context.get("description");

    String relatedVPSTxId = (String) context.get("relatedVPSTxId");
    String relatedVendorTxCode = (String) context.get("relatedVendorTxCode");
    String relatedSecurityKey = (String) context.get("relatedSecurityKey");
    String relatedTxAuthNo = (String) context.get("relatedTxAuthNo");

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

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

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

    parameters.put("VPSProtocol", vpsProtocol);
    parameters.put("TxType", "REFUND");
    parameters.put("Vendor", vendor);
    parameters.put("VendorTxCode", vendorTxCode);
    parameters.put("Amount", amount);
    parameters.put("Currency", currency);
    parameters.put("Description", description);
    parameters.put("RelatedVPSTxId", relatedVPSTxId);
    parameters.put("RelatedVendorTxCode", relatedVendorTxCode);
    parameters.put("RelatedSecurityKey", relatedSecurityKey);
    parameters.put("RelatedTxAuthNo", relatedTxAuthNo);
    //end - refund parameters

    try {//from  ww  w.  j a  v  a 2 s  . c  om
        String successMessage = null;

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

        Debug.logInfo("response data -> " + responseData, module);

        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)) {
            resultMap.put("vpsTxId", responseData.get("VPSTxId"));
            resultMap.put("txAuthNo", responseData.get("TxAuthNo"));
            successMessage = "Payment Refunded";
        }
        //end - payment refunded

        //start - refund not authorized by the acquiring bank
        if ("NOTAUTHED".equals(status)) {
            successMessage = "Refund not authorized by the acquiring bank";
        }
        //end - refund not authorized by the acquiring bank

        //start - refund request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = "Refund 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:org.apache.cloudstack.storage.datastore.util.DateraUtil.java

private static String executeApiRequest(DateraObject.DateraConnection conn, HttpRequest apiReq)
        throws DateraObject.DateraError {

    //Get the token first
    String authToken = null;//from www  .ja  v  a  2 s  .c  o  m
    try {
        authToken = login(conn);
    } catch (UnsupportedEncodingException e) {
        throw new CloudRuntimeException("Unable to login to Datera " + e.getMessage());
    }

    if (authToken == null) {
        throw new CloudRuntimeException("Unable to login to Datera: error getting auth token ");
    }

    apiReq.addHeader(HEADER_AUTH_TOKEN, authToken);

    return executeHttp(conn, apiReq);
}

From source file:org.apache.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentVoid(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentVoid", module);
    Debug.logInfo("SagePay 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");
    Locale locale = (Locale) context.get("locale");

    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");

    parameters.put("VPSProtocol", vpsProtocol);
    parameters.put("TxType", "VOID");
    parameters.put("Vendor", vendor);
    parameters.put("VendorTxCode", vendorTxCode);
    parameters.put("VPSTxId", vpsTxId);
    parameters.put("SecurityKey", securityKey);
    parameters.put("TxAuthNo", txAuthNo);
    //end - void parameters

    try (CloseableHttpClient httpClient = SagePayUtil.getHttpClient()) {
        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 = UtilProperties.getMessage(resource, "AccountingSagePayPaymentVoided", locale);
        }/*from  w  w  w.  j  a  v a  2 s  . c o  m*/
        //end - payment void

        //start - void request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentVoidRequestMalformed",
                    locale);
        }
        //end - void request not formed properly or parameters missing

        //start - invalid information passed in parameters
        if ("INVALID".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentInvalidInformationPassed", locale);
        }
        //end - invalid information passed in parameters

        //start - problem at Sagepay
        if ("ERROR".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentError", locale);
        }
        //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
        Debug.logError(uee, "Error occurred in encoding parameters for HttpPost (" + uee.getMessage() + ")",
                module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorEncodingParameters",
                        UtilMisc.toMap("errorString", uee.getMessage()), locale));
    } catch (ClientProtocolException cpe) {
        //from httpClient execute
        Debug.logError(cpe, "Error occurred in HttpClient execute(" + cpe.getMessage() + ")", module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecute",
                        UtilMisc.toMap("errorString", cpe.getMessage()), locale));
    } catch (IOException ioe) {
        //from httpClient execute or getResponsedata
        Debug.logError(ioe,
                "Error occurred in HttpClient execute or getting response (" + ioe.getMessage() + ")", module);
        resultMap = ServiceUtil.returnError(
                UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecuteOrGettingResponse",
                        UtilMisc.toMap("errorString", ioe.getMessage()), locale));
    }
    return resultMap;
}

From source file:org.apache.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentRelease(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentRelease", module);
    Debug.logInfo("SagePay paymentRelease 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");
    Locale locale = (Locale) context.get("locale");

    HttpHost host = SagePayUtil.getHost(props);

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

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

    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);
    //end - release parameters

    try (CloseableHttpClient httpClient = SagePayUtil.getHttpClient()) {
        String successMessage = null;
        HttpPost httpPost = SagePayUtil.getHttpPost(props.get("releaseUrl"), 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 released
        if ("OK".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentReleased", locale);
        }/*from  www. j av a2s . c  o  m*/
        //end - payment released

        //start - release request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentReleaseRequestMalformed", locale);
        }
        //end - release request not formed properly or parameters missing

        //start - invalid information passed in parameters
        if ("INVALID".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentInvalidInformationPassed", locale);
        }
        //end - invalid information passed in parameters

        //start - problem at Sagepay
        if ("ERROR".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentError", locale);
        }
        //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
        Debug.logError(uee, "Error occurred in encoding parameters for HttpPost (" + uee.getMessage() + ")",
                module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorEncodingParameters",
                        UtilMisc.toMap("errorString", uee.getMessage()), locale));
    } catch (ClientProtocolException cpe) {
        //from httpClient execute
        Debug.logError(cpe, "Error occurred in HttpClient execute(" + cpe.getMessage() + ")", module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecute",
                        UtilMisc.toMap("errorString", cpe.getMessage()), locale));
    } catch (IOException ioe) {
        //from httpClient execute or getResponsedata
        Debug.logError(ioe,
                "Error occurred in HttpClient execute or getting response (" + ioe.getMessage() + ")", module);
        resultMap = ServiceUtil.returnError(
                UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecuteOrGettingResponse",
                        UtilMisc.toMap("errorString", ioe.getMessage()), locale));
    }
    return resultMap;
}

From source file:org.apache.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentAuthorisation(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentAuthorisation", module);
    Debug.logInfo("SagePay 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");
    Locale locale = (Locale) context.get("locale");

    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("ReleaseAmount", amount);

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

    try (CloseableHttpClient httpClient = SagePayUtil.getHttpClient()) {
        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 = UtilProperties.getMessage(resource, "AccountingSagePayPaymentReleased", locale);
        }//  ww  w . ja  va  2 s  . c om
        //end - payment refunded

        //start - refund request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentReleaseRequestMalformed", locale);
        }
        //end - refund request not formed properly or parameters missing

        //start - invalid information passed in parameters
        if ("INVALID".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentInvalidInformationPassed", locale);
        }
        //end - invalid information passed in parameters

        //start - problem at Sagepay
        if ("ERROR".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentError", locale);
        }
        //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
        Debug.logError(uee, "Error occurred in encoding parameters for HttpPost (" + uee.getMessage() + ")",
                module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorEncodingParameters",
                        UtilMisc.toMap("errorString", uee.getMessage()), locale));
    } catch (ClientProtocolException cpe) {
        //from httpClient execute
        Debug.logError(cpe, "Error occurred in HttpClient execute(" + cpe.getMessage() + ")", module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecute",
                        UtilMisc.toMap("errorString", cpe.getMessage()), locale));
    } catch (IOException ioe) {
        //from httpClient execute or getResponsedata
        Debug.logError(ioe,
                "Error occurred in HttpClient execute or getting response (" + ioe.getMessage() + ")", module);
        resultMap = ServiceUtil.returnError(
                UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecuteOrGettingResponse",
                        UtilMisc.toMap("errorString", ioe.getMessage()), locale));
    }
    return resultMap;
}

From source file:org.apache.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java

public static Map<String, Object> paymentRefund(DispatchContext ctx, Map<String, Object> context) {
    Debug.logInfo("SagePay - Entered paymentRefund", module);
    Debug.logInfo("SagePay paymentRefund 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 amount = (String) context.get("amount");
    String currency = (String) context.get("currency");
    String description = (String) context.get("description");

    String relatedVPSTxId = (String) context.get("relatedVPSTxId");
    String relatedVendorTxCode = (String) context.get("relatedVendorTxCode");
    String relatedSecurityKey = (String) context.get("relatedSecurityKey");
    String relatedTxAuthNo = (String) context.get("relatedTxAuthNo");
    Locale locale = (Locale) context.get("locale");

    HttpHost host = SagePayUtil.getHost(props);

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

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

    parameters.put("VPSProtocol", vpsProtocol);
    parameters.put("TxType", "REFUND");
    parameters.put("Vendor", vendor);
    parameters.put("VendorTxCode", vendorTxCode);
    parameters.put("Amount", amount);
    parameters.put("Currency", currency);
    parameters.put("Description", description);
    parameters.put("RelatedVPSTxId", relatedVPSTxId);
    parameters.put("RelatedVendorTxCode", relatedVendorTxCode);
    parameters.put("RelatedSecurityKey", relatedSecurityKey);
    parameters.put("RelatedTxAuthNo", relatedTxAuthNo);
    //end - refund parameters

    try (CloseableHttpClient httpClient = SagePayUtil.getHttpClient()) {
        String successMessage = null;

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

        Debug.logInfo("response data -> " + responseData, module);

        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)) {
            resultMap.put("vpsTxId", responseData.get("VPSTxId"));
            resultMap.put("txAuthNo", responseData.get("TxAuthNo"));
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentRefunded", locale);
        }//  www . ja  va 2  s  . co m
        //end - payment refunded

        //start - refund not authorized by the acquiring bank
        if ("NOTAUTHED".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentRefundNotAuthorized",
                    locale);
        }
        //end - refund not authorized by the acquiring bank

        //start - refund request not formed properly or parameters missing
        if ("MALFORMED".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentRefundRequestMalformed", locale);
        }
        //end - refund request not formed properly or parameters missing

        //start - invalid information passed in parameters
        if ("INVALID".equals(status)) {
            successMessage = UtilProperties.getMessage(resource,
                    "AccountingSagePayPaymentInvalidInformationPassed", locale);
        }
        //end - invalid information passed in parameters

        //start - problem at Sagepay
        if ("ERROR".equals(status)) {
            successMessage = UtilProperties.getMessage(resource, "AccountingSagePayPaymentError", locale);
        }
        //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
        Debug.logError(uee, "Error occurred in encoding parameters for HttpPost (" + uee.getMessage() + ")",
                module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorEncodingParameters",
                        UtilMisc.toMap("errorString", uee.getMessage()), locale));
    } catch (ClientProtocolException cpe) {
        //from httpClient execute
        Debug.logError(cpe, "Error occurred in HttpClient execute(" + cpe.getMessage() + ")", module);
        resultMap = ServiceUtil
                .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecute",
                        UtilMisc.toMap("errorString", cpe.getMessage()), locale));
    } catch (IOException ioe) {
        //from httpClient execute or getResponsedata
        Debug.logError(ioe,
                "Error occurred in HttpClient execute or getting response (" + ioe.getMessage() + ")", module);
        resultMap = ServiceUtil.returnError(
                UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecuteOrGettingResponse",
                        UtilMisc.toMap("errorString", ioe.getMessage()), locale));
    }

    return resultMap;
}