2 * Copyright (C) 2016 - 2024 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.mailer.model.delivery;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import javax.ejb.ActivationConfigProperty;
23 import javax.ejb.MessageDriven;
24 import javax.jms.JMSException;
25 import javax.jms.Message;
26 import javax.jms.MessageListener;
27 import javax.jms.ObjectMessage;
28 import javax.mail.MessagingException;
29 import javax.naming.NamingException;
30 import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean;
31 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
34 * A message-driven bean for sending out mails
36 * @author Roland Häder<roland@mxchange.org>
39 name = "jjobsEmailDelivery",
40 description = "A message bean for email delivery",
42 @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jjobs-email-queue"),
43 @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
45 public class JobsEmailDeliveryMessageBean extends BaseEnterpriseBean implements MessageListener {
50 private static final long serialVersionUID = 75_638_176_619_024L;
56 private DeliverableJobsEmailRemote mailerBean;
61 * @throws javax.naming.NamingException If a JNDI name could not be found
63 public JobsEmailDeliveryMessageBean () throws NamingException {
64 // Call super constructor
69 public void onMessage (final Message message) {
71 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
73 // The parameter should be valid
74 if (null == message) {
76 throw new NullPointerException("message is null"); //NOI18N
77 } else if (!(message instanceof ObjectMessage)) {
78 // Not implementing right interface
79 throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
83 final ObjectMessage objectMessage = (ObjectMessage) message;
86 final Serializable serializable;
89 // Get object from message
90 serializable = objectMessage.getObject();
91 } catch (final JMSException ex) {
92 // Log it and don't continue any further
93 this.getLoggerBeanLocal().logException(ex);
98 this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N
100 // Okay, is it the right interface?
101 if (null == serializable) {
103 throw new NullPointerException("serializable is null"); //NOI18N
104 } else if (!(serializable instanceof WrapableEmailDelivery)) {
105 // Not correct object send
106 throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N
110 final WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable;
112 // Is all required set?
113 if (wrapper.getLocale() == null) {
115 throw new NullPointerException("wrapper.locale is null"); //NOI18N
116 } else if (wrapper.getRecipientAddress() == null) {
118 throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N
119 } else if (wrapper.getSubjectLine() == null) {
121 throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N
122 } else if (wrapper.getSubjectLine().isEmpty()) {
124 throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N
125 } else if (wrapper.getTemplateName() == null) {
127 throw new NullPointerException("wrapper.templateName is null"); //NOI18N
128 } else if (wrapper.getTemplateName().isEmpty()) {
130 throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N
135 this.mailerBean.sendDeliverableMail(wrapper);
136 } catch (final MessagingException ex) {
137 // Opps, something went wrong
138 this.getLoggerBeanLocal().logException(ex);
143 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N