/** * 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); }