]> git.mxchange.org Git - pizzaservice-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>
Fri, 20 May 2016 21:30:21 +0000 (23:30 +0200)
- Fixed mail delivery (opps)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/beans/resendlink/PizzaResendLinkSessionBean.java
src/java/org/mxchange/pizzaapplication/mailer/model/delivery/PizzaEmailDeliveryMessageBean.java

index cfb91e578de8ad1ab57791a4e3c86b6821a44731..bff70cc72459b33a96befda8250693916d37d679 100644 (file)
@@ -16,7 +16,6 @@
  */
 package org.mxchange.pizzaapplication.beans.resendlink;
 
-import de.chotime.landingpage.beans.resendlink.ResendLinkSessionBeanRemote;
 import java.text.MessageFormat;
 import java.util.Locale;
 import javax.ejb.EJBException;
index d6f17d4497e9c1f1664e79117742ff296a9c4ea0..9f445c321ef2f383cad7b3f971ac37b49966973b 100644 (file)
@@ -16,9 +16,6 @@
  */
 package org.mxchange.pizzaapplication.mailer.model.delivery;
 
-import de.chotime.landingpage.database.BaseLandingDatabaseBean;
-import de.chotime.landingpage.mailer.model.delivery.DeliverableLandingEmail;
-import de.chotime.landingpage.mailer.model.delivery.LandingMailer;
 import java.io.Serializable;
 import java.text.MessageFormat;
 import java.util.Properties;
@@ -30,6 +27,9 @@ import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageListener;
 import javax.jms.ObjectMessage;
+import javax.mail.MessagingException;
+import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
+import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
 /**
  * A message-driven bean for sending out emails
@@ -40,7 +40,7 @@ import javax.jms.ObjectMessage;
        @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
        @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
 })
-public class PizzaEmailDeliveryMessageBean extends BaseLandingDatabaseBean implements MessageListener {
+public class PizzaEmailDeliveryMessageBean extends BasePizzaDatabaseBean implements MessageListener {
 
        /**
         * Serial number
@@ -48,56 +48,21 @@ public class PizzaEmailDeliveryMessageBean extends BaseLandingDatabaseBean imple
        private static final long serialVersionUID = 75_638_176_619_024L;
 
        /**
-        * Mailer instance
+        * Configuration file
         */
-       private final DeliverableLandingEmail mailer;
+       private final String configFile = "org.mxchange.jmailer.config"; //NOI18N
 
        /**
-        * Configuration file
+        * Mailer instance
         */
-       private final String configFile = "org.mxchange.jmailer.config"; //NOI18N
+       private final DeliverablePizzaEmail mailer;
 
        /**
         * Default constructor
         */
        public PizzaEmailDeliveryMessageBean () {
                // Init mailer instance
-               this.mailer = new LandingMailer();
-       }
-
-       @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
+               this.mailer = new PizzaMailer();
        }
 
        /**
@@ -141,4 +106,82 @@ public class PizzaEmailDeliveryMessageBean extends BaseLandingDatabaseBean imple
                // 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
+       }
 }