]> git.mxchange.org Git - pizzaservice-mailer-ejb.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Wed, 18 May 2016 09:01:48 +0000 (11:01 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 21 May 2016 11:59:33 +0000 (13:59 +0200)
- Fixed mail delivery (opps)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java [deleted file]

diff --git a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java b/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java
new file mode 100644 (file)
index 0000000..e844ef4
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.mailer.model.delivery;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Properties;
+import java.util.ResourceBundle;
+import javax.annotation.PostConstruct;
+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
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@MessageDriven (activationConfig = {
+       @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
+       @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
+})
+public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 75_638_176_619_024L;
+
+       /**
+        * Configuration file
+        */
+       private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N
+
+       /**
+        * Mailer instance
+        */
+       private final DeliverableAddressbookEmail mailer;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookEmailDeliveryMessageBean () {
+               // Init mailer instance
+               this.mailer = new AddressbookMailer();
+       }
+
+       /**
+        * Post-construction
+        */
+       @PostConstruct
+       public void init () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
+
+               // Try to load bundle
+               ResourceBundle bundle = ResourceBundle.getBundle(this.configFile);
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: bundle={0}", bundle)); //NOI18N
+
+               // The bunble should be valid
+               if (null == bundle) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N
+               }
+
+               // Init Properties
+               Properties properties = new Properties();
+
+               // Is the bundle not empty?
+               if (!bundle.keySet().isEmpty()) {
+                       // Loop through all
+                       for (final String key : bundle.keySet()) {
+                               // Log debug message
+                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: key={0}", key)); //NOI18N
+
+                               // Get string from bundle and set it in properties
+                               properties.put(key, bundle.getString(key));
+                       }
+               }
+
+               // Handle it over to the mailer
+               this.mailer.init(properties);
+
+               // 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
+       }
+
+}
diff --git a/src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java b/src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java
deleted file mode 100644 (file)
index 1fead75..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.mailer.model.delivery;
-
-import java.io.Serializable;
-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 org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-
-/**
- * A message-driven bean for sending out emails
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@MessageDriven (activationConfig = {
-       @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
-       @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
-})
-public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 75_638_176_619_024L;
-
-       /**
-        * Mailer instance
-        */
-       private final DeliverableAddressbookEmail mailer;
-
-       /**
-        * Configuration file
-        */
-       private final String configFile = "org.mxchange.jmailer.config"; //NOI18N
-
-       /**
-        * Default constructor
-        */
-       public EmailDeliveryMessageBean () {
-               // 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
-        */
-       @PostConstruct
-       public void init () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
-
-               // Try to load bundle
-               ResourceBundle bundle = ResourceBundle.getBundle(this.configFile);
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: bundle={0}", bundle)); //NOI18N
-
-               // The bunble should be valid
-               if (null == bundle) {
-                       // Throw NPE
-                       throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N
-               }
-
-               // Init Properties
-               Properties properties = new Properties();
-
-               // Is the bundle not empty?
-               if (!bundle.keySet().isEmpty()) {
-                       // Loop through all
-                       for (final String key : bundle.keySet()) {
-                               // Log debug message
-                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: key={0}", key)); //NOI18N
-
-                               // Get string from bundle and set it in properties
-                               properties.put(key, bundle.getString(key));
-                       }
-               }
-
-               // Handle it over to the mailer
-               this.mailer.init(properties);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
-       }
-}