2 * Copyright (C) 2016 Cho-Time GmbH
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.pizzaapplication.mailer.model.delivery;
19 import de.chotime.landingpage.database.BaseLandingDatabaseBean;
20 import de.chotime.landingpage.mailer.model.delivery.DeliverableLandingEmail;
21 import de.chotime.landingpage.mailer.model.delivery.LandingMailer;
22 import java.io.Serializable;
23 import java.text.MessageFormat;
24 import java.util.Properties;
25 import java.util.ResourceBundle;
26 import javax.annotation.PostConstruct;
27 import javax.ejb.ActivationConfigProperty;
28 import javax.ejb.MessageDriven;
29 import javax.jms.JMSException;
30 import javax.jms.Message;
31 import javax.jms.MessageListener;
32 import javax.jms.ObjectMessage;
35 * A message-driven bean for sending out emails
37 * @author Roland Haeder<rhaeder@cho-time.de>
39 @MessageDriven (activationConfig = {
40 @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
41 @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
43 public class PizzaEmailDeliveryMessageBean extends BaseLandingDatabaseBean implements MessageListener {
48 private static final long serialVersionUID = 75_638_176_619_024L;
53 private final DeliverableLandingEmail mailer;
58 private final String configFile = "org.mxchange.jmailer.config"; //NOI18N
63 public PizzaEmailDeliveryMessageBean () {
64 // Init mailer instance
65 this.mailer = new LandingMailer();
69 public void onMessage (final Message message) {
71 this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
72 // The parameter should be valid
73 if (null == message) {
75 throw new NullPointerException("message is null"); //NOI18N
76 } else if (!(message instanceof ObjectMessage)) {
77 // Not implementing right interface
78 throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
82 ObjectMessage objectMessage = (ObjectMessage) message;
85 Serializable serializable;
88 // Get object from message
89 serializable = objectMessage.getObject();
90 } catch (final JMSException ex) {
91 // Log it and don't continue any further
92 this.getLoggerBeanLocal().logException(ex);
97 this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
100 this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
107 public void init () {
109 this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
111 // Try to load bundle
112 ResourceBundle bundle = ResourceBundle.getBundle(this.configFile);
115 this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: bundle={0}", bundle)); //NOI18N
117 // The bunble should be valid
118 if (null == bundle) {
120 throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N
124 Properties properties = new Properties();
126 // Is the bundle not empty?
127 if (!bundle.keySet().isEmpty()) {
129 for (final String key : bundle.keySet()) {
131 this.getLoggerBeanLocal().logDebug(MessageFormat.format("init: key={0}", key)); //NOI18N
133 // Get string from bundle and set it in properties
134 properties.put(key, bundle.getString(key));
138 // Handle it over to the mailer
139 this.mailer.init(properties);
142 this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N