Example usage for org.springframework.mail MailException getMessage

List of usage examples for org.springframework.mail MailException getMessage

Introduction

In this page you can find the example usage for org.springframework.mail MailException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:edu.washington.iam.registry.ws.RelyingPartyController.java

@RequestMapping(value = "/rp/attr", method = RequestMethod.PUT)
public ModelAndView putRelyingPartyAttributes(@RequestParam(value = "id", required = true) String id,
        @RequestParam(value = "policyId", required = true) String policyId,
        @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in,
        HttpServletRequest request, HttpServletResponse response) {

    RPSession session = processRequestInfo(request, response, false);
    if (session == null)
        return (emptyMV());
    log.info("PUT update attrs for " + id + " in " + policyId);
    int status = 200;

    /**/*from   w  ww .  ja va 2  s.  c o  m*/
           if (session.isBrowser && !(paramXsrf!=null && paramXsrf.equals(session.xsrfCode))) {
               log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode);
               return emptyMV("invalid session (xsrf)");
           }
     **/

    ModelAndView mv = emptyMV("OK dokey");

    if (!session.isAdmin) {
        status = 401;
        mv.addObject("alert", "You are not permitted to update attriubtes.");
        response.setStatus(status);
        return mv;
    }

    Document doc = null;
    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        doc = builder.parse(in);
    } catch (Exception e) {
        log.info("parse error: " + e);
        status = 400;
        mv.addObject("alert", "The posted document was not valid:\n" + e);
    }
    if (doc != null) {
        try {
            filterPolicyManager.updateRelyingParty(policyId, doc);
            status = 200;
        } catch (FilterPolicyException e) {
            status = 400;
            mv.addObject("alert", "Update of the entity failed:" + e);
        }
    }

    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setTo(mailTo);
    String act = "updated";
    if (status == 201)
        act = "created";
    msg.setSubject("Service provider attributes " + act + " by " + session.remoteUser);
    msg.setText("User '" + session.remoteUser + "' " + act + " attributes for '" + id + "'.\nRequest status: "
            + status + "\n");
    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        log.error("sending mail: " + ex.getMessage());
    }

    response.setStatus(status);
    return mv;
}

From source file:edu.washington.iam.registry.ws.RelyingPartyController.java

@RequestMapping(value = "/rp/attrReq", method = RequestMethod.PUT)
public ModelAndView putRelyingPartyAttrReq(@RequestParam(value = "id", required = true) String id,
        InputStream in, HttpServletRequest request, HttpServletResponse response) {

    RPSession session = processRequestInfo(request, response, false);
    if (session == null)
        return (emptyMV());
    log.info("PUT request for: " + id);
    int status = 200;

    ModelAndView mv = emptyMV("OK dokey");

    try {//w ww .  j  a v  a2 s.  c o  m
        if (!userCanEdit(session, id)) {
            status = 401;
            mv.addObject("alert", "You are not an owner of that entity.");
        }
    } catch (DNSVerifyException e) {
        mv.addObject("alert", "Could not verify ownership:\n" + e.getCause());
        response.setStatus(500);
        return mv;
    }

    Document doc = null;
    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        doc = builder.parse(in);
    } catch (Exception e) {
        log.info("parse error: " + e);
        status = 400;
        mv.addObject("alert", "The posted document was not valid:\n" + e);
    }
    if (doc != null) {
        StringBuffer txt = new StringBuffer(
                "[ Assign to Identity and Access Management. ]\n\nEntity Id: " + id + "\n");
        txt.append("User:      " + session.remoteUser + "\n\nRequesting:\n");
        List<Element> attrs = XMLHelper.getElementsByName(doc.getDocumentElement(), "Add");
        log.debug(attrs.size() + " adds");
        for (int i = 0; i < attrs.size(); i++)
            txt.append("  Add new attribute: " + attrs.get(i).getAttribute("id") + "\n\n");
        attrs = XMLHelper.getElementsByName(doc.getDocumentElement(), "Drop");
        log.debug(attrs.size() + " drops");
        for (int i = 0; i < attrs.size(); i++)
            txt.append("  Drop existing attribute: " + attrs.get(i).getAttribute("id") + "\n\n");
        Element mele = XMLHelper.getElementByName(doc.getDocumentElement(), "Comments");
        if (mele != null)
            txt.append("\nComment:\n\n" + mele.getTextContent() + "\n\n");
        txt.append("Quick link:\n\n   " + spRegistryUrl + "#a" + id + "\n");

        SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
        /* production to RT system */
        msg.setTo(requestMailTo);
        msg.setSubject("IdP attribute request for " + id);
        msg.setFrom(session.remoteUser + "@uw.edu");
        msg.setText(txt.toString());
        try {
            this.mailSender.send(msg);
        } catch (MailException ex) {
            log.error("sending mail: " + ex.getMessage());
            status = 500;
        }

    }
    response.setStatus(status);
    return mv;
}

From source file:edu.washington.iam.registry.ws.RelyingPartyController.java

@RequestMapping(value = "/ws/metadata", method = RequestMethod.PUT)
public ModelAndView putRelyingParty(@RequestParam(value = "id", required = true) String id,
        @RequestParam(value = "mdid", required = true) String mdid, InputStream in, HttpServletRequest request,
        HttpServletResponse response) {//from w ww .j  av a  2s  .  c om

    RPSession session = processRequestInfo(request, response, false);
    if (session == null)
        return (emptyMV());
    log.info("API PUT update for: " + id);
    int status = 403;

    ModelAndView mv = basicModelAndView(session, "xml", "empty");

    String dns = dnsFromEntityId(id);
    for (int i = 0; i < session.altNames.size(); i++) {
        if (dns.equals(session.altNames.get(i))) {
            log.info("dns match found for " + dns);
            status = 200;
        }
    }
    if (status == 403) {
        mv.addObject("alert", "You are not an owner of that entity.");
        response.setStatus(status);
        return mv;
    }
    if (!rpManager.isMetadataEditable(mdid)) {
        status = 400;
        mv.addObject("alert", "The metadata was not found or is not editable");
        response.setStatus(status);
        return mv;
    }

    RelyingParty rp = null;
    try {
        Document doc = null;
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        doc = builder.parse(in);
        rp = new RelyingParty(doc.getDocumentElement(), mdid, rpManager.isMetadataEditable(mdid));
    } catch (Exception e) {
        log.info("parse error: " + e);
        status = 400;
        mv.addObject("alert", "The posted document was not valid:\n" + e);
        response.setStatus(status);
        return mv;
    }
    if (rp.getEntityId().equals(id)) {
        try {
            rpManager.updateRelyingParty(rp, mdid);
        } catch (RelyingPartyException e) {
            status = 400;
            mv.addObject("alert", "Update of the metadata failed:\n" + e);
        }
    } else {
        mv.addObject("alert", String.format("Id %s doesn't match %s", rp.getEntityId(), id));
    }

    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setTo(mailTo);
    String act = "updated";
    if (status == 201)
        act = "created";
    else if (status >= 400)
        act = "attempted edit of";
    msg.setSubject("Service provider metadata " + act + " by " + session.remoteUser);
    msg.setText("User '" + session.remoteUser + "' " + act + " metadata for '" + id + "'.\nRequest status: "
            + status + "\n\nThis message is advisory.  No response is indicated.");
    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        log.error("sending mail: " + ex.getMessage());
    }

    response.setStatus(status);
    return mv;
}

From source file:edu.washington.iam.registry.ws.RelyingPartyController.java

@RequestMapping(value = "/rp/proxy", method = RequestMethod.PUT)
public ModelAndView putRelyingPartyAttributesZ(@RequestParam(value = "id", required = true) String id,
        @RequestParam(value = "role", required = false) String role,
        @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in,
        HttpServletRequest request, HttpServletResponse response) {

    RPSession session = processRequestInfo(request, response, false);
    if (session == null)
        return (emptyMV());

    log.info("PUT update proxy for " + id);
    int status = 200;

    if (session.isBrowser && !(paramXsrf != null && paramXsrf.equals(session.xsrfCode))) {
        log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode);
        return emptyMV("invalid session (xsrf)");
    }/*w w w  . j  a  v a  2  s  . co m*/

    ModelAndView mv = emptyMV("OK dokey");
    try {
        if (!userCanEdit(session, id)) {
            status = 401;
            mv.addObject("alert", "You are not an owner of that entity.");
            response.setStatus(status);
            return mv;
        }
    } catch (DNSVerifyException e) {
        mv.addObject("alert", "Could not verify ownership:\n" + e.getCause());
        response.setStatus(500);
        return mv;
    }

    Document doc = null;
    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        doc = builder.parse(in);
    } catch (Exception e) {
        log.info("parse error: " + e);
        status = 400;
        mv.addObject("alert", "The posted document was not valid:\n" + e);
    }
    if (doc != null) {
        try {
            List<Element> eles = XMLHelper.getElementsByName(doc.getDocumentElement(), "Proxy");
            if (eles.size() != 1)
                throw new ProxyException("proxy xml must contain one element");
            Element pxe = eles.get(0);
            Proxy newproxy = new Proxy(pxe);
            if (!newproxy.getEntityId().equals(id))
                throw new ProxyException("post doesn't match qs id");
            proxyManager.updateProxy(newproxy);
            status = 200;
        } catch (ProxyException e) {
            status = 400;
            mv.addObject("alert", "Update of the entity failed:" + e);
        }
    }

    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setTo(mailTo);
    String act = "updated";
    if (status == 201)
        act = "created";
    msg.setSubject("Service provider proxy info " + act + " by " + session.remoteUser);
    msg.setText("User '" + session.remoteUser + "' " + act + " proxy info '" + id + "'.\nRequest status: "
            + status + "\n");
    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        log.error("sending mail: " + ex.getMessage());
    }

    response.setStatus(status);
    return mv;
}

From source file:edu.washington.iam.registry.ws.RelyingPartyController.java

@RequestMapping(value = "/rp", method = RequestMethod.PUT)
public ModelAndView putRelyingParty(@RequestParam(value = "id", required = true) String id,
        @RequestParam(value = "mdid", required = true) String mdid,
        @RequestParam(value = "role", required = false) String role,
        @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in,
        HttpServletRequest request, HttpServletResponse response) {

    RPSession session = processRequestInfo(request, response, false);
    if (session == null)
        return (emptyMV());

    log.info("PUT update for: " + id);
    int status = 200;

    if (session.isBrowser && !(paramXsrf != null && paramXsrf.equals(session.xsrfCode))) {
        log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode);
        return emptyMV("invalid session (xsrf)");
    }/* w w w.j a va2s  .com*/

    ModelAndView mv = emptyMV("OK dokey");

    try {
        if (!userCanEdit(session, id)) {
            status = 401;
            mv.addObject("alert", "You are not an owner of that entity.");
            response.setStatus(status);
            return mv;
        }
    } catch (DNSVerifyException e) {
        mv.addObject("alert", "Could not verify ownership:\n" + e.getCause());
        response.setStatus(500);
        return mv;
    }

    RelyingParty relyingParty = null;
    try {
        Document doc = null;
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        doc = builder.parse(in);
        relyingParty = new RelyingParty(doc.getDocumentElement(), mdid, rpManager.isMetadataEditable(mdid));
    } catch (Exception e) {
        log.info("parse error: " + e);
        status = 400;
        mv.addObject("alert", "The posted document was not valid:\n" + e);
        response.setStatus(status);
        return mv;
    }

    try {
        status = rpManager.updateRelyingParty(relyingParty, mdid);
    } catch (RelyingPartyException e) {
        status = 400;
        mv.addObject("alert", "Update failed:\n" + e.getMessage());
        response.setStatus(status);
        return mv;
    }

    SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
    msg.setTo(mailTo);
    String act = "updated";
    if (status == 201)
        act = "created";
    else if (status >= 400)
        act = "attempted edit of";
    msg.setSubject("Service provider metadata " + act + " by " + session.remoteUser);
    msg.setText("User '" + session.remoteUser + "' " + act + " metadata for '" + id + "'.\nRequest status: "
            + status + "\n\nThis message is advisory.  No response is indicated.");
    try {
        this.mailSender.send(msg);
    } catch (MailException ex) {
        log.error("sending mail: " + ex.getMessage());
    }

    response.setStatus(status);
    return mv;
}

From source file:net.malariagen.alfresco.action.CustomMailAction.java

/**
 * Send a test message//from ww w. ja  v a  2  s .  co  m
 * 
 * @return true, message sent
 * @throws AlfrescoRuntimeException
 */
public boolean sendTestMessage() {
    if (testMessageTo == null || testMessageTo.length() == 0) {
        throw new AlfrescoRuntimeException("email.outbound.err.test.no.to");
    }
    if (testMessageSubject == null || testMessageSubject.length() == 0) {
        throw new AlfrescoRuntimeException("email.outbound.err.test.no.subject");
    }
    if (testMessageText == null || testMessageText.length() == 0) {
        throw new AlfrescoRuntimeException("email.outbound.err.test.no.text");
    }
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put(PARAM_TO, testMessageTo);
    params.put(PARAM_SUBJECT, testMessageSubject);
    params.put(PARAM_TEXT, testMessageText);

    Action ruleAction = serviceRegistry.getActionService().createAction(NAME, params);

    MimeMessageHelper message = prepareEmail(ruleAction, null,
            new Pair<String, Locale>(testMessageTo, getLocaleForUser(testMessageTo)), getFrom(ruleAction));
    try {
        mailService.send(message.getMimeMessage());
        onSend();
    } catch (MailException me) {
        onFail();
        StringBuffer txt = new StringBuffer();

        txt.append(me.getClass().getName() + ", " + me.getMessage());

        Throwable cause = me.getCause();
        while (cause != null) {
            txt.append(", ");
            txt.append(cause.getClass().getName() + ", " + cause.getMessage());
            cause = cause.getCause();
        }

        Object[] args = { testMessageTo, txt.toString() };
        throw new AlfrescoRuntimeException("email.outbound.err.send.failed", args, me);
    }

    return true;
}

From source file:cz.zcu.kiv.eegdatabase.data.service.SpringJavaMailService.java

@Override
public void sendNotification(String email, Article article, Locale locale) {

    try {// w ww  .ja  v a 2  s .  c o m
        String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + article.getArticleId();
        // System.out.println(articleURL);
        String subject = messageSource.getMessage("articles.group.email.subscribtion.subject",
                new String[] { article.getTitle(), article.getPerson().getUsername() }, locale);
        // System.out.println(subject);
        String emailBody = "<html><body>";

        emailBody += "<p>" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part1",
                new String[] { article.getTitle(),
                        article.getResearchGroup() != null ? article.getResearchGroup().getTitle()
                                : "Public articles" },
                locale) + "";
        emailBody += "&nbsp;(<a href=\"" + articleURL + "\" target=\"_blank\">" + articleURL
                + "</a>)</p><br />";
        emailBody += "<h3>" + article.getTitle() + "</h3> <p>" + article.getText() + "</p><br />";
        emailBody += "<p>"
                + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part2", null, locale)
                + "</p>";
        emailBody += "</body></html>";

        // System.out.println(emailBody);
        log.debug("email body: " + emailBody);

        log.debug("Composing e-mail message");
        MimeMessage mimeMessage = mailSender.createMimeMessage();

        MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
        message.setFrom(mailMessage.getFrom());

        // message.setContent("text/html");
        message.setTo(email);
        // helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request)));
        message.setSubject(subject);
        message.setText(emailBody, true);

        log.debug("Sending e-mail" + message);
        log.debug("mailSender" + mailSender);
        mailSender.send(mimeMessage);
        log.debug("E-mail was sent");

    } catch (MailException e) {
        log.error("E-mail for subscribers was NOT sent");
        log.error(e.getMessage(), e);
    } catch (MessagingException e) {
        log.error("E-mail for subscribers was NOT sent");
        log.error(e.getMessage(), e);
    }
}

From source file:cz.zcu.kiv.eegdatabase.data.service.SpringJavaMailService.java

@Override
public void sendNotification(String email, ArticleComment comment, Locale locale) throws MailException {

    try {/*from w  w w  .j a  v a2s . c o  m*/
        String articleURL = "http://" + domain + "/articles/detail.html?articleId="
                + comment.getArticle().getArticleId();
        //System.out.println(articleURL);
        String subject = messageSource.getMessage("articles.comments.email.subscribtion.subject",
                new String[] { comment.getArticle().getTitle(), comment.getPerson().getUsername() }, locale);
        //System.out.println(subject);
        String emailBody = "<html><body>";

        emailBody += "<p>" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part1",
                new String[] { comment.getArticle().getTitle() }, locale) + "";
        emailBody += "&nbsp;(<a href=\"" + articleURL + "\" target=\"_blank\">" + articleURL
                + "</a>)</p><br />";
        emailBody += "<h3>Text:</h3> <p>" + comment.getText() + "</p><br />";
        emailBody += "<p>"
                + messageSource.getMessage("articles.group.email.subscribtion.body.text.part2", null, locale)
                + "</p>";
        emailBody += "</body></html>";

        //System.out.println(emailBody);
        log.debug("email body: " + emailBody);

        log.debug("Composing e-mail message");
        MimeMessage mimeMessage = mailSender.createMimeMessage();

        MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
        message.setFrom(mailMessage.getFrom());

        //  message.setContent("text/html");
        message.setTo(email);
        //helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request)));
        message.setSubject(subject);
        message.setText(emailBody, true);

        log.debug("Sending e-mail" + message);
        log.debug("mailSender" + mailSender);
        mailSender.send(mimeMessage);
        log.debug("E-mail was sent");
    } catch (MailException e) {
        log.error("E-mail for subscribers was NOT sent");
        log.error(e.getMessage(), e);
    } catch (MessagingException e) {
        log.error("E-mail for subscribers was NOT sent");
        log.error(e.getMessage(), e);
    }
}

From source file:cz.zcu.kiv.eegdatabase.data.service.SpringJavaMailService.java

private boolean sendEmail(String from, String to, String subject, String emailBody) throws MailException {// make
                                                                                                          // public
                                                                                                          // if
                                                                                                          // needed
    try {/*w ww. j a va2 s . c om*/
        log.debug("email body: " + emailBody);
        log.debug("Composing e-mail message");
        MimeMessage mimeMessage = createMimeMessage(from, to, subject, emailBody);
        log.debug("MailSender " + mailSender + " sending email");
        mailSender.send(mimeMessage);
        log.debug("E-mail was sent");
        return true;
    } catch (MailException e) {
        log.error(e.getMessage(), e);
        throw new MailSendException(e.getMessage(), e);
    }
}

From source file:gov.nih.nci.cabig.caaers.domain.repository.InvestigatorRepositoryImpl.java

/**
 * Save remote investigators./*w w  w .  j  a  va2  s  .  com*/
 *
 * @param remoteList the remote list
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, noRollbackFor = MailException.class)
private void saveRemoteInvestigators(List<Investigator> remoteList) {
    for (Investigator remoteInvestigator : remoteList) {

        Investigator inv = investigatorDao.getByExternalId(remoteInvestigator.getExternalId());
        if (inv == null) {
            try {
                List<SiteInvestigator> siList = remoteInvestigator.getSiteInvestigators();
                List<SiteInvestigator> siDBList = new ArrayList<SiteInvestigator>();
                for (SiteInvestigator si : siList) {
                    Organization remoteOrganization = si.getOrganization();
                    Organization organization = organizationDao
                            .getByNCIcode(remoteOrganization.getNciInstituteCode());
                    if (organization == null) {
                        organizationRepository.create(remoteOrganization);
                        organization = organizationDao.getByNCIcode(remoteOrganization.getNciInstituteCode());
                    }
                    SiteInvestigator dbSI = new SiteInvestigator();
                    dbSI.setOrganization(organization);
                    dbSI.setStartDate(DateUtils.today());
                    dbSI.setInvestigator(remoteInvestigator);
                    siDBList.add(dbSI);

                }
                remoteInvestigator.getSiteInvestigators().clear();
                remoteInvestigator.setSiteInvestigators(siDBList);

                save(remoteInvestigator, "URL");
                remoteInvestigator = investigatorDao.getByExternalId(remoteInvestigator.getExternalId());
            } catch (MailException e) {
                logger.error("Mail send exception --" + e.getMessage());
            }
        } else {
            try {
                List<SiteInvestigator> siList = remoteInvestigator.getSiteInvestigators();
                for (SiteInvestigator si : siList) {
                    Organization remoteOrganization = si.getOrganization();
                    Organization organization = organizationDao
                            .getByNCIcode(remoteOrganization.getNciInstituteCode());
                    if (organization == null) {
                        organizationRepository.create(remoteOrganization);
                        organization = organizationDao.getByNCIcode(remoteOrganization.getNciInstituteCode());
                    }
                    SiteInvestigator siteInvestigator = new SiteInvestigator();
                    siteInvestigator.setOrganization(organization);
                    siteInvestigator.setStartDate(DateUtils.today());
                    siteInvestigator.setInvestigator(remoteInvestigator);
                    List<SiteInvestigator> siDBList = inv.getSiteInvestigators();
                    boolean exists = false;
                    for (SiteInvestigator sid : siDBList) {
                        if (sid.getOrganization().getNciInstituteCode()
                                .equals(organization.getNciInstituteCode())) {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists) {
                        inv.addSiteInvestigator(siteInvestigator);
                    }
                }
                save(inv, "URL");
            } catch (MailException e) {
                logger.error("Mail send exception --" + e.getMessage());
            }
        }
    }

    eventFactory.publishEntityModifiedEvent(new LocalInvestigator(), false);

}