]> git.mxchange.org Git - jjobs-mailer-lib.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2017 22:21:31 +0000 (00:21 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 7 Jul 2017 22:40:49 +0000 (00:40 +0200)
- @Resource is not working in any unmanaged classes (like ordinary classes are)
- so let's try it with the annotation-free JNDI lookup over InitialContext
- the constructor may throw now a NamingException if the JNDI lookup failed
- please note, the short name is now generally "smtpSession"

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/addressbook/mailer/model/delivery/AddressbookMailer.java

index e0e9a5b42e7bfcaa6a99424484467d9d0ef6ed2d..f30868943af9a62f6477a6ec3ae0087fcbf64eb0 100644 (file)
@@ -18,9 +18,11 @@ package org.mxchange.addressbook.mailer.model.delivery;
 
 import java.text.MessageFormat;
 import java.util.Map;
-import javax.annotation.Resource;
 import javax.mail.MessagingException;
 import javax.mail.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.mxchange.jmailee.model.delivery.BaseMailer;
@@ -41,8 +43,20 @@ public class AddressbookMailer extends BaseMailer implements DeliverableAddressb
        /**
         * Email session
         */
-       @Resource (name = "jmail/addressbook", description = "A JavaMail resource")
-       private Session mailSession;
+       private final Session mailSession;
+
+       /**
+        * Default constructor
+        * <p>
+        * @throws javax.naming.NamingException If the JNDI name is not found
+        */
+       public AddressbookMailer () throws NamingException {
+               // Get initial context
+               Context context = new InitialContext();
+
+               // Try to lookup
+               this.mailSession = (Session) context.lookup("java:global/jfinancials-mailer/smtpSession"); //NOI18N
+       }
 
        @Override
        public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException {
@@ -53,9 +67,9 @@ public class AddressbookMailer extends BaseMailer implements DeliverableAddressb
                if (null == emailWrapper) {
                        // Throw NPE
                        throw new NullPointerException("emailWrapper is null"); //NOI18N
-               } else if (emailWrapper.getRecipient() == null) {
+               } else if (emailWrapper.getRecipientAddress() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("emailWrapper.recipient is null"); //NOI18N
+                       throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N
                } else if (emailWrapper.getSubjectLine() == null) {
                        // ... and again
                        throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N