]> git.mxchange.org Git - jmailer-ee.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 23 Jul 2017 08:36:02 +0000 (10:36 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 23 Jul 2017 08:56:20 +0000 (10:56 +0200)
- let BaseDatabaseBean initialize the logger for us
- added sender email address which is taken from property "mailer.from"
- new dependency 'jcoree' added

Signed-off-by: Roland Häder <roland@mxchange.org>
nbproject/project.properties
src/org/mxchange/jmailee/model/delivery/BaseMailerBean.java
src/org/mxchange/jmailee/model/delivery/wrapper/WrapableEmailDelivery.java

index 93ff525a11562e86c24ef6cdcba9c3a028c17d1d..d1bf3a83ec790eb1740a6f129337c67bb57f45b4 100644 (file)
@@ -31,6 +31,7 @@ endorsed.classpath=
 excludes=
 file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
 file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
+file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.juser-core.jar=lib/juser-core.jar
 includes=**
 jar.archive.disabled=${jnlp.enabled}
@@ -40,6 +41,7 @@ javac.classpath=\
     ${file.reference.juser-core.jar}:\
     ${file.reference.jcontacts-core.jar}:\
     ${file.reference.jcore-logger-lib.jar}:\
+    ${file.reference.jcoreee.jar}:\
     ${libs.Apache_Velocity_1.7.classpath}:\
     ${libs.javaee-api-7.0.classpath}
 # Space-separated list of extra javac options
@@ -100,6 +102,7 @@ run.test.classpath=\
 source.encoding=UTF-8
 source.reference.jcontacts-core.jar=../jcontacts-core/src/
 source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
+source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.juser-core.jar=../juser-core/src/
 src.dir=src
 test.src.dir=test
index b77b97b4a03ae6470a148190e5a490629ad41c66..5fb6303efa5313a14b4b27cc0629563f6d524cff 100644 (file)
@@ -20,21 +20,19 @@ import java.io.StringWriter;
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Properties;
+import javax.mail.Address;
+import javax.mail.Message;
 import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-import org.mxchange.jcoreeelogger.beans.local.logger.Log;
-import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
 
 /**
@@ -42,19 +40,13 @@ import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public abstract class BaseMailerBean implements DeliverableEmailLocal {
+public abstract class BaseMailerBean extends BaseDatabaseBean implements DeliverableEmailLocal {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 14_598_912_753_106L;
 
-       /**
-        * Logger bean
-        */
-       @Log
-       private LoggerBeanLocal loggerBeanLocal;
-
        /**
         * Properties for this mailer
         * <p>
@@ -74,16 +66,8 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
         * Default constructor
         */
        protected BaseMailerBean () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Lookup logger
-                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-               }
+               // Call super constructor
+               super();
 
                // Init template engine
                this.templateEngine = new VelocityEngine();
@@ -104,12 +88,15 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
         */
        private void deliverMail (final WrapableEmailDelivery emailWrapper, final StringWriter writer, final Session mailSession) throws MessagingException {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailWrapper={0},body={1},mailSession={2} - CALLED!", emailWrapper, writer, mailSession)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("deliverMail: emailWrapper={0},body={1},mailSession={2} - CALLED!", emailWrapper, writer, mailSession)); //NOI18N
 
                // Are the additional properties and all parameter set?
                if (null == this.properties) {
                        // Nothing set
                        throw new NullPointerException("this.properties is null"); //NOI18N
+               } else if (!this.properties.containsKey("mailer.from")) { //NOI18N
+                       // Throw exception
+                       throw new IllegalStateException("this.properties.mailer.from is not set"); //NOI18N
                } else if (null == emailWrapper) {
                        // Throw NPE
                        throw new NullPointerException("emailWrapper is null"); //NOI18N
@@ -118,7 +105,7 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
                        throw new NullPointerException("emailWrapper.locale is null"); //NOI18N
                } else if (emailWrapper.getRecipientAddress() == null) {
                        // Throw it again
-                       throw new NullPointerException("emailWrapper.recipient is null"); //NOI18N
+                       throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N
                } else if (emailWrapper.getTemplateName() == null) {
                        // Throw it again
                        throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N
@@ -145,12 +132,16 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
                        throw new NullPointerException("mailSession is null"); //NOI18N
                }
 
+               // Parse from address
+               Address senderAddress = new InternetAddress(this.properties.getProperty("mailer.from"));
+
                // Get MIME message instance
                MimeMessage message = new MimeMessage(mailSession);
 
                // Set subject, recipients and body
+               message.setFrom(senderAddress);
                message.setSubject(emailWrapper.getSubjectLine());
-               message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailWrapper.getRecipientAddress().toString(), true));
+               message.setRecipient(Message.RecipientType.TO, emailWrapper.getRecipientAddress());
                message.setSentDate(new Date());
                message.setText(writer.toString());
                message.setHeader("MIME-Version", "1.0"); //NOI18N
@@ -179,7 +170,7 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
                Transport.send(message);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("deliverMail: EXIT!"); //NOI18N
        }
 
        /**
@@ -194,7 +185,7 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
         */
        protected void deliverMailWithTemplate (final Template template, final VelocityContext context, final WrapableEmailDelivery emailWrapper, final Session mailSession) throws MessagingException {
                // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMailTemplate: template={0},emailWrapper={1},mailSession={2} - CALLED!", template, emailWrapper, mailSession)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("deliverMailWithTemplate: template={0},emailWrapper={1},mailSession={2} - CALLED!", template, emailWrapper, mailSession)); //NOI18N
 
                // The parameters must be valid
                if (null == template) {
@@ -208,7 +199,7 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
                        throw new NullPointerException("emailWrapper.locale is null"); //NOI18N
                } else if (emailWrapper.getRecipientAddress() == null) {
                        // Throw it again
-                       throw new NullPointerException("emailWrapper.recipient is null"); //NOI18N
+                       throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N
                } else if (emailWrapper.getTemplateName() == null) {
                        // Throw it again
                        throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N
@@ -239,16 +230,7 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
                this.deliverMail(emailWrapper, writer, mailSession);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
-       }
-
-       /**
-        * Getter for logger bean
-        * <p>
-        * @return Local logger bean
-        */
-       protected LoggerBeanLocal getLoggerBeanLocal () {
-               return this.loggerBeanLocal;
+               this.getLoggerBeanLocal().logTrace("deliverMailWithTemplate: EXIT!"); //NOI18N
        }
 
        /**
@@ -265,11 +247,14 @@ public abstract class BaseMailerBean implements DeliverableEmailLocal {
                if (null == properties) {
                        // Is null
                        throw new NullPointerException("properties is null"); //NOI18N
+               } else if (!properties.containsKey("mailer.from")) { //NOI18N
+                       // From not set
+                       throw new IllegalArgumentException("properties.mailer.from is not set"); //NOI18N
                } else if (!properties.containsKey("mailer.errorsto")) { //NOI18N
                        // Errors-To not set
                        throw new IllegalArgumentException("properties.mailer.errorsto is not set"); //NOI18N
                } else if (!properties.containsKey("mailer.bouncesto")) { //NOI18N
-                       // Errors-To not set
+                       // Bounces-To not set
                        throw new IllegalArgumentException("properties.mailer.bouncesto is not set"); //NOI18N
                }
 
index ef1e6c0107fb901efadc3b3bdacca43f1c493af3..7f501f1df1a3d31bd518e37859eeb6849f82ef68 100644 (file)
@@ -52,9 +52,9 @@ public interface WrapableEmailDelivery extends Serializable {
        /**
         * Setter for recipient email address
         * <p>
-        * @param recipient Email address recipient
+        * @param recipientAddress Email address recipient
         */
-       void setRecipientAddress (final Address recipient);
+       void setRecipientAddress (final Address recipientAddress);
 
        /**
         * Getter for optional properties