]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java
Please cherry-pick:
[addressbook-mailer-ejb.git] / src / java / org / mxchange / addressbook / mailer / model / delivery / AddressbookEmailDeliveryMessageBean.java
index e844ef45259916ecb926e727b27e23105a3c031d..31b6e0ab319c69b6d348e6bec471ee7459de1b6c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -18,97 +18,57 @@ 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.EJB;
+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 javax.naming.NamingException;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
 
 /**
- * A message-driven bean for sending out emails
+ * A message-driven bean for sending out mails
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<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 {
+@MessageDriven (
+               name = "addressbookEmailDelivery",
+               description = "A message bean for email delivery",
+               activationConfig = {
+                       @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/addressbook-email-queue"),
+                       @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
+               })
+public class AddressbookEmailDeliveryMessageBean extends BaseDatabaseBean 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;
+       @EJB
+       private DeliverableAddressbookEmailLocal mailerBean;
 
        /**
         * Default constructor
+        * <p>
+        * @throws javax.naming.NamingException If a JNDI name could not be found
         */
-       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
+       public AddressbookEmailDeliveryMessageBean () throws NamingException {
+               // Call super constructor
+               super();
        }
 
        @Override
        public void onMessage (final Message message) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
 
                // The parameter should be valid
                if (null == message) {
@@ -135,7 +95,7 @@ public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabase
                }
 
                // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N
 
                // Okay, is it the right interface?
                if (null == serializable) {
@@ -153,9 +113,9 @@ public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabase
                if (wrapper.getLocale() == null) {
                        // Throw NPE
                        throw new NullPointerException("wrapper.locale is null"); //NOI18N
-               } else if (wrapper.getRecipient() == null) {
+               } else if (wrapper.getRecipientAddress() == null) {
                        // Throw again ...
-                       throw new NullPointerException("wrapper.recipient is null"); //NOI18N
+                       throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N
                } else if (wrapper.getSubjectLine() == null) {
                        // ... and again
                        throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N
@@ -172,7 +132,7 @@ public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabase
 
                try {
                        // Send email out
-                       this.mailer.sendDeliverableMail(wrapper);
+                       this.mailerBean.sendDeliverableMail(wrapper);
                } catch (final MessagingException ex) {
                        // Opps, something went wrong
                        this.getLoggerBeanLocal().logException(ex);
@@ -180,7 +140,7 @@ public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabase
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N
        }
 
 }