Example usage for org.apache.commons.lang3.exception ContextedException getMessage

List of usage examples for org.apache.commons.lang3.exception ContextedException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ContextedException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Provides the message explaining the exception, including the contextual data.

Usage

From source file:com.rodaxsoft.mailgun.message.tools.MailgunSender.java

/**
 * Sends the message/*from   w w  w  .  j  a va2 s. c o  m*/
 * @param cmd Command line args
 * @param er Email request object
 */
private static void sendMessage(CommandLine cmd, EmailRequest er) {
    //Set optional campaign
    if (cmd.hasOption(CAMPAIGN_ID_OPT)) {
        er = er.setCampaign(cmd.getOptionValue(CAMPAIGN_ID_OPT));
    }

    //Set optional test mode
    if (cmd.hasOption(TEST_MODE_OPT)) {
        final String value = cmd.getOptionValue(TEST_MODE_OPT);
        Boolean mode = new Boolean(value);
        er.setTestMode(mode);
    }

    //Set reply-to email address
    if (cmd.hasOption(REPLY_TO_EMAIL_ADDRESS_OPT)) {
        er = er.setReplyTo(cmd.getOptionValue(REPLY_TO_EMAIL_ADDRESS_OPT));
    }

    try {
        LOG.info("Sending message...");
        boolean success = MailgunManager.sendMessage(er);

        if (success) {
            LOG.info("Message sent successfully");
        } else {
            LOG.error("Failed to send message");
        }
    } catch (ContextedException e) {
        LOG.error(e.getMessage());
        LOG.debug("Mailgun Message Send Error", e);
    }
}

From source file:com.rodaxsoft.mailgun.message.tools.MailgunSender.java

/**
 * Sends a message to a mailing list (<code>-m</code> option) or 
 * single email address (<code>-e</code> option).
 * @param cmd Command line arguments//from  w w  w  . j av a  2 s  .  c  o  m
 * @param text Plain text email content
 * @param html HTML email content
 */
private static void sendMessageToEmailAddress(CommandLine cmd, String text, String html) {

    if (cmd.hasOption(MAILING_LIST_OPT) || cmd.hasOption(EMAIL_ADDRESS_OPT)) {
        final boolean isMailingList = cmd.hasOption(MAILING_LIST_OPT);
        final String toAddress = isMailingList ? cmd.getOptionValue(MAILING_LIST_OPT)
                : cmd.getOptionValue(EMAIL_ADDRESS_OPT);
        if (isMailingList) {

            try {
                validateMailingListAddress(toAddress);
            } catch (ContextedException e) {
                LOG.error(e.getMessage());
                LOG.debug("Mailgun Mailing List Error", e);
                System.exit(-1);
            }
        }
        //Build the email request object
        final EmailRequest er = makeEmailRequest(cmd, text, html, toAddress);
        LOG.trace(er);

        sendMessage(cmd, er);
    } else {
        final String msg = "Option value must be an email address or mailing list.";
        handleOmittedOptionError(cmd, msg);
    }
}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#getCampaign(String)}
 *//*  w w w.j  a  va 2s.  c o  m*/
@Test
public void testGetCampaign() {
    try {
        Campaign campaign = MailgunManager.getCampaign(sCampaignId);
        assertNotNull(campaign);
    } catch (ContextedException e) {
        LOG.error("Get Campaign Error", e);
        fail(e.getMessage());
    }
}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#getCampaignEvents(String)}
 *//*from   ww w. jav a  2s . c  o  m*/
@Test
public void testGetCampaignEvents() {
    try {
        List<Map<String, Object>> events;
        events = MailgunManager.getCampaignEvents(sCampaignId);

        assertNotNull(events);
    } catch (ContextedException e) {
        LOG.error("Campaign Events Error", e);
        fail(e.getMessage());
    }
}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#getMailingLists()}
 */// ww w .  j a v a 2  s.c o  m
@Test
public void testGetMailingLists() {

    try {
        //Fetch mailing lists
        Collection<ListInfo> lists = MailgunManager.getMailingLists();
        assertNotNull(lists);

    } catch (ContextedException e) {
        LOG.error("Mailing Lists Fetch Error", e);
        fail(e.getMessage());
    }

}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#deleteMailingListMember(String, String)}
 *///  w  w w .j  a  v a2 s.c o  m
@Test
public void testDeleteMailingListMember() {

    boolean success;
    try {
        //Add the list member first
        success = MailgunManager.addMailingListMember(sMailingListAddress, getListMemberRequest());

        success = MailgunManager.deleteMailingListMember(sMailingListAddress, LIST_MEMBER_ADDRESS);
        assertTrue(success);

    } catch (ContextedException e) {
        LOG.error("Delete List Member Error", e);
        fail(e.getMessage());
    }

}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#unsubscribeMailingListMember(String, String)}
 *//*w ww .j  a v a 2 s  .  c  o  m*/
@Test
public void testUnsubscribeMailingListMember() {

    boolean success;
    try {
        //Add the list member first
        success = MailgunManager.addMailingListMember(sMailingListAddress, getListMemberRequest());

        success = MailgunManager.unsubscribeMailingListMember(sMailingListAddress, LIST_MEMBER_ADDRESS);
        assertTrue(success);

    } catch (ContextedException e) {
        LOG.error("Unsubscribe List Member Error", e);
        fail(e.getMessage());
    }

}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#getMailingListMember(String, String)}
 *///from   w  ww.  j  a  v  a  2  s. c o m
@Test
public void testGetMailingListMemberWithoutVarsType() {

    try {

        ListMemberRequest request = getListMemberRequest();
        boolean success = MailgunManager.addMailingListMember(sMailingListAddress, request);
        assertTrue(success);

        ListMember member = MailgunManager.getMailingListMember(sMailingListAddress, LIST_MEMBER_ADDRESS);
        assertNotNull(member);

    } catch (ContextedException e) {
        LOG.error("Get Mailing List Member Error", e);
        fail(e.getMessage());
    }

}

From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java

/**
 * Tests {@link MailgunManager#updateMailingListMember(String, ListMemberRequest)}
 *//*from w w  w .jav  a2  s  .c  o  m*/
@Test
public void testUpdateMailingListMember() {
    try {

        ListMemberRequest request = getListMemberRequest();
        boolean success = MailgunManager.addMailingListMember(sMailingListAddress, request);
        assertTrue(success);

        //Change the name
        request.setName("John Updated");

        success = MailgunManager.updateMailingListMember(sMailingListAddress, request);
        assertTrue(success);

    } catch (ContextedException e) {
        LOG.error("Get Mailing List Member Error", e);
        fail(e.getMessage());
    }

}