Search in sources :

Example 16 with HttpClientException

use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.

the class ValueLinkServices method reload.

public static Map<String, Object> reload(DispatchContext dctx, Map<String, Object> context) {
    Delegator delegator = dctx.getDelegator();
    Properties props = getProperties(context);
    String cardNumber = (String) context.get("cardNumber");
    String pin = (String) context.get("pin");
    String currency = (String) context.get("currency");
    String orderId = (String) context.get("orderId");
    String partyId = (String) context.get("partyId");
    BigDecimal amount = (BigDecimal) context.get("amount");
    Locale locale = (Locale) context.get("locale");
    // override interface for void/rollback
    String iFace = (String) context.get("Interface");
    // get an api instance
    ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
    Map<String, Object> request = vl.getInitialRequestMap(context);
    request.put("Interface", iFace != null ? iFace : "Reload");
    request.put("CardNo", cardNumber);
    request.put("PIN", vl.encryptPin(pin));
    request.put("Amount", vl.getAmount(amount));
    request.put("LocalCurr", vl.getCurrency(currency));
    // user defined field #1
    if (UtilValidate.isNotEmpty(orderId)) {
        request.put("User1", orderId);
    }
    // user defined field #2
    if (UtilValidate.isNotEmpty(partyId)) {
        request.put("User2", partyId);
    }
    // set the timeout reversal
    setTimeoutReversal(dctx, context, request);
    // send the request
    Map<String, Object> response = null;
    try {
        response = vl.send(request);
    } catch (HttpClientException e) {
        Debug.logError(e, "Problem communicating with VL");
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToReloadGiftCard", locale));
    }
    String responseCode = (String) response.get("responsecode");
    Map<String, Object> result = ServiceUtil.returnSuccess();
    result.put("processResult", "00".equals(responseCode));
    result.put("responseCode", responseCode);
    result.put("authCode", response.get("authcode"));
    result.put("previousAmount", vl.getAmount((String) response.get("prevbal")));
    result.put("amount", vl.getAmount((String) response.get("newbal")));
    result.put("expireDate", response.get("expiredate"));
    result.put("cardClass", response.get("cardclass"));
    result.put("referenceNum", response.get("traceno"));
    Debug.logInfo("Reload Result : " + result, module);
    return result;
}
Also used : Locale(java.util.Locale) HttpClientException(org.apache.ofbiz.base.util.HttpClientException) Delegator(org.apache.ofbiz.entity.Delegator) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties) Properties(java.util.Properties) BigDecimal(java.math.BigDecimal)

Example 17 with HttpClientException

use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.

the class ValueLinkServices method transactionHistory.

public static Map<String, Object> transactionHistory(DispatchContext dctx, Map<String, Object> context) {
    Delegator delegator = dctx.getDelegator();
    Properties props = getProperties(context);
    String cardNumber = (String) context.get("cardNumber");
    String pin = (String) context.get("pin");
    String orderId = (String) context.get("orderId");
    String partyId = (String) context.get("partyId");
    Locale locale = (Locale) context.get("locale");
    // get an api instance
    ValueLinkApi vl = ValueLinkApi.getInstance(delegator, props);
    Map<String, Object> request = vl.getInitialRequestMap(context);
    request.put("Interface", "History");
    request.put("CardNo", cardNumber);
    request.put("PIN", vl.encryptPin(pin));
    // user defined field #1
    if (UtilValidate.isNotEmpty(orderId)) {
        request.put("User1", orderId);
    }
    // user defined field #2
    if (UtilValidate.isNotEmpty(partyId)) {
        request.put("User2", partyId);
    }
    // send the request
    Map<String, Object> response = null;
    try {
        response = vl.send(request);
    } catch (HttpClientException e) {
        Debug.logError(e, "Problem communicating with VL");
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingValueLinkUnableToCallHistoryInquiry", locale));
    }
    String responseCode = (String) response.get("responsecode");
    Map<String, Object> result = ServiceUtil.returnSuccess();
    result.put("processResult", "00".equals(responseCode));
    result.put("responseCode", responseCode);
    result.put("balance", vl.getAmount((String) response.get("currbal")));
    result.put("history", response.get("history"));
    result.put("expireDate", response.get("expiredate"));
    result.put("cardClass", response.get("cardclass"));
    result.put("referenceNum", response.get("traceno"));
    Debug.logInfo("History Result : " + result, module);
    return result;
}
Also used : Locale(java.util.Locale) HttpClientException(org.apache.ofbiz.base.util.HttpClientException) Delegator(org.apache.ofbiz.entity.Delegator) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties) Properties(java.util.Properties)

Example 18 with HttpClientException

use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.

the class CdyneServices method cdyneReturnCityState.

/**
 * CDyne ReturnCityState Service
 *@param dctx The DispatchContext that this service is operating in
 *@param context Map containing the input parameters
 *@return Map with the result of the service, the output parameters
 */
public static Map<String, Object> cdyneReturnCityState(DispatchContext dctx, Map<String, ?> context) {
    String zipcode = (String) context.get("zipcode");
    Locale locale = (Locale) context.get("locale");
    String serviceUrl = "http://ws.cdyne.com/psaddress/addresslookup.asmx/ReturnCityState?zipcode=" + zipcode + "&LicenseKey=" + licenseKey;
    try {
        String httpResponse = HttpClient.getUrlContent(serviceUrl);
        Document addressDocument = UtilXml.readXmlDocument(httpResponse);
        Element addressRootElement = addressDocument.getDocumentElement();
        Map<String, Object> response = ServiceUtil.returnSuccess();
        populateCdyneAddress(addressRootElement, response);
        if ("true".equals(response.get("ServiceError"))) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonCDyneServiceError", UtilMisc.toMap("zipcode", zipcode), locale));
        }
        if ("true".equals(response.get("AddressError"))) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonCDyneAddressError", UtilMisc.toMap("zipcode", zipcode), locale));
        }
        return response;
    } catch (HttpClientException e) {
        Debug.logError(e, "Error calling CDyne service at URL [" + serviceUrl + "]: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonCDyneCallingError", UtilMisc.toMap("serviceUrl", serviceUrl, "errorString", e.toString()), locale));
    } catch (SAXException | ParserConfigurationException | IOException e) {
        Debug.logError(e, "Error parsing XML result from CDyne service at URL [" + serviceUrl + "]: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonCDyneParsingError", UtilMisc.toMap("serviceUrl", serviceUrl, "errorString", e.toString()), locale));
    }
}
Also used : Locale(java.util.Locale) HttpClientException(org.apache.ofbiz.base.util.HttpClientException) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 19 with HttpClientException

use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.

the class RitaApi method send.

public RitaApi send() throws IOException, GeneralException {
    if (host == null || port == 0) {
        throw new GeneralException("TCP transaction not supported without valid host/port configuration");
    }
    if (mode == MODE_IN) {
        String stream = this.toString() + "..\r\n";
        Debug.logInfo("Sending - \n" + stream, module);
        String urlString = "http://" + host + ":" + port;
        HttpClient http = new HttpClient(urlString);
        http.setDebug(true);
        Map<String, String> docMap = new HashMap<>();
        String resp = null;
        try {
            resp = http.post(stream);
        } catch (HttpClientException e) {
            Debug.logError(e, module);
            throw new IOException(e.getMessage());
        }
        String[] lines = resp.split("\n");
        for (int i = 0; i < lines.length; i++) {
            Debug.logInfo(lines[i], module);
            if (!".".equals(lines[i].trim())) {
                String[] lineSplit = lines[i].trim().split(" ", 2);
                if (lineSplit != null && lineSplit.length == 2) {
                    docMap.put(lineSplit[0], lineSplit[1]);
                } else {
                    Debug.logWarning("Line split error - " + lines[i], module);
                }
            } else {
                break;
            }
        }
        RitaApi out = new RitaApi(docMap);
        return out;
    }
    throw new IllegalStateException("Cannot send output object");
}
Also used : GeneralException(org.apache.ofbiz.base.util.GeneralException) HttpClientException(org.apache.ofbiz.base.util.HttpClientException) HashMap(java.util.HashMap) HttpClient(org.apache.ofbiz.base.util.HttpClient) IOException(java.io.IOException)

Example 20 with HttpClientException

use of org.apache.ofbiz.base.util.HttpClientException in project ofbiz-framework by apache.

the class AIMPaymentServices method processCard.

private static Map<String, Object> processCard(Map<String, Object> request, Properties props, Locale locale) {
    Map<String, Object> result = new HashMap<String, Object>();
    String url = props.getProperty("url");
    if (UtilValidate.isEmpty(url)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingAuthorizeNetTransactionUrlNotFound", locale));
    }
    if (isTestMode()) {
        Debug.logInfo("TEST Authorize.net using url [" + url + "]", module);
        Debug.logInfo("TEST Authorize.net request string " + request.toString(), module);
        Debug.logInfo("TEST Authorize.net properties string " + props.toString(), module);
    }
    // card present has a different layout from standard AIM; this determines how to parse the response
    int apiType = UtilValidate.isEmpty(props.get("cpMarketType")) ? AuthorizeResponse.AIM_RESPONSE : AuthorizeResponse.CP_RESPONSE;
    try {
        HttpClient httpClient = new HttpClient(url, request);
        String certificateAlias = props.getProperty("certificateAlias");
        httpClient.setClientCertificateAlias(certificateAlias);
        String httpResponse = httpClient.post();
        Debug.logInfo("transaction response: " + httpResponse, module);
        AuthorizeResponse ar = new AuthorizeResponse(httpResponse, apiType);
        if (ar.isApproved()) {
            result.put("authResult", Boolean.TRUE);
        } else {
            result.put("authResult", Boolean.FALSE);
            if (Debug.infoOn()) {
                Debug.logInfo("transactionId:  " + ar.getTransactionId(), module);
                Debug.logInfo("responseCode:   " + ar.getResponseCode(), module);
                Debug.logInfo("responseReason: " + ar.getReasonCode(), module);
                Debug.logInfo("reasonText:     " + ar.getReasonText(), module);
            }
        }
        result.put("httpResponse", httpResponse);
        result.put("authorizeResponse", ar);
    } catch (HttpClientException e) {
        Debug.logInfo(e, "Could not complete Authorize.Net transaction: " + e.toString(), module);
    }
    result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
    return result;
}
Also used : HttpClientException(org.apache.ofbiz.base.util.HttpClientException) HashMap(java.util.HashMap) HttpClient(org.apache.ofbiz.base.util.HttpClient)

Aggregations

HttpClientException (org.apache.ofbiz.base.util.HttpClientException)20 Locale (java.util.Locale)11 HttpClient (org.apache.ofbiz.base.util.HttpClient)10 Properties (java.util.Properties)9 UtilProperties (org.apache.ofbiz.base.util.UtilProperties)9 Delegator (org.apache.ofbiz.entity.Delegator)9 EntityUtilProperties (org.apache.ofbiz.entity.util.EntityUtilProperties)9 IOException (java.io.IOException)5 BigDecimal (java.math.BigDecimal)5 HashMap (java.util.HashMap)3 GeneralException (org.apache.ofbiz.base.util.GeneralException)3 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)3 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)3 Document (org.w3c.dom.Document)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TransformerException (javax.xml.transform.TransformerException)2 Element (org.w3c.dom.Element)2 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1