[jboss-svn-commits] JBL Code SVN: r5537 - in labs/jbossesb/trunk/product/core: common/src/org/jboss/soa/esb/helpers common/src/org/jboss/soa/esb/notification common/tests/src/org/jboss/soa/esb/helpers services/tests/src/org/jboss/soa/esb/services/EJB/test
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 7 10:08:44 EDT 2006
Author: tfennelly
Date: 2006-08-07 10:08:32 -0400 (Mon, 07 Aug 2006)
New Revision: 5537
Modified:
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/Email.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/EJB/test/NotificationTest.java
Log:
Committing Johan Kumps mods re http://jira.jboss.com/jira/browse/JBESB-67. He was unable to commit to SVN for some reason and Mark asked me to do it for him.
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/Email.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/Email.java 2006-08-07 13:59:43 UTC (rev 5536)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/Email.java 2006-08-07 14:08:32 UTC (rev 5537)
@@ -23,6 +23,7 @@
package org.jboss.soa.esb.helpers;
import java.util.Properties;
+import java.util.StringTokenizer;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
@@ -99,11 +100,46 @@
* to be attached in the outgoing message
*/
public static final String MESSAGE = "message";
+
+ /**
+ * will be the contents of the From: field in the outgoing message
+ */
+ private String from = null;
+ /**
+ * comma separated list of recipients
+ */
+ private String sendTo = null;
+
+ /**
+ * comma separated list of copy recipients
+ */
+ private String copyTo = null;
+
+ /**
+ * This attribute will be the content of the subject of the mail message
+ */
+ private String subject = null;
+
+ /**
+ * Comma separated list of attachment file names
+ */
+ private String[] attachments = null;
+
+ /**
+ * Value of this attribute will be the content of the e-mail's text
+ */
+ private String message = null;
+
/**
* The message to b sent via a subsequent call to {@link #sendMessage()}.
*/
private MimeMessage mailMessage;
+
+ /**
+ * The mail Session to use
+ */
+ private Session oMailSess = null;
/**
* Public constructor.
@@ -122,24 +158,21 @@
* @see DomElement
*
*/
- public Email(DomElement p_oMessageParms) throws AddressException, MessagingException {
+ public Email() throws AddressException, MessagingException {
// REVIEW: How about typing the parameters a little better??? Looks as though that might have a huge ripple-on effect accross the codebase!!
// REVIEW: Does the session need to ne initialised every time???
- Session oMailSess = initMailServerSession();
+ this.oMailSess = initMailServerSession();
- // Initialise the oMailMess property...
- mailMessage = createMailMessage(p_oMessageParms, oMailSess);
-
// Message can be "sent" via a subsequent call to the sendMessage method!
} // __________________________________
/**
* Send the mail message associated with this instance.
* @throws MessagingException Unable to transport the message associated with this
- * EsbEmail instance.
+ * Email instance.
*/
public void sendMessage() throws MessagingException {
- Transport.send(mailMessage);
+ Transport.send(this.getMailMessage());
}
/**
@@ -147,11 +180,98 @@
* instance.
* @return The mailMessage property value.
*/
- public MimeMessage getMailMessage() {
+ public MimeMessage getMailMessage() throws MessagingException {
+ if (this.mailMessage == null){
+ this.mailMessage = this.createMailMessage(this.oMailSess);
+ }
return mailMessage;
- }
+ }
/**
+ * @return Returns the attachments.
+ */
+ public String[] getAttachments() {
+ return this.attachments;
+ }
+
+ /**
+ * @param attachments The attachments to set.
+ */
+ public void setAttachments(String[] attachments) {
+ this.attachments = attachments;
+ }
+
+ /**
+ * @return Returns the copyTo.
+ */
+ public String getCopyTo() {
+ return this.copyTo;
+ }
+
+ /**
+ * @param copyTo The copyTo to set.
+ */
+ public void setCopyTo(String copyTo) {
+ this.copyTo = copyTo;
+ }
+
+ /**
+ * @return Returns the from.
+ */
+ public String getFrom() {
+ return this.from;
+ }
+
+ /**
+ * @param from The from to set.
+ */
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ /**
+ * @return Returns the sendTo.
+ */
+ public String getSendTo() {
+ return this.sendTo;
+ }
+
+ /**
+ * @param sendTo The sendTo to set.
+ */
+ public void setSendTo(String sendTo) {
+ this.sendTo = sendTo;
+ }
+
+ /**
+ * @return Returns the subject.
+ */
+ public String getSubject() {
+ return this.subject;
+ }
+
+ /**
+ * @param subject The subject to set.
+ */
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ /**
+ * @return Returns the message.
+ */
+ public String getMessage() {
+ return this.message;
+ }
+
+ /**
+ * @param message The message to set.
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
* Create the mail message instance to be {@link #sendMessage() sent}.
* @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
* @param oMailSess Mail session on which the message is to be transported.
@@ -159,13 +279,13 @@
* @throws AddressException
* @throws MessagingException
*/
- private MimeMessage createMailMessage(DomElement p_oMessageParms, Session oMailSess) throws AddressException, MessagingException {
+ private MimeMessage createMailMessage(Session oMailSess) throws AddressException, MessagingException {
MimeMessage oMessage = new MimeMessage(oMailSess);
// Populate the message with the data supplied in the p_oMessageParms DomElement.
- addMessageAddressing(p_oMessageParms, oMessage);
- addMessageSubject(p_oMessageParms, oMessage);
- addMessageContent(p_oMessageParms, oMessage);
+ addMessageAddressing(oMessage);
+ addMessageSubject( oMessage);
+ addMessageContent(oMessage);
return oMessage;
}
@@ -177,22 +297,20 @@
* @throws AddressException
* @throws MessagingException
*/
- private void addMessageAddressing(DomElement p_oMessageParms, MimeMessage oMessage) throws AddressException, MessagingException {
- String sFrom = p_oMessageParms.getAttr(FROM);
- InternetAddress oFrom = new InternetAddress(sFrom);
+ private void addMessageAddressing(MimeMessage oMessage) throws AddressException, MessagingException {
+ InternetAddress oFrom = new InternetAddress(this.from);
oMessage.setFrom(oFrom);
oMessage.setReplyTo(new Address[] { oFrom });
InternetAddress[] oaTo =
- InternetAddress.parse(p_oMessageParms.getAttr(SENDTO));
+ InternetAddress.parse(this.sendTo);
for (int i1 = 0; i1 < oaTo.length; i1++) {
oMessage.addRecipient(MimeMessage.RecipientType.TO, oaTo[i1]);
}
-
- String sCopyToAddress = (String) p_oMessageParms.getAttr(COPYTO);
- if (null != sCopyToAddress) {
- oaTo = InternetAddress.parse(sCopyToAddress);
+
+ if (null != this.copyTo) {
+ oaTo = InternetAddress.parse(this.copyTo);
for (int i1 = 0; i1 < oaTo.length; i1++) {
oMessage.addRecipient(MimeMessage.RecipientType.CC, oaTo[i1]);
}
@@ -205,11 +323,9 @@
* @param oMessage The message.
* @throws MessagingException
*/
- private void addMessageSubject(DomElement p_oMessageParms, MimeMessage oMessage) throws MessagingException {
- String sSubject = (String) p_oMessageParms.getAttr(SUBJECT);
-
- if (null != sSubject) {
- oMessage.setSubject(sSubject);
+ private void addMessageSubject(MimeMessage oMessage) throws MessagingException {
+ if (null != this.subject) {
+ oMessage.setSubject(this.subject);
}
}
@@ -220,25 +336,24 @@
* @param oMessage The message.
* @throws MessagingException
*/
- private void addMessageContent(DomElement p_oMessageParms, MimeMessage oMessage) throws MessagingException {
+ private void addMessageContent(MimeMessage oMessage) throws MessagingException {
BodyPart oBodyP = new MimeBodyPart();
Multipart oMultiP = new MimeMultipart();
oMultiP.addBodyPart(oBodyP);
oMessage.setContent(oMultiP);
- String sBodyPartText = p_oMessageParms.getAttr(MESSAGE);
- if (null == sBodyPartText) {
- sBodyPartText = "";
+ if (null == this.message) {
+ this.message = "";
}
- oBodyP.setText(sBodyPartText + "\n");
+ oBodyP.setText(this.message + "\n");
- String[] saFn = p_oMessageParms.getTextChildren(ATTACH);
- for (int i1 = 0; i1 < saFn.length; i1++) {
- oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
- String sFile = saFn[i1];
- oBodyP.setDataHandler(new DataHandler(new FileDataSource(sFile)));
- oBodyP.setFileName(sFile.substring(1 + sFile.lastIndexOf("\\")));
- }
+
+ for (int i1 = 0; i1 < this.attachments.length; i1++) {
+ oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
+ String sFile = this.attachments[i1];
+ oBodyP.setDataHandler(new DataHandler(new FileDataSource(sFile)));
+ oBodyP.setFileName(sFile.substring(1 + sFile.lastIndexOf("\\")));
+ }
}
/**
@@ -265,6 +380,25 @@
javax.mail.Session.getDefaultInstance(oMailP, oAuth);
return oMailSess;
}
+
+ /**
+ * Method parsing filename from a string containing a comma separated list of filenames
+ * @param attachments the string containing the comma separated list of filenames
+ * @return a String array containing an entry for every filename in the given comma separated list
+ */
+ private String[] getFileNamesAsArray(String attachments) {
+ if (attachments.indexOf(',') != -1){
+ StringTokenizer st = new StringTokenizer(attachments,",");
+ String[] attachmentFileNames = new String[st.countTokens()];
+ int index = 0;
+ while (st.hasMoreTokens()) {
+ attachmentFileNames[index] = st.nextToken();
+ index++;
+ }
+ return attachmentFileNames;
+ }
+ return new String[]{attachments};
+ }
private class MyAuth extends Authenticator {
private String m_sUser, m_sPwd;
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java 2006-08-07 13:59:43 UTC (rev 5536)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java 2006-08-07 14:08:32 UTC (rev 5537)
@@ -31,7 +31,7 @@
import org.jboss.soa.esb.util.Util;
/**
- * This class will send an e-mail using the EsbEmail class
+ * This class will send an e-mail using the Email class
* <p>
* Description:
* </p>
@@ -48,10 +48,9 @@
*
* @param p_oP
* DomElement - See attributes and structure needed for the
- * EsbEmail(DomElement) constructor - The MESSAGE attribute will
+ * Email() constructor - The MESSAGE attribute will
* be filled in at sendNotification(Serializable) time
* @throws Exception
- * @see Email#Email(DomElement)
* @see NotifyEmail#sendNotification(Serializable)
*/
public NotifyEmail(DomElement p_oP) throws Exception {
@@ -69,7 +68,7 @@
} // __________________________________
/**
- * Send an Email using EsbEmail() using p_o.toString() to fill in the
+ * Send an Email using Email() using p_o.toString() to fill in the
* message text
*
* @param p_o
@@ -97,7 +96,16 @@
* @param messageParams Message parameters.
*/
protected void sendEmailNotification(DomElement messageParams) throws AddressException, MessagingException {
- Email esbMail = new Email(messageParams);
+
+ Email esbMail = new Email();
+ esbMail.setSendTo(messageParams.getAttr(Email.SENDTO));
+ esbMail.setFrom(messageParams.getAttr(Email.FROM));
+ esbMail.setCopyTo(messageParams.getAttr(Email.COPYTO));
+ esbMail.setSubject(messageParams.getAttr(Email.SUBJECT));
+
+ esbMail.setAttachments(messageParams.getTextChildren(Email.ATTACH));
+ esbMail.setMessage(messageParams.getAttr(Email.MESSAGE));
+
esbMail.sendMessage();
}
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java 2006-08-07 13:59:43 UTC (rev 5536)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java 2006-08-07 14:08:32 UTC (rev 5537)
@@ -48,7 +48,14 @@
public void test_Email() throws AddressException, MessagingException, IOException {
// Look at the source message in testfile4.xml before reading this test.
- Email esbMail = new Email(mailParams);
+ Email esbMail = new Email();
+ esbMail.setSendTo(mailParams.getAttr(Email.SENDTO));
+ esbMail.setFrom(mailParams.getAttr(Email.FROM));
+ esbMail.setCopyTo(mailParams.getAttr(Email.COPYTO));
+ esbMail.setSubject(mailParams.getAttr(Email.SUBJECT));
+
+ esbMail.setAttachments(mailParams.getTextChildren(Email.ATTACH));
+ esbMail.setMessage(mailParams.getAttr(Email.MESSAGE));
MimeMessage message = esbMail.getMailMessage();
Address[] addresses;
Modified: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/EJB/test/NotificationTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/EJB/test/NotificationTest.java 2006-08-07 13:59:43 UTC (rev 5536)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/EJB/test/NotificationTest.java 2006-08-07 14:08:32 UTC (rev 5537)
@@ -21,8 +21,15 @@
*/
package org.jboss.soa.esb.services.EJB.test;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Hashtable;
+
+import javax.naming.InitialContext;
+
import junit.framework.Test;
import junit.framework.TestSuite;
+
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.jboss.soa.esb.common.tests.BaseTest;
@@ -35,12 +42,7 @@
import org.jboss.soa.esb.notification.NotifySqlTable;
import org.jboss.soa.esb.services.EJB.NotificationHandler;
-import javax.naming.InitialContext;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Hashtable;
-
public class NotificationTest extends BaseTest
{
private Logger logger = Logger.getLogger(NotificationTest.class);
@@ -107,17 +109,17 @@
// {
// DomElement oTgt = new DomElement(NotificationList.CHILD_TGT);
// oTgt.setAttr(NotificationTarget.PRM_NOTIF_CLASS,"NotifyEmail");
-// oTgt.setAttr(EsbEmail.FROM,"sender at jboss.com");
-// oTgt.setAttr(EsbEmail.SENDTO,"receiver1 at hotmail.com,receiver2 at jboss.com");;
-// oTgt.setAttr(EsbEmail.SUBJECT,"TEST from Rosetta");
-// oTgt.setAttr(EsbEmail.MESSAGE,"This is the text of your message");
+// oTgt.setAttr(Email.FROM,"sender at jboss.com");
+// oTgt.setAttr(Email.SENDTO,"receiver1 at hotmail.com,receiver2 at jboss.com");;
+// oTgt.setAttr(Email.SUBJECT,"TEST from Rosetta");
+// oTgt.setAttr(Email.MESSAGE,"This is the text of your message");
//
// // This class does NOT send the e-mails, the app server does
// // consequently these paths would have to be accessible in the
// // application server (filesystem / mounts)
// String[] sa = {"/tmp/tomcat.sh","/tmp/program.js"};
// for (String sCurr : sa)
-// oTgt.addTextChild(EsbEmail.ATTACH,sCurr);
+// oTgt.addTextChild(Email.ATTACH,sCurr);
//
// return oTgt;
// } //________________________________
More information about the jboss-svn-commits
mailing list