public JSONObject getWelcome() throws Exception { JSONObject result = new JSONObject(); result.put("ok", true); result.put("service", "mail"); if( null != mailDelivery && mailDelivery.isConfigured() ){ result.put("configured", true); } if( null != mailRecipients ){ int count = getRecipientsForDestination(null).size(); result.put("defaultRecipientCount", count); } return result; }
@Override public void init(ServletConfig config) throws ServletException { super.init(config); // Pick up configuration Object configurationObj = config.getServletContext().getAttribute(MailServletConfiguration.CONFIGURATION_KEY); if( null == configurationObj ) { throw new ServletException("Can not find configuration object"); } if( configurationObj instanceof MailServletConfiguration ){ configuration = (MailServletConfiguration)configurationObj; mailActions = new MailServiceActions( configuration.getAtlasName(), configuration.getMailDelivery(), configuration.getRecipients() ); MailMessageGenerator formEmailGenerator = configuration.getFormEmailGenerator(); if( null != formEmailGenerator ){ mailActions.setFormEmailGenerator(formEmailGenerator); } } else { throw new ServletException("Invalid class for configuration: "+configurationObj.getClass().getName()); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { List<String> paths = computeRequestPath(request); if( paths.size() < 1 ) { JSONObject result = mailActions.getWelcome(); sendJsonResponse(response, result); } else { throw new Exception("Unrecognized request"); } } catch (Exception e) { reportError(e, response); } }
JSONObject result = mailActions.sendFormEmail(destination, subject, contact, body);
JSONObject result = new JSONObject(); List<MailRecipient> recipients = getRecipientsForDestination(destination); if( recipients.size() < 1 ){ throw new Exception("Unable to send form e-mail because no recipients are set: "+destination);