From b24bc060edc4ded45ad6160cd18907767d6e760e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 8 Jul 2017 19:15:04 +0200 Subject: [PATCH] Please cherry-pick: - this message-driven bean has been moved to new project - also the mailer's initialization and config properties MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/build-impl.xml | 14 +- nbproject/project.properties | 11 +- nbproject/project.xml | 10 +- .../JobsEmailDeliveryMessageBean.java | 202 ------------------ .../org/mxchange/jmailer/config.properties | 21 -- 5 files changed, 22 insertions(+), 236 deletions(-) delete mode 100644 src/java/org/mxchange/jmailee/model/delivery/JobsEmailDeliveryMessageBean.java delete mode 100644 src/java/org/mxchange/jmailer/config.properties diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index df7c1f5..749bd30 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -812,7 +812,7 @@ exists or setup the property manually. For example like this: - + @@ -826,7 +826,7 @@ exists or setup the property manually. For example like this: - + @@ -862,7 +862,7 @@ exists or setup the property manually. For example like this: - + @@ -884,7 +884,7 @@ exists or setup the property manually. For example like this: - + @@ -906,7 +906,7 @@ exists or setup the property manually. For example like this: - + @@ -929,7 +929,7 @@ exists or setup the property manually. For example like this: - + @@ -1316,7 +1316,7 @@ exists or setup the property manually. For example like this: - + diff --git a/nbproject/project.properties b/nbproject/project.properties index 4db3ad3..bbeb373 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -74,7 +74,7 @@ javac.classpath=\ ${file.reference.jmailer-ee.jar}:\ ${reference.jjobs-core.jar}:\ ${reference.jjobs-lib.jar}:\ - ${reference.jjobs-mailer.jar}:\ + ${reference.jjobs-mailer-lib.jar}:\ ${file.reference.cdi-api.jar} javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.debug=true @@ -105,13 +105,14 @@ meta.inf.excludes=sun-cmp-mappings.xml platform.active=default_platform project.jjobs-core=../jjobs-core project.jjobs-lib=../jjobs-lib -project.jjobs-mailer=../jjobs-mailer +project.jjobs-mailer-lib=../../NetBeansProjects/jjobs-mailer-lib +project.jjobs-mailer.jar=../jjobs-mailer-lib project.juser-core=../juser-core project.license=agpl30 project.serviceLocator.class=org.mxchange.jjobs.mailer.model.delivery.JobsMailer reference.jjobs-core.jar=${project.jjobs-core}/dist/jjobs-core.jar reference.jjobs-lib.jar=${project.jjobs-lib}/dist/jjobs-lib.jar -reference.jjobs-mailer.jar=${project.jjobs-mailer}/dist/jjobs-mailer.jar +reference.jjobs-mailer-lib.jar=${project.jjobs-mailer-lib}/dist/jjobs-mailer-lib.jar resource.dir=setup run.test.classpath=\ ${javac.test.classpath}:\ @@ -120,8 +121,8 @@ run.test.classpath=\ # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): runmain.jvmargs= source.encoding=UTF-8 -source.reference.jaddressbook-core.jar=../jaddressbook-core/src/ -source.reference.jaddressbook-lib.jar=../jaddressbook-lib/src/ +source.reference.jjjobs-core.jar=../jjjobs-core/src/ +source.reference.jjjobs-lib.jar=../jjjobs-lib/src/ source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/ source.reference.jcontacts-core.jar=../jcontacts-core/src/ source.reference.jcontacts-lib.jar=../jcontacts-lib/src/ diff --git a/nbproject/project.xml b/nbproject/project.xml index 521ac6d..aeb8029 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -23,7 +23,7 @@ file.reference.jmailer-ee.jar reference.jjobs-core.jar reference.jjobs-lib.jar - reference.jjobs-mailer.jar + reference.jjobs-mailer-lib.jar file.reference.cdi-api.jar @@ -60,6 +60,14 @@ clean jar + + jjobs-mailer-lib + jar + + jar + clean + jar + juser-core jar diff --git a/src/java/org/mxchange/jmailee/model/delivery/JobsEmailDeliveryMessageBean.java b/src/java/org/mxchange/jmailee/model/delivery/JobsEmailDeliveryMessageBean.java deleted file mode 100644 index c68f430..0000000 --- a/src/java/org/mxchange/jmailee/model/delivery/JobsEmailDeliveryMessageBean.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jmailee.model.delivery; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Properties; -import java.util.ResourceBundle; -import javax.annotation.PostConstruct; -import javax.ejb.ActivationConfigProperty; -import javax.ejb.MessageDriven; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.ObjectMessage; -import javax.mail.MessagingException; -import javax.naming.NamingException; -import org.mxchange.jjobs.database.BaseJobsDatabaseBean; -import org.mxchange.jjobsmailer.model.delivery.DeliverableJobsEmail; -import org.mxchange.jjobsmailer.model.delivery.JobsMailer; -import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; - -/** - * A message queue for sending out emails - *

- * @author Roland Häder - */ -@MessageDriven ( - name = "jjobsEmailDelivery", - description = "A message bean for email delivery", - activationConfig = { - @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jjobs-email-queue"), - @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") - }) -public class JobsEmailDeliveryMessageBean extends BaseJobsDatabaseBean implements MessageListener { - - /** - * Serial number - */ - private static final long serialVersionUID = 75_638_176_619_024L; - - /** - * Configuration file - */ - private final String configFile = "org.mxchange.jmailer.config"; //NOI18N - - /** - * Mailer instance - */ - private final DeliverableJobsEmail mailer; - - /** - * Default constructor - *

- * @throws javax.naming.NamingException If a JNDI name could not be found - */ - public JobsEmailDeliveryMessageBean () throws NamingException { - // Call super constructor - super(); - - // Init mailer instance - this.mailer = new JobsMailer(); - } - - /** - * Post-construction - */ - @PostConstruct - public void init () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Try to load bundle - ResourceBundle bundle = ResourceBundle.getBundle(this.configFile); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: bundle={1}", this.getClass().getSimpleName(), bundle)); //NOI18N - - // The bunble should be valid - if (null == bundle) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N - } - - // Init Properties - Properties properties = new Properties(); - - // Is the bundle not empty? - if (!bundle.keySet().isEmpty()) { - // Loop through all - for (final String key : bundle.keySet()) { - // Log debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: key={1}", this.getClass().getSimpleName(), key)); //NOI18N - - // Get string from bundle and set it in properties - properties.put(key, bundle.getString(key)); - } - } - - // Handle it over to the mailer - this.mailer.init(properties); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - @Override - public void onMessage (final Message message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N - - // The parameter should be valid - if (null == message) { - // Throw NPE - throw new NullPointerException("message is null"); //NOI18N - } else if (!(message instanceof ObjectMessage)) { - // Not implementing right interface - throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N - } - - // Securely cast it - ObjectMessage objectMessage = (ObjectMessage) message; - - // Init variable - Serializable serializable; - - try { - // Get object from message - serializable = objectMessage.getObject(); - } catch (final JMSException ex) { - // Log it and don't continue any further - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N - - // Okay, is it the right interface? - if (null == serializable) { - // Throw NPE - throw new NullPointerException("serializable is null"); //NOI18N - } else if (!(serializable instanceof WrapableEmailDelivery)) { - // Not correct object send - throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N - } - - // Securely cast it - WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable; - - // Is all required set? - if (wrapper.getLocale() == null) { - // Throw NPE - throw new NullPointerException("wrapper.locale is null"); //NOI18N - } else if (wrapper.getRecipientAddress()== null) { - // Throw again ... - throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N - } else if (wrapper.getSubjectLine() == null) { - // ... and again - throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N - } else if (wrapper.getSubjectLine().isEmpty()) { - // Is empty - throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N - } else if (wrapper.getTemplateName() == null) { - // Throw NPE again - throw new NullPointerException("wrapper.templateName is null"); //NOI18N - } else if (wrapper.getTemplateName().isEmpty()) { - // Is empty - throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N - } else if (wrapper.getTemplateVariables() == null) { - // No template variables set, should not happen - throw new NullPointerException("wrapper.templateVariables is null"); //NOI18N - } - - try { - // Send email out - this.mailer.sendDeliverableMail(wrapper); - } catch (final MessagingException ex) { - // Opps, something went wrong - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N - } - -} diff --git a/src/java/org/mxchange/jmailer/config.properties b/src/java/org/mxchange/jmailer/config.properties deleted file mode 100644 index 5a02e31..0000000 --- a/src/java/org/mxchange/jmailer/config.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2016, 2017 Roland H\u00e4der -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -# Email address for "Errors-To" header -mailer.errorsto=you@foo.example -# Email address for "Bounces-To" header -mailer.bouncesto=you@foo.example -# Email address for "X-Loop" header -mailer.xloop=you@foo.example -- 2.39.5