Author: szimano Date: 2006-06-19 05:07:20 -0400 (Mon, 19 Jun 2006) New Revision: 4778 Added: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/mail-service.xml labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/EMailNotifierSLSB.java Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java Log: MDB->SLSB in wiki, mail configuration in repo Added: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/mail-service.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/mail-service.xml 2006-06-19 04:59:32 UTC (rev 4777) +++ labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/mail-service.xml 2006-06-19 09:07:20 UTC (rev 4778) @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE server> +<!-- $Id: mail-service.xml,v 1.5.6.1 2005/06/01 06:20:43 starksm Exp $ --> + +<server> + + <!-- ==================================================================== --> + <!-- Mail Connection Factory --> + <!-- ==================================================================== --> + + <mbean code="org.jboss.mail.MailService" + name="jboss:service=Mail"> + <attribute name="JNDIName">java:/Mail</attribute> + <attribute name="User">nobody</attribute> + <attribute name="Password">password</attribute> + <attribute name="Configuration"> + <!-- Test --> + <configuration> + <!-- Change to your mail server prototocol --> + <property name="mail.store.protocol" value="pop3"/> + <property name="mail.transport.protocol" value="smtp"/> + + <!-- Change to the user who will receive mail --> + <property name="mail.user" value="nobody"/> + + <!-- Change to the mail server --> + <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/> + + <!-- Change to the SMTP gateway server --> + <property name="mail.smtp.host" value="localhost"/> + + <!-- Change to the address mail will be from --> + <property name="mail.from" value="do-...@jb..."/> + + <!-- Enable debugging output from the javamail classes --> + <property name="mail.debug" value="false"/> + </configuration> + <depends>jboss:service=Naming</depends> + </attribute> + </mbean> + +</server> Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java 2006-06-19 04:59:32 UTC (rev 4777) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/WikiCommon.java 2006-06-19 09:07:20 UTC (rev 4778) @@ -37,6 +37,7 @@ import org.jboss.mx.util.MBeanProxyExt; import org.jboss.mx.util.MBeanServerLocator; import org.jboss.wiki.exceptions.WikiManagementNotFoundException; +import org.jboss.wiki.management.EMailNotifier; import org.jboss.wiki.management.NotificationMsg; import org.jboss.wiki.management.WikiServiceMenagement; import org.jboss.wiki.plugins.DifferenceEngine; @@ -77,17 +78,20 @@ try { InitialContext context = new InitialContext(); - QueueSession sess = null; - Queue queue = null; + //QueueSession sess = null; + //Queue queue = null; + EMailNotifier notifer = null; try { - queue = (Queue) context.lookup("queue/wikiNotifications"); + /*queue = (Queue) context.lookup("queue/wikiNotifications"); QueueConnectionFactory factory = (QueueConnectionFactory) context .lookup("java:/ConnectionFactory"); sess = factory.createQueueConnection().createQueueSession( - false, QueueSession.AUTO_ACKNOWLEDGE); + false, QueueSession.AUTO_ACKNOWLEDGE);*/ - if (sess != null) { - + notifer = (EMailNotifier)context.lookup(EMailNotifier.class.getName()); + + //if (sess != null) { + if (notifer != null) { String notifs = page .getMetaDataProperty(WatchListPlugin.WATCH_PROPERTY); @@ -150,17 +154,18 @@ diffs + "<br /><hr />\n<br/>\nThis is notification of page: " + pageLink + "<br/>\n" + pageHtml.getContent(), page.getName(), fromEmail, pageLink); - ObjectMessage msg = sess.createObjectMessage(notifMsg); - sess.createSender(queue).send(msg); + //ObjectMessage msg = sess.createObjectMessage(notifMsg); + //sess.createSender(queue).send(msg); + notifer.sendNotification(notifMsg); } } else { log.error("Couldn't create queue session."); } } catch (CloneNotSupportedException e) { log.error(e); - } catch (JMSException e) { + }/* catch (JMSException e) { log.error(e); - } + }*/ } catch (NamingException e1) { log.error(e1); } Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/EMailNotifierSLSB.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/EMailNotifierSLSB.java 2006-06-19 04:59:32 UTC (rev 4777) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/EMailNotifierSLSB.java 2006-06-19 09:07:20 UTC (rev 4778) @@ -0,0 +1,78 @@ +package org.jboss.wiki; + +import java.util.Date; + +import javax.ejb.Stateless; +import javax.mail.Address; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.Message.RecipientType; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; + +import org.jboss.logging.Logger; +import org.jboss.wiki.management.EMailNotifier; +import org.jboss.wiki.management.NotificationMsg; + +@Stateless +public class EMailNotifierSLSB implements EMailNotifier { + + private static final Logger log = Logger.getLogger(EMailNotifier.class); + + public synchronized void sendNotification(NotificationMsg notifications) { + + try { + Session session = (Session) PortableRemoteObject.narrow( + new InitialContext().lookup("java:Mail"), Session.class); + + log.debug("Got email notification msg"); + + for (String email : notifications.getEmails()) { + log.debug("MDB for: " + email); + + StringBuffer buffer = null; + Address[] to = null; + MimeMessage m = new MimeMessage(session); + + if (email != null) { + m + .setFrom(new InternetAddress(notifications + .getFromEmail())); + to = new InternetAddress[] { new InternetAddress(email) }; + m.setRecipients(RecipientType.TO, to); + m.setSubject("[JBossWiki] Page change notification: " + + notifications.getPageName()); + + m.setSentDate(new Date()); + buffer = new StringBuffer(); + + buffer + .append( + "This message is generated automaticcaly. Please do not reply. To remove yourself from the watch list please go to ") + .append(notifications.getPageLink()).append( + "<br />\n"); + buffer.append(notifications.getPageContent()); + + m.setContent(buffer.toString(), + "text/html; charset=\"UTF-8\""); + Transport.send(m); + log.debug("Notification send to: "+email); + } + } + } catch (ClassCastException e) { + log.error(e); + } catch (NamingException e) { + log.error(e); + } catch (AddressException e) { + log.error(e); + } catch (MessagingException e) { + log.error(e); + } + } + +} Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java 2006-06-19 04:59:32 UTC (rev 4777) +++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-management/src/java/org/jboss/wiki/MailNotificationBean.java 2006-06-19 09:07:20 UTC (rev 4778) @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.wiki; +/*package org.jboss.wiki; import java.util.Date; @@ -102,4 +102,4 @@ } } -} +}*/ |