meta.inf=${source.root}/conf
meta.inf.excludes=sun-cmp-mappings.xml
platform.active=default_platform
-project.addressbook-lib=../addressbook-lib
-project.addressbook-mailer=../../NetBeansProjects/addressbook-mailer
project.juser-core=../juser-core
project.license=agpl30
+project.addressbook-lib=../addressbook-lib
+project.addressbook-mailer=../../NetBeansProjects/addressbook-mailer
+project.serviceLocator.class=org.mxchange.addressbook.mailer.model.delivery.AddressbookMailer
reference.addressbook-lib.jar=${project.addressbook-lib}/dist/addressbook-lib.jar
reference.addressbook-mailer.jar=${project.addressbook-mailer}/dist/addressbook-mailer.jar
resource.dir=setup
*/
package org.mxchange.addressbook.beans.resendlink;
+import de.chotime.landingpage.beans.resendlink.ResendLinkSessionBeanRemote;
+import java.text.MessageFormat;
+import java.util.Locale;
+import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
+import javax.faces.FacesException;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
/**
* A session-based EJB for resending confirmation links
*/
private static final long serialVersionUID = 71_546_726_857_195_360L;
+ /**
+ * Connection
+ */
+ private Connection connection;
+
+ /**
+ * Object message
+ */
+ private ObjectMessage message;
+
+ /**
+ * Message producer
+ */
+ private MessageProducer messageProducer;
+
+ /**
+ * Mailer message queue
+ */
+ private Queue queue;
+
+ /**
+ * Session instance
+ */
+ private Session session;
+
+ /**
+ * Initialization of this bean
+ */
+ @PostConstruct
+ public void init () {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
+
+ try {
+ // Get initial context
+ Context context = new InitialContext();
+
+ // Get factory from JMS resource
+ QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
+
+ // Lookup queue
+ this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
+
+ // Create connection
+ this.connection = connectionFactory.createConnection();
+
+ // Init session instance
+ this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // And message producer
+ this.messageProducer = this.session.createProducer(this.queue);
+
+ // Finally the message instance itself
+ this.message = this.session.createObjectMessage();
+ } catch (final NamingException | JMSException e) {
+ // Continued to throw
+ throw new FacesException(e);
+ }
+ }
+
+ @Override
+ public String resendConfirmationLink (final User user, final Locale locale) {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("resendConfirmationLink: user={0} - CALLED!", user)); //NOI18N
+
+ // The user instance should be valid
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N
+ } else if (user.getUserConfirmKey() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.userConfirmKey is null"); //NOI18N
+ } else if (user.getUserAccountStatus() != UserAccountStatus.UNCONFIRMED) {
+ // User account status is not UNCONFIRMED
+ throw new IllegalStateException(MessageFormat.format("Account status from user.userId={0} is not UNCONFIRMED:{1}", user.getUserId(), user.getUserAccountStatus())); //NOI18N
+ } else if (null == locale) {
+ // Locale should be set
+ throw new NullPointerException("locale is null"); //NOI18N
+ }
+
+ // @TODO Unfinished!
+ // All fine
+ return "resend_done"; //NOI18N
+ }
+
}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+
+/**
+ * A message-driven bean for sending out emails
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@MessageDriven (activationConfig = {
+ @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
+ @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
+})
+public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 75_638_176_619_024L;
+
+ /**
+ * Mailer instance
+ */
+ private final DeliverableAddressbookEmail mailer;
+
+ /**
+ * Default constructor
+ */
+ public EmailDeliveryMessageBean () {
+ // Init mailer instance
+ this.mailer = new AddressbookMailer();
+ }
+
+ @Override
+ public void onMessage (final Message message) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", 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("onMessage: serializable={0}", serializable)); //NOI18N
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
+ }
+
+}
import java.text.MessageFormat;
import java.util.GregorianCalendar;
import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.NoResultException;
import javax.persistence.Query;
-import org.mxchange.addressbook.mailer.model.delivery.AddressbookMailer;
-import org.mxchange.addressbook.mailer.model.delivery.DeliverableAddressbookEmail;
import org.mxchange.jcoreee.database.BaseDatabaseBean;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
import org.mxchange.jusercore.model.user.UserUtils;
// Persist it
//this.getEntityManager().persist(emailChange);
- // Get mailer instance
- DeliverableAddressbookEmail mailer = new AddressbookMailer();
- // Send out email change
- mailer.sendEmailChangeMail(this.messageProducer, this.message, emailChange);
+ // Prepare mail wrapper
+ WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper();
+
+ try {
+ // Create email address and set
+ Address emailAddress = new InternetAddress(emailChange.getEmailAddress());
+ emailWrapper.setRecipient(emailAddress);
+ } catch (final AddressException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Set all values
+ Properties variables = UserUtils.getAllUserFields(emailChange.getEmailChangeUser());
+
+ // Set all
+ // @TODO Get locale from user + language from message bundle
+ emailWrapper.setLocale(Locale.GERMAN);
+ emailWrapper.setSubjectLine("Email change");
+ emailWrapper.setTemplateName("email_change"); //NOI18N
+ emailWrapper.setTemplateVariables(variables);
+
+ try {
+ // Send out email change
+ this.message.setObject(emailWrapper);
+
+ // Send message
+ this.sendMessage(this.message);
+ } catch (final JMSException ex) {
+ // Throw again
+ throw new EJBException(ex);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("enqueueEmailAddressForChange - EXIT!"); //NOI18N
}
/**
*/
@PostConstruct
public void init () {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("init: CALLED!"); //NOI18N
+
try {
// Get initial context
Context context = new InitialContext();
// Get factory from JMS resource
- QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/addressbook-queue-factory"); //NOI18N
+ QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
// Lookup queue
- this.queue = (Queue) context.lookup("jms/addressbook-email-queue"); //NOI18N
+ this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
// Create connection
this.connection = connectionFactory.createConnection();
emailAddress.setEmailChangeHash(hash);
}
+ /**
+ * Sends given message to configured queue
+ * <p>
+ * @param message Message to send
+ * <p>
+ * @throws JMSException if something went wrong
+ */
+ private void sendMessage (final ObjectMessage message) throws JMSException {
+ // The parameter should be valid
+ if (null == message) {
+ // Throw NPE
+ throw new NullPointerException("message is null"); //NOI18N
+ }
+
+ // Send it
+ this.messageProducer.send(message);
+ }
+
}
// Return it
return addedUser;
}
+
}