From a426d451765091f7d10a7248db49edb12ff56e22 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 18 May 2016 11:01:48 +0200 Subject: [PATCH] Continued a bit: - Fixed mail delivery (opps) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ... AddressbookEmailDeliveryMessageBean.java} | 131 ++++++++++++------ 1 file changed, 87 insertions(+), 44 deletions(-) rename src/java/org/mxchange/addressbook/mailer/model/delivery/{EmailDeliveryMessageBean.java => AddressbookEmailDeliveryMessageBean.java} (69%) diff --git a/src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java b/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java similarity index 69% rename from src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java rename to src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java index 1fead75..e844ef4 100644 --- a/src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java +++ b/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java @@ -21,13 +21,13 @@ import java.text.MessageFormat; import java.util.Properties; import java.util.ResourceBundle; import javax.annotation.PostConstruct; -import javax.ejb.ActivationConfigProperty; -import javax.ejb.MessageDriven; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; +import javax.mail.MessagingException; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; /** * A message-driven bean for sending out emails @@ -38,7 +38,7 @@ import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"), @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") }) -public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener { +public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener { /** * Serial number @@ -46,59 +46,23 @@ public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implem private static final long serialVersionUID = 75_638_176_619_024L; /** - * Mailer instance + * Configuration file */ - private final DeliverableAddressbookEmail mailer; + private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N /** - * Configuration file + * Mailer instance */ - private final String configFile = "org.mxchange.jmailer.config"; //NOI18N + private final DeliverableAddressbookEmail mailer; /** * Default constructor */ - public EmailDeliveryMessageBean () { + public AddressbookEmailDeliveryMessageBean () { // Init mailer instance this.mailer = new AddressbookMailer(); } - @Override - public void onMessage (final Message message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N - - // The parameter should be valid - if (null == message) { - // Throw NPE - throw new NullPointerException("message is null"); //NOI18N - } else if (!(message instanceof ObjectMessage)) { - // Not implementing right interface - throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N - } - - // Securely cast it - ObjectMessage objectMessage = (ObjectMessage) message; - - // Init variable - Serializable serializable; - - try { - // Get object from message - serializable = objectMessage.getObject(); - } catch (final JMSException ex) { - // Log it and don't continue any further - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N - } - /** * Post-construction */ @@ -140,4 +104,83 @@ public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implem // Trace message this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N } + + @Override + public void onMessage (final Message message) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N + + // The parameter should be valid + if (null == message) { + // Throw NPE + throw new NullPointerException("message is null"); //NOI18N + } else if (!(message instanceof ObjectMessage)) { + // Not implementing right interface + throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N + } + + // Securely cast it + ObjectMessage objectMessage = (ObjectMessage) message; + + // Init variable + Serializable serializable; + + try { + // Get object from message + serializable = objectMessage.getObject(); + } catch (final JMSException ex) { + // Log it and don't continue any further + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N + + // Okay, is it the right interface? + if (null == serializable) { + // Throw NPE + throw new NullPointerException("serializable is null"); //NOI18N + } else if (!(serializable instanceof WrapableEmailDelivery)) { + // Not correct object send + throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N + } + + // Securely cast it + WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable; + + // Is all required set? + if (wrapper.getLocale() == null) { + // Throw NPE + throw new NullPointerException("wrapper.locale is null"); //NOI18N + } else if (wrapper.getRecipient() == null) { + // Throw again ... + throw new NullPointerException("wrapper.recipient is null"); //NOI18N + } else if (wrapper.getSubjectLine() == null) { + // ... and again + throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N + } else if (wrapper.getSubjectLine().isEmpty()) { + // Is empty + throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N + } else if (wrapper.getTemplateName() == null) { + // Throw NPE again + throw new NullPointerException("wrapper.templateName is null"); //NOI18N + } else if (wrapper.getTemplateName().isEmpty()) { + // Is empty + throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N + } + + try { + // Send email out + this.mailer.sendDeliverableMail(wrapper); + } catch (final MessagingException ex) { + // Opps, something went wrong + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Trace message + this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N + } + } -- 2.39.5