<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
-<project name="addressbook-mailer-ejb" default="default" basedir="." xmlns:ejbjarproject="http://www.netbeans.org/ns/j2ee-mailer-ejbjarproject/3">
- <description>Builds, tests, and runs the project addressbook-mailer-ejb.</description>
+<project name="jjobs-mailer-ejb" default="default" basedir="." xmlns:ejbjarproject="http://www.netbeans.org/ns/j2ee-mailer-ejbjarproject/3">
+ <description>Builds, tests, and runs the project jjobs-mailer-ejb.</description>
<import file="nbproject/build-impl.xml"/>
<!--
- cleanup
-->
-<project xmlns:ejbjarproject1="http://www.netbeans.org/ns/j2ee-ejbjarproject/1" xmlns:ejbjarproject2="http://www.netbeans.org/ns/j2ee-ejbjarproject/2" xmlns:ejbjarproject3="http://www.netbeans.org/ns/j2ee-ejbjarproject/3" basedir=".." default="default" name="addressbook-mailer-ejb-impl">
+<project xmlns:ejbjarproject1="http://www.netbeans.org/ns/j2ee-ejbjarproject/1" xmlns:ejbjarproject2="http://www.netbeans.org/ns/j2ee-ejbjarproject/2" xmlns:ejbjarproject3="http://www.netbeans.org/ns/j2ee-ejbjarproject/3" basedir=".." default="default" name="jjobs-mailer-ejb-impl">
<import file="ant-deploy.xml"/>
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
- <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="addressbook-mailer-ejb" testname="TestNG tests" workingDir="${basedir}">
+ <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="jjobs-mailer-ejb" testname="TestNG tests" workingDir="${basedir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
<isset property="test.method"/>
</condition>
- <condition else="-suitename addressbook-mailer-ejb -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
+ <condition else="-suitename jjobs-mailer-ejb -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<matches pattern=".*\.xml" string="@{testClass}"/>
</condition>
<delete dir="${build.test.results.dir}" quiet="true"/>
COMPILATION SECTION
-->
<target depends="init" if="no.dist.ear.dir" name="-deps-module-jar" unless="no.deps">
- <ant antfile="${project.addressbook-mailer-lib}/build.xml" inheritall="false" target="jar">
+ <ant antfile="${project.jjobs-mailer-lib}/build.xml" inheritall="false" target="jar">
<property name="deploy.on.save" value="false"/>
</ant>
<ant antfile="${project.juser-core}/build.xml" inheritall="false" target="jar">
</ant>
</target>
<target depends="init" if="dist.ear.dir" name="-deps-ear-jar" unless="no.deps">
- <ant antfile="${project.addressbook-mailer-lib}/build.xml" inheritall="false" target="jar">
+ <ant antfile="${project.jjobs-mailer-lib}/build.xml" inheritall="false" target="jar">
<property name="deploy.on.save" value="false"/>
</ant>
<ant antfile="${project.juser-core}/build.xml" inheritall="false" target="jar">
<copyfiles files="${file.reference.jcore-logger-lib.jar}" todir="${build.classes.dir}"/>
<copyfiles files="${file.reference.jmailer-ee.jar}" todir="${build.classes.dir}"/>
<copyfiles files="${file.reference.cdi-api.jar}" todir="${build.classes.dir}"/>
- <copyfiles files="${reference.addressbook-mailer-lib.jar}" todir="${build.classes.dir}"/>
+ <copyfiles files="${reference.jjobs-mailer-lib.jar}" todir="${build.classes.dir}"/>
<copyfiles files="${libs.velocity.classpath}" todir="${build.classes.dir}"/>
</target>
<target if="is.server.weblogic" name="-library-inclusion-in-archive-weblogic">
<basename file="${file.reference.jcore-logger-lib.jar}" property="manifest.file.reference.jcore-logger-lib.jar"/>
<basename file="${file.reference.jmailer-ee.jar}" property="manifest.file.reference.jmailer-ee.jar"/>
<basename file="${file.reference.cdi-api.jar}" property="manifest.file.reference.cdi-api.jar"/>
- <basename file="${reference.addressbook-mailer-lib.jar}" property="manifest.reference.addressbook-mailer-lib.jar"/>
+ <basename file="${reference.jjobs-mailer-lib.jar}" property="manifest.reference.jjobs-mailer-lib.jar"/>
<basename file="${libs.velocity.classpath}" property="manifest.libs.velocity.classpath"/>
<manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update">
<attribute name="Extension-List" value="jar-1 jar-2 jar-3 jar-4 jar-5 jar-6 "/>
<attribute name="jar-2-Extension-Name" value="${manifest.file.reference.jcore-logger-lib.jar}"/>
<attribute name="jar-3-Extension-Name" value="${manifest.file.reference.jmailer-ee.jar}"/>
<attribute name="jar-4-Extension-Name" value="${manifest.file.reference.cdi-api.jar}"/>
- <attribute name="jar-5-Extension-Name" value="${manifest.reference.addressbook-mailer-lib.jar}"/>
+ <attribute name="jar-5-Extension-Name" value="${manifest.reference.jjobs-mailer-lib.jar}"/>
<attribute name="jar-6-Extension-Name" value="${manifest.libs.velocity.classpath}"/>
</manifest>
</target>
<copyfiles files="${file.reference.jcore-logger-lib.jar}" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jmailer-ee.jar}" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.cdi-api.jar}" todir="${dist.ear.dir}/lib"/>
- <copyfiles files="${reference.addressbook-mailer-lib.jar}" todir="${dist.ear.dir}/lib"/>
+ <copyfiles files="${reference.jjobs-mailer-lib.jar}" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${libs.velocity.classpath}" todir="${dist.ear.dir}/lib"/>
<manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target>
CLEANUP SECTION
-->
<target depends="init" name="deps-clean" unless="no.deps">
- <ant antfile="${project.addressbook-mailer-lib}/build.xml" inheritall="false" target="clean"/>
+ <ant antfile="${project.jjobs-mailer-lib}/build.xml" inheritall="false" target="clean"/>
<ant antfile="${project.juser-core}/build.xml" inheritall="false" target="clean"/>
</target>
<target depends="init" name="-do-clean">
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
-file.reference.addressbook-mailer.jar=lib/addressbook-mailer.jar
+file.reference.jjobs-mailer.jar=lib/jjobs-mailer.jar
file.reference.cdi-api.jar=lib/cdi-api.jar
file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
file.reference.jcoreee.jar=lib/jcoreee.jar
j2ee.platform.wsit.classpath=
j2ee.server.type=gfv3ee6
jar.compress=false
-jar.name=addressbook-mailer-ejb.jar
+jar.name=jjobs-mailer-ejb.jar
jars.in.ejbjar=false
javac.classpath=\
${file.reference.jcoreee.jar}:\
${file.reference.jcore-logger-lib.jar}:\
${file.reference.jmailer-ee.jar}:\
${file.reference.cdi-api.jar}:\
- ${reference.addressbook-mailer-lib.jar}:\
+ ${reference.jjobs-mailer-lib.jar}:\
${libs.velocity.classpath}
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
javac.debug=true
javadoc.splitindex=true
javadoc.use=true
javadoc.version=true
-javadoc.windowtitle=addressbook EJBs
+javadoc.windowtitle=jjobs EJBs
meta.inf=${source.root}/conf
meta.inf.excludes=sun-cmp-mappings.xml
platform.active=default_platform
-project.addressbook-mailer-lib=../addressbook-mailer-lib
+project.jjobs-mailer-lib=../jjobs-mailer-lib
project.juser-core=../juser-core
project.license=agpl30
project.serviceLocator.class=de.chotime.landingpage.mailer.model.delivery.LandingMailer
-reference.addressbook-mailer-lib.jar=${project.addressbook-mailer-lib}/dist/addressbook-mailer-lib.jar
+reference.jjobs-mailer-lib.jar=${project.jjobs-mailer-lib}/dist/jjobs-mailer-lib.jar
resource.dir=setup
run.test.classpath=\
${javac.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.addressbook-mailer.jar=../addressbook-mailer/src/
+source.reference.jjobs-mailer.jar=../jjobs-mailer/src/
source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
source.reference.jcoreee.jar=../jcoreee/src/
source.reference.jmailer-ee.jar=../jmailer-ee/src/
<type>org.netbeans.modules.j2ee.ejbjarproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2ee-ejbjarproject/3">
- <name>addressbook-mailer-ejb</name>
+ <name>jjobs-mailer-ejb</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<included-library dirs="200">file.reference.jcoreee.jar</included-library>
<included-library dirs="200">file.reference.jcore-logger-lib.jar</included-library>
<included-library dirs="200">file.reference.jmailer-ee.jar</included-library>
<included-library dirs="200">file.reference.cdi-api.jar</included-library>
- <included-library dirs="200">reference.addressbook-mailer-lib.jar</included-library>
+ <included-library dirs="200">reference.jjobs-mailer-lib.jar</included-library>
<included-library dirs="200">libs.velocity.classpath</included-library>
<source-roots>
<root id="src.dir"/>
</libraries>
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
<reference>
- <foreign-project>addressbook-mailer-lib</foreign-project>
+ <foreign-project>jjobs-mailer-lib</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.mailer.model.delivery;
-
-import java.io.Serializable;
-import java.text.MessageFormat;
-import javax.ejb.ActivationConfigProperty;
-import javax.ejb.EJB;
-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.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
-
-/**
- * A message-driven bean for sending out mails
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@MessageDriven (
- name = "addressbookEmailDelivery",
- description = "A message bean for email delivery",
- activationConfig = {
- @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/addressbook-email-queue"),
- @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
- })
-public class AddressbookEmailDeliveryMessageBean extends BaseDatabaseBean implements MessageListener {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 75_638_176_619_024L;
-
- /**
- * Mailer instance
- */
- @EJB
- private DeliverableAddressbookEmailLocal mailerBean;
-
- /**
- * Default constructor
- * <p>
- * @throws javax.naming.NamingException If a JNDI name could not be found
- */
- public AddressbookEmailDeliveryMessageBean () throws NamingException {
- // Call super constructor
- super();
- }
-
- @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
- }
-
- try {
- // Send email out
- this.mailerBean.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
- }
-
-}
+++ /dev/null
-/*
- * 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 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.mailer.model.delivery;
-
-import java.text.MessageFormat;
-import java.util.Map;
-import java.util.Properties;
-import java.util.ResourceBundle;
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-import javax.ejb.Singleton;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.mxchange.jmailee.model.delivery.BaseMailerBean;
-import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
-
-/**
- * A singleton mailer EJB
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Singleton
-public class AddressbookMailerSingletonBean extends BaseMailerBean implements DeliverableAddressbookEmailLocal {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 17_857_816_596_030_918L;
-
- /**
- * Configuration file
- */
- private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N
-
- /**
- * Email session
- */
- @Resource (name = "addressbookSmtpSession", description = "A Java Mail session")
- private Session mailSession;
-
- /**
- * Default constructor
- * <p>
- */
- public AddressbookMailerSingletonBean () {
- }
-
- /**
- * 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.setProperties(properties);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N
- }
-
- @Override
- public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException {
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N
-
- // The parameter must be valid
- if (null == emailWrapper) {
- // Throw NPE
- throw new NullPointerException("emailWrapper is null"); //NOI18N
- } else if (emailWrapper.getRecipientAddress() == null) {
- // Throw NPE again
- throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N
- } else if (emailWrapper.getSubjectLine() == null) {
- // ... and again
- throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N
- } else if (emailWrapper.getSubjectLine().isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N
- } else if (emailWrapper.getTemplateName() == null) {
- // ... and again
- throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N
- } else if (emailWrapper.getTemplateName().isEmpty()) {
- // Is empty
- throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N
- } else if (emailWrapper.getLocale() == null) {
- // Throw NPE again
- throw new NullPointerException("emailWrapper.locale is null"); //NOI18N
- } else if (!emailWrapper.getTemplateVariables().containsKey("baseUrl")) { //NOI18N
- // Not set
- throw new IllegalArgumentException("emailWrapper.templateVariables.baseUrl is not set"); //NOI18N
- }
-
- // All required data is set, load template
- Template template = this.getTemplateEngine().getTemplate(String.format("templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N
-
- // Init context
- VelocityContext context = new VelocityContext();
-
- // Are some variables set?
- if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) {
- // Add all variables
- for (Map.Entry<Object, Object> entry : emailWrapper.getTemplateVariables().entrySet()) {
- // Get key/value
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
-
- // Both should not be empty
- if (null == key) {
- // Throw NPE
- throw new NullPointerException("key is null"); //NOI18N
- } else if (null == value) {
- // Throw NPE again
- throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N
- }
-
- // Set it
- context.put(key, value);
- }
- }
-
- // Send the email
- this.deliverMailWithTemplate(template, context, emailWrapper, this.mailSession);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N
- }
-
-}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.mailer.model.delivery;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+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.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
+
+/**
+ * A message-driven bean for sending out mails
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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 BaseDatabaseBean implements MessageListener {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 75_638_176_619_024L;
+
+ /**
+ * Mailer instance
+ */
+ @EJB
+ private DeliverableJobsEmailLocal mailerBean;
+
+ /**
+ * Default constructor
+ * <p>
+ * @throws javax.naming.NamingException If a JNDI name could not be found
+ */
+ public JobsEmailDeliveryMessageBean () throws NamingException {
+ // Call super constructor
+ super();
+ }
+
+ @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
+ }
+
+ try {
+ // Send email out
+ this.mailerBean.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
+ }
+
+}
--- /dev/null
+/*
+ * 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 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.mailer.model.delivery;
+
+import java.text.MessageFormat;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ResourceBundle;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.Singleton;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.mxchange.jmailee.model.delivery.BaseMailerBean;
+import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
+
+/**
+ * A singleton mailer EJB
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Singleton
+public class JobsMailerSingletonBean extends BaseMailerBean implements DeliverableJobsEmailLocal {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 17_857_816_596_030_918L;
+
+ /**
+ * Configuration file
+ */
+ private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N
+
+ /**
+ * Email session
+ */
+ @Resource (name = "jjobsSmtpSession", description = "A Java Mail session")
+ private Session mailSession;
+
+ /**
+ * Default constructor
+ * <p>
+ */
+ public JobsMailerSingletonBean () {
+ }
+
+ /**
+ * 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.setProperties(properties);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N
+ }
+
+ @Override
+ public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N
+
+ // The parameter must be valid
+ if (null == emailWrapper) {
+ // Throw NPE
+ throw new NullPointerException("emailWrapper is null"); //NOI18N
+ } else if (emailWrapper.getRecipientAddress() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N
+ } else if (emailWrapper.getSubjectLine() == null) {
+ // ... and again
+ throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N
+ } else if (emailWrapper.getSubjectLine().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N
+ } else if (emailWrapper.getTemplateName() == null) {
+ // ... and again
+ throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N
+ } else if (emailWrapper.getTemplateName().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N
+ } else if (emailWrapper.getLocale() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailWrapper.locale is null"); //NOI18N
+ } else if (!emailWrapper.getTemplateVariables().containsKey("baseUrl")) { //NOI18N
+ // Not set
+ throw new IllegalArgumentException("emailWrapper.templateVariables.baseUrl is not set"); //NOI18N
+ }
+
+ // All required data is set, load template
+ Template template = this.getTemplateEngine().getTemplate(String.format("templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N
+
+ // Init context
+ VelocityContext context = new VelocityContext();
+
+ // Are some variables set?
+ if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) {
+ // Add all variables
+ for (Map.Entry<Object, Object> entry : emailWrapper.getTemplateVariables().entrySet()) {
+ // Get key/value
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+
+ // Both should not be empty
+ if (null == key) {
+ // Throw NPE
+ throw new NullPointerException("key is null"); //NOI18N
+ } else if (null == value) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N
+ }
+
+ // Set it
+ context.put(key, value);
+ }
+ }
+
+ // Send the email
+ this.deliverMailWithTemplate(template, context, emailWrapper, this.mailSession);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N
+ }
+
+}