2 * Copyright (C) 2016 Roland Haeder
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.addressbook.mailer.model.delivery;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import java.util.Properties;
22 import java.util.ResourceBundle;
23 import javax.annotation.PostConstruct;
24 import javax.ejb.ActivationConfigProperty;
25 import javax.ejb.MessageDriven;
26 import javax.jms.JMSException;
27 import javax.jms.Message;
28 import javax.jms.MessageListener;
29 import javax.jms.ObjectMessage;
30 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
33 * A message-driven bean for sending out emails
35 * @author Roland Haeder<roland@mxchange.org>
37 @MessageDriven (activationConfig = {
38 @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
39 @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
41 public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener {
46 private static final long serialVersionUID = 75_638_176_619_024L;
51 private final DeliverableAddressbookEmail mailer;
56 private final String configFile = "org.mxchange.jmailer.config"; //NOI18N
61 public EmailDeliveryMessageBean () {
62 // Init mailer instance
63 this.mailer = new AddressbookMailer();
67 public void onMessage (final Message message) {
69 this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
71 // The parameter should be valid
72 if (null == message) {
74 throw new NullPointerException("message is null"); //NOI18N
75 } else if (!(message instanceof ObjectMessage)) {
76 // Not implementing right interface
77 throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
81 ObjectMessage objectMessage = (ObjectMessage) message;
84 Serializable serializable;
87 // Get object from message
88 serializable = objectMessage.getObject();
89 } catch (final JMSException ex) {
90 // Log it and don't continue any further
91 this.getLoggerBeanLocal().logException(ex);
96 this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
99 this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
106 public void init () {
108 this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
110 // Try to load bundle
111 ResourceBundle bundle = ResourceBundle.getBundle(this.configFile);
114 this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: bundle={0}", bundle)); //NOI18N
116 // The bunble should be valid
117 if (null == bundle) {
119 throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N
123 Properties properties = new Properties();
125 // Is the bundle not empty?
126 if (!bundle.keySet().isEmpty()) {
128 for (final String key : bundle.keySet()) {
130 this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: key={0}", key)); //NOI18N
132 // Get string from bundle and set it in properties
133 properties.put(key, bundle.getString(key));
137 // Handle it over to the mailer
138 this.mailer.init(properties);
141 this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N