/** * Transmit a request to ValueLink * * @param url override URL from what is defined in the properties * @param request request Map of request parameters * @return Map of response parameters * @throws HttpClientException */ public Map<String, Object> send(String url, Map<String, Object> request) throws HttpClientException { if (debug) { Debug.logInfo("Request : " + url + " / " + request, module); } // read the timeout value String timeoutString = (String) props.get("payment.valuelink.timeout"); int timeout = 34; try { timeout = Integer.parseInt(timeoutString); } catch (NumberFormatException e) { Debug.logError(e, "Unable to set timeout to " + timeoutString + " using default " + timeout); } // create the HTTP client HttpClient client = new HttpClient(url, request); client.setTimeout(timeout * 1000); client.setDebug(debug); client.setClientCertificateAlias((String) props.get("payment.valuelink.certificateAlias")); String response = client.post(); // parse the response and return a map return this.parseResponse(response); }
/** * JavaMail Service that gets body content from a URL * * @param ctx The DispatchContext that this service is operating in * @param rcontext Map containing the input parameters * @return Map with the result of the service, the output parameters */ public static Map<String, Object> sendMailFromUrl( DispatchContext ctx, Map<String, ? extends Object> rcontext) { // pretty simple, get the content and then call the sendMail method below Map<String, Object> sendMailContext = UtilMisc.makeMapWritable(rcontext); String bodyUrl = (String) sendMailContext.remove("bodyUrl"); Map<String, Object> bodyUrlParameters = UtilGenerics.checkMap(sendMailContext.remove("bodyUrlParameters")); Locale locale = (Locale) rcontext.get("locale"); LocalDispatcher dispatcher = ctx.getDispatcher(); URL url = null; try { url = new URL(bodyUrl); } catch (MalformedURLException e) { Debug.logWarning(e, module); return ServiceUtil.returnError( UtilProperties.getMessage( resource, "CommonEmailSendMalformedUrl", UtilMisc.toMap("bodyUrl", bodyUrl, "errorString", e.toString()), locale)); } HttpClient httpClient = new HttpClient(url, bodyUrlParameters); String body = null; try { body = httpClient.post(); } catch (HttpClientException e) { Debug.logWarning(e, module); return ServiceUtil.returnError( UtilProperties.getMessage( resource, "CommonEmailSendGettingError", UtilMisc.toMap("errorString", e.toString()), locale)); } sendMailContext.put("body", body); Map<String, Object> sendMailResult; try { sendMailResult = dispatcher.runSync("sendMail", sendMailContext); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } // just return the same result; it contains all necessary information return sendMailResult; }
/** * Processes the request and returns an AuthorizeResponse. This service causes a * GenericServiceException if there is a fatal confguration error that must be addressed. */ private static AuthorizeResponse processRequest(Map request, String resource) throws GenericServiceException { boolean testMode = isTestMode(resource); String url = UtilProperties.getPropertyValue(resource, "payment.authorizedotnet.url"); if (UtilValidate.isEmpty(url)) { throw new GenericServiceException( "Authorize.NET transaction URL not configured. Please ensure payment.authorizedotnet.test is defined in " + resource); } Debug.logInfo("Sending eCheck.NET request type " + request.get("x_type"), module); if (testMode) { Debug.logInfo("Request URL: " + url, module); Debug.logInfo("Request Map: " + request, module); } // post the request to the url String responseString = null; try { HttpClient client = new HttpClient(url, request); client.setClientCertificateAlias("AUTHORIZE_NET"); responseString = client.post(); } catch (HttpClientException e) { Debug.logError( e, "Failed to send eCheck.NET request due to client exception: " + e.getMessage(), module); return null; } if (testMode) { Debug.logInfo("Response from eCheck.NET: " + responseString, module); } return new AuthorizeResponse(responseString); }