Author: alex.guizar(a)jboss.com
Date: 2009-04-25 17:53:13 -0400 (Sat, 25 Apr 2009)
New Revision: 4619
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressBuilderImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/AddressBuilder.java
Removed:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/GivenSpaceFamilyNameBuilder.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailProducer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/RecipientNameBuilder.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ArrayUtil.java
Modified:
jbpm4/trunk/modules/pvm/pom.xml
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailSessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/RecipientTemplate.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailSession.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/impl/AddressFilterTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java
jbpm4/trunk/pom.xml
Log:
removed commons-email dependency in favor of plain javamail
Modified: jbpm4/trunk/modules/pvm/pom.xml
===================================================================
--- jbpm4/trunk/modules/pvm/pom.xml 2009-04-25 10:19:40 UTC (rev 4618)
+++ jbpm4/trunk/modules/pvm/pom.xml 2009-04-25 21:53:13 UTC (rev 4619)
@@ -57,10 +57,6 @@
</dependency>
<dependency>
- <groupId>commons-email</groupId>
- <artifactId>commons-email</artifactId>
- </dependency>
- <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
@@ -104,6 +100,10 @@
<artifactId>livetribe-jsr223</artifactId>
</dependency>
<dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<scope>provided</scope>
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressBuilderImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressBuilderImpl.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressBuilderImpl.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.email.impl;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.mail.Address;
+import javax.mail.internet.InternetAddress;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.identity.User;
+import org.jbpm.pvm.internal.email.spi.AddressBuilder;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class AddressBuilderImpl implements AddressBuilder {
+
+ public Address buildAddress(User user) {
+ String givenName = user.getGivenName();
+ String familyName = user.getFamilyName();
+ String personal =
+ givenName != null ? familyName != null ? givenName + ' ' + familyName :
givenName
+ : familyName;
+ try {
+ return new InternetAddress(user.getEmailAddress(), personal);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new JbpmException("invalid recipient name: " + personal);
+ }
+ }
+
+}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,12 +1,10 @@
package org.jbpm.pvm.internal.email.impl;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import java.util.regex.Pattern;
-import javax.mail.internet.InternetAddress;
+import javax.mail.Address;
/**
* Allows filtering of to/cc/bcc recipient lists based on regular expressions for include
and
@@ -25,17 +23,15 @@
*/
private List<Pattern> excludePatterns;
- public Collection<InternetAddress> filter(final Collection<InternetAddress>
addresses) {
- Collection<InternetAddress> filteredAddresses = new
HashSet<InternetAddress>();
- if (addresses != null) {
- // Loop over for addresses to decide what to keep.
- for (InternetAddress address : addresses) {
- if (includeAddress(address) && !excludeAddress(address)) {
- filteredAddresses.add(address);
- }
+ public Address[] filter(Address... addresses) {
+ List<Address> filteredAddresses = new ArrayList<Address>();
+ // Loop over for addresses to decide what to keep.
+ for (Address address : addresses) {
+ if (includeAddress(address) && !excludeAddress(address)) {
+ filteredAddresses.add(address);
}
}
- return filteredAddresses;
+ return filteredAddresses.toArray(new Address[filteredAddresses.size()]);
}
/**
@@ -43,9 +39,9 @@
*
* @param address email address to match against regex
* @return <code>false</code> if include patterns are present and the
address does not match any
- * pattern, <code>true</code> otherwise
+ * pattern, <code>true</code> otherwise
*/
- protected boolean includeAddress(InternetAddress address) {
+ protected boolean includeAddress(Address address) {
if (includePatterns == null || includePatterns.isEmpty()) return true;
for (Pattern pattern : includePatterns) {
if (pattern.matcher(address.toString()).matches()) return true;
@@ -58,9 +54,9 @@
*
* @param address email address to match against regex
* @return <code>true</code> if exclude patterns are present and the
address matches a pattern,
- * <code>false</code> otherwise
+ * <code>false</code> otherwise
*/
- protected boolean excludeAddress(InternetAddress address) {
+ protected boolean excludeAddress(Address address) {
if (excludePatterns == null) return false;
for (Pattern pattern : excludePatterns) {
if (pattern.matcher(address.toString()).matches()) return true;
Deleted:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/GivenSpaceFamilyNameBuilder.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/GivenSpaceFamilyNameBuilder.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/GivenSpaceFamilyNameBuilder.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.email.impl;
-
-import org.jbpm.api.identity.User;
-import org.jbpm.pvm.internal.email.spi.RecipientNameBuilder;
-
-/**
- * @author Alejandro Guizar
- */
-public class GivenSpaceFamilyNameBuilder implements RecipientNameBuilder {
-
- public String buildName(User user) {
- String givenName = user.getGivenName();
- String familyName = user.getFamilyName();
-
- return givenName != null ? familyName != null ? givenName + ' ' + familyName :
givenName
- : familyName;
- }
-
-}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -28,19 +28,26 @@
import java.util.Collections;
import java.util.List;
-import org.apache.commons.mail.Email;
-import org.apache.commons.mail.EmailAttachment;
-import org.apache.commons.mail.EmailException;
-import org.apache.commons.mail.HtmlEmail;
-import org.apache.commons.mail.MultiPartEmail;
-import org.apache.commons.mail.SimpleEmail;
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.mail.Address;
+import javax.mail.BodyPart;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Session;
+import javax.mail.Message.RecipientType;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import org.jbpm.api.Execution;
import org.jbpm.api.JbpmException;
import org.jbpm.api.env.Environment;
-import org.jbpm.api.identity.Group;
import org.jbpm.api.identity.User;
-import org.jbpm.api.model.OpenExecution;
+import org.jbpm.pvm.internal.email.spi.AddressBuilder;
import org.jbpm.pvm.internal.email.spi.MailProducer;
-import org.jbpm.pvm.internal.email.spi.RecipientNameBuilder;
import org.jbpm.pvm.internal.identity.spi.IdentitySession;
import org.jbpm.pvm.internal.script.ScriptManager;
@@ -61,171 +68,245 @@
this.template = template;
}
- public Collection<Email> produce(OpenExecution execution) {
- try {
- Email email = instantiateEmail(template);
- fillRecipients(template, execution, email);
- fillSubject(execution, email);
- fillBody(execution, email);
- return Collections.singleton(email);
- }
- catch (EmailException e) {
- throw new JbpmException("could not produce email", e);
- }
+ public Collection<Message> produce(Execution execution) {
+ Message email = instantiateEmail();
+ fillRecipients(execution, email);
+ fillSubject(execution, email);
+ fillContent(execution, email);
+ return Collections.singleton(email);
}
- protected Email instantiateEmail(MailTemplate template) {
- return template.getHtml() != null ? new HtmlEmail() :
template.getAttachmentTemplates()
- .isEmpty() ? new MultiPartEmail() : new SimpleEmail();
+ protected Message instantiateEmail() {
+ return new MimeMessage((Session) null);
}
- protected void fillRecipients(MailTemplate template, OpenExecution execution, Email
email)
- throws EmailException {
- Environment environment = Environment.getCurrent();
- IdentitySession identitySession = environment.get(IdentitySession.class);
- RecipientNameBuilder recipientNameBuilder =
environment.get(RecipientNameBuilder.class);
-
+ protected void fillRecipients(Execution execution, Message email) {
// to
RecipientTemplate to = template.getTo();
- if (to != null) {
- for (String address : evaluateRecipients(to.getAddresses(), execution)) {
- email.addTo(address);
- }
- for (String actorId : evaluateRecipients(to.getActors(), execution)) {
- Collection<User> users = resolveUsers(identitySession, actorId);
- for (User user : users) {
- email.addTo(user.getEmailAddress(), recipientNameBuilder.buildName(user));
- }
- }
- }
+ if (to != null) fillRecipients(to, execution, email, RecipientType.TO);
// cc
RecipientTemplate cc = template.getCc();
- if (cc != null) {
- for (String address : evaluateRecipients(cc.getAddresses(), execution)) {
- email.addCc(address);
- }
- for (String actorId : evaluateRecipients(cc.getActors(), execution)) {
- Collection<User> users = resolveUsers(identitySession, actorId);
- for (User user : users) {
- email.addCc(user.getEmailAddress(), recipientNameBuilder.buildName(user));
- }
- }
- }
+ if (cc != null) fillRecipients(cc, execution, email, RecipientType.CC);
// bcc
RecipientTemplate bcc = template.getBcc();
- if (bcc != null) {
- for (String address : evaluateRecipients(bcc.getAddresses(), execution)) {
- email.addBcc(address);
+ if (bcc != null) fillRecipients(bcc, execution, email, RecipientType.BCC);
+ }
+
+ private void fillRecipients(RecipientTemplate template, Execution execution, Message
email,
+ RecipientType recipientType) {
+ // addresses
+ String addressList = evaluateExpression(template.getAddresses(), execution);
+ try {
+ Address[] addresses = InternetAddress.parse(addressList);
+ email.addRecipients(recipientType, addresses);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add "
+ + addressList
+ + " to recipients of type "
+ + recipientType, e);
+ }
+
+ Environment environment = Environment.getCurrent();
+ IdentitySession identitySession = environment.get(IdentitySession.class);
+ AddressBuilder addressBuilder = environment.get(AddressBuilder.class);
+ // users
+ for (String userId : evaluateRecipients(template.getUsers(), execution)) {
+ User user = identitySession.findUserById(userId);
+ addRecipient(addressBuilder.buildAddress(user), email, recipientType);
+ }
+ // groups
+ for (String groupId : evaluateRecipients(template.getGroups(), execution)) {
+ Collection<User> users = identitySession.findUsersByGroup(groupId);
+ for (User user : users) {
+ addRecipient(addressBuilder.buildAddress(user), email, recipientType);
}
- for (String actorId : evaluateRecipients(bcc.getActors(), execution)) {
- Collection<User> users = resolveUsers(identitySession, actorId);
- for (User user : users) {
- email.addBcc(user.getEmailAddress(), recipientNameBuilder.buildName(user));
- }
- }
}
}
- private String evaluateExpression(String expression, OpenExecution execution) {
+ private String evaluateExpression(String expression, Execution execution) {
ScriptManager scriptManager = Environment.getFromCurrent(ScriptManager.class);
return scriptManager.evaluateExpression(expression, execution,
template.getLanguage())
.toString();
}
- private String[] evaluateRecipients(String recipients, OpenExecution execution) {
+ private String[] evaluateRecipients(String recipients, Execution execution) {
return evaluateExpression(recipients, execution).split("[,|\\s]+");
}
- private static Collection<User> resolveUsers(IdentitySession identitySession,
String actorId) {
- // first, try to resolve actorId as user
- User user = identitySession.findUserById(actorId);
- if (user != null) return Collections.singleton(user);
-
- // next, try to resolve as group
- Group group = identitySession.findGroupById(actorId);
- if (group != null) return identitySession.findUsersByGroup(actorId);
-
- // give up
- return Collections.emptySet();
+ private static void addRecipient(Address address, Message email, RecipientType
recipientType) {
+ try {
+ email.addRecipient(recipientType, address);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add "
+ + address
+ + " to recipients of type "
+ + recipientType, e);
+ }
}
- protected void fillSubject(OpenExecution execution, Email email) {
- email.setSubject(evaluateExpression(template.getSubject(), execution));
+ protected void fillSubject(Execution execution, Message email) {
+ String subject = evaluateExpression(template.getSubject(), execution);
+ try {
+ email.setSubject(subject);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to set subject to " + subject, e);
+ }
}
- protected void fillBody(OpenExecution execution, Email email) throws EmailException {
- if (template.getHtml() == null) {
- email.setMsg(evaluateExpression(template.getText(), execution));
+ protected void fillContent(Execution execution, Message email) {
+ String html = template.getHtml();
+ List<AttachmentTemplate> attachmentTemplates =
template.getAttachmentTemplates();
+
+ if (html != null || !attachmentTemplates.isEmpty()) {
+ // multipart
+ Multipart multipart = new MimeMultipart("related");
+
+ // text
+ if (template.getText() != null) {
+ BodyPart textPart = new MimeBodyPart();
+ String text = evaluateExpression(template.getText(), execution);
+ try {
+ textPart.setText(text);
+ multipart.addBodyPart(textPart);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add text content: " + text, e);
+ }
+ }
+
+ // html
+ if (html != null) {
+ BodyPart htmlPart = new MimeBodyPart();
+ html = evaluateExpression(html, execution);
+ try {
+ htmlPart.setContent(html, "text/html");
+ multipart.addBodyPart(htmlPart);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add html content: " + html, e);
+ }
+ }
+
+ // attachments
+ if (!attachmentTemplates.isEmpty()) {
+ addAttachments(execution, multipart);
+ }
+
+ try {
+ email.setContent(multipart);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to set multipart content: " +
multipart, e);
+ }
}
else {
- HtmlEmail htmlEmail = (HtmlEmail) email;
- htmlEmail.setHtmlMsg(evaluateExpression(template.getHtml(), execution));
- htmlEmail.setTextMsg(evaluateExpression(template.getText(), execution));
+ // unipart
+ String text = evaluateExpression(template.getText(), execution);
+ try {
+ email.setText(text);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add text content: " + text, e);
+ }
}
}
- protected void addAttachments(OpenExecution execution, Email email) throws
EmailException {
- List<AttachmentTemplate> attachmentTemplates =
template.getAttachmentTemplates();
- if (attachmentTemplates.isEmpty()) return;
+ protected void addAttachments(Execution execution, Multipart multipart) {
+ for (AttachmentTemplate attachmentTemplate : template.getAttachmentTemplates()) {
+ BodyPart attachmentPart = new MimeBodyPart();
- MultiPartEmail multiPartEmail = (MultiPartEmail) email;
- for (AttachmentTemplate attachmentTemplate : attachmentTemplates) {
- EmailAttachment attachment = new EmailAttachment();
- attachment.setDisposition(EmailAttachment.ATTACHMENT);
+ // resolve and set description
+ String description = attachmentTemplate.getDescription();
+ if (description != null) {
+ description = evaluateExpression(description, execution);
+ try {
+ attachmentPart.setDescription(description);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to set attachment description: " +
description, e);
+ }
+ }
- // name
+ // resolve name; if absent, it will be taken from file or url
String name = attachmentTemplate.getName();
- if (name != null) attachment.setName(evaluateExpression(name, execution));
+ if (name != null) {
+ name = evaluateExpression(name, execution);
+ }
- // description
- String description = attachmentTemplate.getDescription();
- if (description != null)
- attachment.setDescription(evaluateExpression(description, execution));
-
- // file
+ // resolve and read file
String file = attachmentTemplate.getFile();
if (file != null) {
File targetFile = new File(evaluateExpression(file, execution));
if (!targetFile.isFile()) {
- throw new EmailException("could not fetch attachment from " +
targetFile);
+ throw new JbpmException("could not read attachment content, file not
found: "
+ + targetFile);
}
- attachment.setPath(targetFile.getPath());
- // extract attachment name from file
- if (name == null) attachment.setName(targetFile.getName());
+ // set content from target file
+ try {
+ attachmentPart.setDataHandler(new DataHandler(new
FileDataSource(targetFile)));
+ // extract attachment name from file
+ if (name == null) {
+ name = targetFile.getName();
+ }
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add attachment content: " +
targetFile, e);
+ }
}
else {
URL targetUrl;
- // url
+ // resolve and read external url
String url = attachmentTemplate.getUrl();
if (url != null) {
try {
- targetUrl = new URL(evaluateExpression(url, execution));
+ url = evaluateExpression(url, execution);
+ targetUrl = new URL(url);
}
catch (MalformedURLException e) {
- throw new EmailException("could not fetch attachment from " + url,
e);
+ throw new JbpmException("could not read attachment content, malformed
url: " + url, e);
}
}
- // resource
+ // resolve and read classpath resource
else {
- String resource = attachmentTemplate.getResource();
- targetUrl =
- Environment.getCurrent().getClassLoader().getResource(
- evaluateExpression(resource, execution));
+ String resource = evaluateExpression(attachmentTemplate.getResource(),
execution);
+ targetUrl = Environment.getCurrent().getClassLoader().getResource(resource);
if (targetUrl == null) {
- throw new EmailException("could not fetch attachment from " +
resource);
+ throw new JbpmException("could not read attachment content, resource not
found: "
+ + resource);
}
}
- attachment.setURL(targetUrl);
- // extract attachment name from url
- if (name == null) {
- String resourceName = extractResourceName(targetUrl);
- attachment.setName(resourceName);
+ // set content from url
+ try {
+ attachmentPart.setDataHandler(new DataHandler(targetUrl));
+ // extract attachment name from target url
+ if (name == null) {
+ name = extractResourceName(targetUrl);
+ }
}
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add attachment content: " +
targetUrl, e);
+ }
}
- multiPartEmail.attach(attachment);
+ // set name, must be resolved at this point
+ try {
+ attachmentPart.setFileName(name);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to set attachment name: " + name, e);
+ }
+
+ try {
+ multipart.addBodyPart(attachmentPart);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to add attachment part: " +
attachmentPart, e);
+ }
}
}
@@ -233,10 +314,7 @@
String path = url.getPath();
if (path == null || path.length() == 0) return null;
- // skip trailing slash
- int sepIndex = path.lastIndexOf('/', path.length() - 1);
- if (sepIndex == -1) return null;
-
- return path.substring(sepIndex);
+ int sepIndex = path.lastIndexOf('/');
+ return sepIndex != -1 ? path.substring(sepIndex) : null;
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -40,7 +40,7 @@
this.authenticator = authenticator;
}
- public Session createMailSession() {
+ public Session getMailSession() {
return Session.getDefaultInstance(sessionProperties, authenticator);
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailSessionImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailSessionImpl.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailSessionImpl.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -3,60 +3,49 @@
import java.util.Collection;
import java.util.List;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
import javax.mail.Session;
-import javax.mail.internet.InternetAddress;
+import javax.mail.Message.RecipientType;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.mail.Email;
-import org.apache.commons.mail.EmailException;
+import org.jbpm.api.JbpmException;
import org.jbpm.pvm.internal.email.spi.MailSession;
public class MailSessionImpl implements MailSession {
private List<MailServer> mailServers;
- private static final Log log = LogFactory.getLog(MailSessionImpl.class);
-
- public void send(Collection<Email> emails) {
+ public void send(Collection<Message> emails) {
// Emails need to have the sessions populated.
- for (Email email : emails) {
- Collection<InternetAddress> to = email.getToAddresses();
- Collection<InternetAddress> cc = email.getCcAddresses();
- Collection<InternetAddress> bcc = email.getBccAddresses();
+ for (Message email : emails) {
+ try {
+ Address[] to = email.getRecipients(RecipientType.TO);
+ Address[] cc = email.getRecipients(RecipientType.CC);
+ Address[] bcc = email.getRecipients(RecipientType.BCC);
- for (MailServer mailServer : mailServers) {
- AddressFilter addressFilter = mailServer.getAddressFilter();
- Session mailSession = mailServer.createMailSession();
- email.setMailSession(mailSession);
+ for (MailServer mailServer : mailServers) {
+ AddressFilter addressFilter = mailServer.getAddressFilter();
+ Session mailSession = mailServer.getMailSession();
- // Need to apply filter.
- try {
- if(addressFilter!=null) {
- Collection<InternetAddress> toFiltered = addressFilter.filter(to);
- Collection<InternetAddress> ccFiltered = addressFilter.filter(cc);
- Collection<InternetAddress> bccFiltered = addressFilter.filter(bcc);
-
- // Set the email with the new filtered addresses.
- email.setTo(toFiltered);
- email.setCc(ccFiltered);
- email.setBcc(bccFiltered);
-
- // If there is someone to send it to, then send it.
- if (!(toFiltered.isEmpty() && ccFiltered.isEmpty() &&
bccFiltered.isEmpty())) {
- email.send();
- }
+ // Need to apply filter.
+ if (addressFilter != null) {
+ // Set the email with the new filtered addresses.
+ email.setRecipients(RecipientType.TO, addressFilter.filter(to));
+ email.setRecipients(RecipientType.CC, addressFilter.filter(cc));
+ email.setRecipients(RecipientType.BCC, addressFilter.filter(bcc));
}
- else {
- //If no filter is set, then accept all.
- email.send();
+
+ // If there is someone to send it to, then send it.
+ Address[] recipients = email.getAllRecipients();
+ if (recipients.length > 0) {
+ mailSession.getTransport().sendMessage(email, recipients);
}
}
- catch (EmailException e) {
- log.error("An exception occurred while sending email.", e);
- // TODO: Does anything else need to occur here?
- }
}
+ catch (MessagingException e) {
+ throw new JbpmException("could not send email: " + email, e);
+ }
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/RecipientTemplate.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/RecipientTemplate.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/RecipientTemplate.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -22,29 +22,38 @@
package org.jbpm.pvm.internal.email.impl;
/**
- * Template for email recipients, either addresses or actors.
+ * Template for email recipients: addresses, users and groups.
*
* @author Alejandro Guizar
*/
public class RecipientTemplate {
- private String addresses;
- private String actors;
+ private String addresses;
+ private String users;
+ private String groups;
- public String getAddresses() {
- return addresses;
- }
+ public String getAddresses() {
+ return addresses;
+ }
- public void setAddresses(String addresses) {
- this.addresses = addresses;
- }
+ public void setAddresses(String addresses) {
+ this.addresses = addresses;
+ }
- public String getActors() {
- return actors;
- }
+ public String getUsers() {
+ return users;
+ }
- public void setActors(String actors) {
- this.actors = actors;
- }
+ public void setUsers(String users) {
+ this.users = users;
+ }
+ public String getGroups() {
+ return groups;
+ }
+
+ public void setGroups(String groups) {
+ this.groups = groups;
+ }
+
}
Deleted:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,46 +0,0 @@
-package org.jbpm.pvm.internal.email.producer;
-
-import java.util.Collection;
-
-import org.jbpm.api.identity.Group;
-import org.jbpm.api.identity.User;
-
-public class MailContext {
-
- private Collection<User> actors;
- private Collection<Group> groups;
- private Collection<String> toAddresses;
- private Collection<String> ccAddresses;
- private Collection<String> bccAddresses;
- public Collection<User> getActors() {
- return actors;
- }
- public void setActors(Collection<User> actors) {
- this.actors = actors;
- }
- public Collection<Group> getGroups() {
- return groups;
- }
- public void setGroups(Collection<Group> groups) {
- this.groups = groups;
- }
- public Collection<String> getToAddresses() {
- return toAddresses;
- }
- public void setToAddresses(Collection<String> toAddresses) {
- this.toAddresses = toAddresses;
- }
- public Collection<String> getCcAddresses() {
- return ccAddresses;
- }
- public void setCcAddresses(Collection<String> ccAddresses) {
- this.ccAddresses = ccAddresses;
- }
- public Collection<String> getBccAddresses() {
- return bccAddresses;
- }
- public void setBccAddresses(Collection<String> bccAddresses) {
- this.bccAddresses = bccAddresses;
- }
-
-}
Deleted:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailProducer.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailProducer.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailProducer.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,12 +0,0 @@
-package org.jbpm.pvm.internal.email.producer;
-
-import java.util.Collection;
-
-import org.apache.commons.mail.Email;
-import org.jbpm.api.Execution;
-
-public interface MailProducer {
-
- public Collection<Email> produce(final Execution exe, final MailContext
mailContext) throws Exception;
-
-}
\ No newline at end of file
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/AddressBuilder.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/AddressBuilder.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/AddressBuilder.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.email.spi;
+
+import javax.mail.Address;
+
+import org.jbpm.api.identity.User;
+
+/**
+ * @author Alejandro Guizar
+ */
+public interface AddressBuilder {
+
+ Address buildAddress(User user);
+}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailProducer.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -23,17 +23,18 @@
import java.util.Collection;
-import org.apache.commons.mail.Email;
-import org.jbpm.api.model.OpenExecution;
+import javax.mail.Message;
+import org.jbpm.api.Execution;
+
/**
- * Pluggable control object for creating emails from templates.
+ * Pluggable control object for creating email messages from templates.
*
* @author Brad Davis
* @author Alejandro Guizar
*/
public interface MailProducer {
- Collection<Email> produce(OpenExecution execution);
+ Collection<Message> produce(Execution execution);
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailSession.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailSession.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/MailSession.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -2,7 +2,7 @@
import java.util.Collection;
-import org.apache.commons.mail.Email;
+import javax.mail.Message;
/**
* Pluggable control object for sending emails.
@@ -11,6 +11,6 @@
*/
public interface MailSession {
- void send(Collection<Email> emails);
+ void send(Collection<Message> emails);
}
Deleted:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/RecipientNameBuilder.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/RecipientNameBuilder.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/spi/RecipientNameBuilder.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.email.spi;
-
-import org.jbpm.api.identity.User;
-
-/**
- * Function to create email recipient names from {@linkplain User user} entities. The
following two
- * strategies are representative.
- * <ul>
- * <li>Albert Einstein (given name + ' ' + family name)</li>
- * <li>Einstein, Albert (family name + ", " + given name)</li>
- * </ul>
- *
- * @author Alejandro Guizar
- */
-public interface RecipientNameBuilder {
-
- String buildName(User user);
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ArrayUtil.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ArrayUtil.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ArrayUtil.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,26 +0,0 @@
-package org.jbpm.pvm.internal.util;
-
-public class ArrayUtil {
-
- public static String toString(Object[] array) {
- if (array==null) {
- return "null";
- } else {
- StringBuffer buffer = new StringBuffer();
- buffer.append("[");
- for (int i=0; i<array.length; i++) {
- Object o = array[i];
- if (o!=null) {
- buffer.append(o);
- } else {
- buffer.append("null");
- }
- if (i!=array.length-1) {
- buffer.append("|");
- }
- }
- buffer.append("]");
- return buffer.toString();
- }
- }
-}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -6,6 +6,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
@@ -115,7 +116,7 @@
try {
constructor = clazz.getDeclaredConstructor(parameterTypes);
- if (log.isTraceEnabled()) log.trace("found constructor
"+clazz.getName()+"("+ArrayUtil.toString(parameterTypes)+")");
+ if (log.isTraceEnabled()) log.trace("found constructor
"+clazz.getName()+"("+Arrays.toString(parameterTypes)+")");
} catch (SecurityException e) {
throw new JbpmException("wasn't allowed to get constructor
'"+clazz.getName()+"("+getParameterTypesText(parameterTypes)+")'",
e);
@@ -160,7 +161,7 @@
method = clazz.getDeclaredMethod(methodName, parameterTypes);
if (log.isTraceEnabled())
- log.trace("found method
"+clazz.getName()+"."+methodName+"("+ArrayUtil.toString(parameterTypes)+")");
+ log.trace("found method
"+clazz.getName()+"."+methodName+"("+Arrays.toString(parameterTypes)+")");
} catch (SecurityException e) {
throw new JbpmException("wasn't allowed to get method
'"+clazz.getName()+"."+methodName+"("+getParameterTypesText(parameterTypes)+")'",
e);
@@ -207,7 +208,7 @@
String className = null;
try {
- log.trace("creating new instance for class '"+className+"'
with args "+ArrayUtil.toString(args));
+ log.trace("creating new instance for class '"+className+"'
with args "+Arrays.toString(args));
if (constructor==null) {
log.trace("getting default constructor");
constructor = clazz.getConstructor((Class[])null);
@@ -220,7 +221,7 @@
return constructor.newInstance(args);
} catch (Throwable t) {
- throw new JbpmException("couldn't construct new
'"+className+"' with args "+ArrayUtil.toString(args), t);
+ throw new JbpmException("couldn't construct new
'"+className+"' with args "+Arrays.toString(args), t);
}
}
@@ -258,7 +259,7 @@
throw new JbpmException("method is null");
}
try {
- log.trace("invoking '"+method.getName()+"' on
'"+target+"' with "+ArrayUtil.toString(args));
+ log.trace("invoking '"+method.getName()+"' on
'"+target+"' with "+Arrays.toString(args));
if (!method.isAccessible()) {
log.trace("making method accessible");
method.setAccessible(true);
@@ -266,9 +267,9 @@
return method.invoke(target, args);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
- throw new JbpmException("couldn't invoke
'"+method.getName()+"' with "+ArrayUtil.toString(args)+" on
"+target+": "+targetException.getMessage(), targetException);
+ throw new JbpmException("couldn't invoke
'"+method.getName()+"' with "+Arrays.toString(args)+" on
"+target+": "+targetException.getMessage(), targetException);
} catch (Exception e) {
- throw new JbpmException("couldn't invoke
'"+method.getName()+"' with "+ArrayUtil.toString(args)+" on
"+target+": "+e.getMessage(), e);
+ throw new JbpmException("couldn't invoke
'"+method.getName()+"' with "+Arrays.toString(args)+" on
"+target+": "+e.getMessage(), e);
}
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -142,11 +142,15 @@
ObjectDescriptor recipientDescriptor = new
ObjectDescriptor(RecipientTemplate.class);
String addresses = XmlUtil.attribute(element, "addresses");
- if (addresses != null) recipientDescriptor.addInjection("addresses", new
StringDescriptor(addresses));
+ if (addresses != null)
+ recipientDescriptor.addInjection("addresses", new
StringDescriptor(addresses));
- String actors = XmlUtil.attribute(element, "actors");
- if (actors != null) recipientDescriptor.addInjection("actors", new
StringDescriptor(actors));
+ String users = XmlUtil.attribute(element, "users");
+ if (users != null) recipientDescriptor.addInjection("users", new
StringDescriptor(users));
+ String groups = XmlUtil.attribute(element, "groups");
+ if (groups != null) recipientDescriptor.addInjection("groups", new
StringDescriptor(groups));
+
return recipientDescriptor;
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -5,12 +5,12 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.jbpm.api.JbpmException;
import org.jbpm.api.env.Environment;
import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.util.ArrayUtil;
import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
@@ -146,7 +146,7 @@
Object[] args = getArgs(wireContext, argDescriptors);
Constructor<?> constructor = ReflectUtil.findConstructor(clazz,
argDescriptors, args);
if (constructor==null) {
- throw new WireException("couldn't find constructor
"+clazz.getName()+" with args "+ArrayUtil.toString(args));
+ throw new WireException("couldn't find constructor
"+clazz.getName()+" with args "+Arrays.toString(args));
}
object = constructor.newInstance(args);
} catch (WireException e) {
Modified:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/impl/AddressFilterTest.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/impl/AddressFilterTest.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/impl/AddressFilterTest.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -1,90 +1,81 @@
package org.jbpm.pvm.internal.email.impl;
-import java.util.Collection;
-import java.util.HashSet;
+import java.util.Arrays;
+import java.util.List;
import java.util.regex.Pattern;
+import javax.mail.Address;
import javax.mail.internet.InternetAddress;
import junit.framework.TestCase;
-public class AddressFilterTest extends TestCase{
+public class AddressFilterTest extends TestCase {
- /**
- * When no filter is provided, all addresses should be contained in the filtered list.
- */
- public void testWildCardIncludesNoFilters() throws Exception
- {
- AddressFilter filter = new AddressFilter();
-
- Collection<InternetAddress> addresses = new HashSet<InternetAddress>();
- addresses.add(new InternetAddress("test(a)jboss.org"));
-
- Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
- assertTrue(filteredAddresses.contains(new
InternetAddress("test(a)jboss.org")));
- }
-
- /**
- * If the includes is provided, no other addresses except those explicitly listed should
- * be included in the filtered list.
- */
- public void testWildCardIncludes() throws Exception
- {
- AddressFilter filter = new AddressFilter();
-
- Collection<InternetAddress> addresses = new HashSet<InternetAddress>();
- addresses.add(new InternetAddress("test(a)jboss.org"));
- addresses.add(new InternetAddress("test(a)amentra.com"));
-
- filter.addIncludePattern(Pattern.compile(".+(a)jboss.org"));
-
- Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
- assertTrue(filteredAddresses.contains(new
InternetAddress("test(a)jboss.org")));
- assertTrue(!filteredAddresses.contains(new
InternetAddress("test(a)amentra.com")));
- }
-
- /**
- * The includes should always override the excludes.
- */
- public void testWildCardIncludesOverridesExcludes() throws Exception
- {
- AddressFilter filter = new AddressFilter();
-
- Collection<InternetAddress> addresses = new HashSet<InternetAddress>();
- addresses.add(new InternetAddress("test(a)jboss.org"));
- addresses.add(new InternetAddress("test(a)amentra.com"));
-
- filter.addIncludePattern(Pattern.compile(".+(a)jboss.org"));
- filter.addExcludePattern(Pattern.compile(".+(a)amentra.com"));
-
- Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
- //Includes jboss
- assertTrue(filteredAddresses.contains(new
InternetAddress("test(a)jboss.org")));
- //Does not include amentra.
- assertTrue(!filteredAddresses.contains(new
InternetAddress("test(a)amentra.com")));
- }
-
- /**
- * When the excludes is specified but no includes, all addresses except those explicitly
stated
- * should be contained in the filtered set.
- */
- public void testWildCardExcludes() throws Exception
- {
- AddressFilter filter = new AddressFilter();
-
- Collection<InternetAddress> addresses = new HashSet<InternetAddress>();
- addresses.add(new InternetAddress("test(a)jboss.org"));
- addresses.add(new InternetAddress("test(a)amentra.com"));
- addresses.add(new InternetAddress("test(a)redhat.com"));
-
- filter.addExcludePattern(Pattern.compile(".+(a)jboss.org"));
-
- Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
- //Does not include jboss
- assertTrue(!filteredAddresses.contains(new
InternetAddress("test(a)jboss.org")));
- //Does include amentra
- assertTrue(filteredAddresses.contains(new
InternetAddress("test(a)amentra.com")));
- //Does include redhat
- assertTrue(filteredAddresses.contains(new
InternetAddress("test(a)redhat.com")));
- }
+ /**
+ * When no filter is provided, all addresses should be contained in the filtered list.
+ */
+ public void testWildCardIncludesNoFilters() throws Exception {
+ AddressFilter filter = new AddressFilter();
+
+ InternetAddress jbossAddress = new InternetAddress("test(a)jboss.org");
+ List<Address> filterAddresses = Arrays.asList(filter.filter(jbossAddress));
+
+ assertTrue(filterAddresses.contains(jbossAddress));
+ }
+
+ /**
+ * If the includes is provided, no other addresses except those explicitly listed
should be
+ * included in the filtered list.
+ */
+ public void testWildCardIncludes() throws Exception {
+ AddressFilter filter = new AddressFilter();
+ filter.addIncludePattern(Pattern.compile(".+(a)jboss.org"));
+
+ InternetAddress jbossAddress = new InternetAddress("test(a)jboss.org");
+ InternetAddress amentraAddress = new InternetAddress("test(a)amentra.com");
+ List<Address> filterAddresses = Arrays.asList(filter.filter(jbossAddress,
amentraAddress));
+
+ assertTrue(filterAddresses.contains(jbossAddress));
+ assertFalse(filterAddresses.contains(amentraAddress));
+ }
+
+ /**
+ * The includes should always override the excludes.
+ */
+ public void testWildCardIncludesOverridesExcludes() throws Exception {
+ AddressFilter filter = new AddressFilter();
+ filter.addIncludePattern(Pattern.compile(".+(a)jboss.org"));
+ filter.addExcludePattern(Pattern.compile(".+(a)amentra.com"));
+
+ InternetAddress jbossAddress = new InternetAddress("test(a)jboss.org");
+ InternetAddress amentraAddress = new InternetAddress("test(a)amentra.com");
+ List<Address> filterAddresses = Arrays.asList(filter.filter(jbossAddress,
amentraAddress));
+
+ // Includes jboss
+ assertTrue(filterAddresses.contains(jbossAddress));
+ // Does not include amentra.
+ assertFalse(filterAddresses.contains(amentraAddress));
+ }
+
+ /**
+ * When the excludes is specified but no includes, all addresses except those
explicitly stated
+ * should be contained in the filtered set.
+ */
+ public void testWildCardExcludes() throws Exception {
+ AddressFilter filter = new AddressFilter();
+ filter.addExcludePattern(Pattern.compile(".+(a)jboss.org"));
+
+ InternetAddress jbossAddress = new InternetAddress("test(a)jboss.org");
+ InternetAddress amentraAddress = new InternetAddress("test(a)amentra.com");
+ InternetAddress redhatAddress = new InternetAddress("test(a)redhat.com");
+ List<Address> filterAddresses =
+ Arrays.asList(filter.filter(jbossAddress, amentraAddress, redhatAddress));
+
+ // Does not include jboss
+ assertFalse(filterAddresses.contains(jbossAddress));
+ // Does include amentra
+ assertTrue(filterAddresses.contains(amentraAddress));
+ // Does include redhat
+ assertTrue(filterAddresses.contains(redhatAddress));
+ }
}
Modified:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java 2009-04-25
10:19:40 UTC (rev 4618)
+++
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailTemplateWireTest.java 2009-04-25
21:53:13 UTC (rev 4619)
@@ -75,13 +75,13 @@
createWireContext("<objects>"
+ "<mail-template name='plate'>"
+ " <to addresses='dilbert@office, alice@work,
dogbert@house'/>"
- + " <cc actors='theboss, hrpolicymaker'/>"
+ + " <cc users='theboss, hrpolicymaker'/>"
+ " <subject>bureaucracy</subject>"
+ "</mail-template>"
+ "</objects>");
MailTemplate template = wireContext.get(MailTemplate.class);
- assertEquals("theboss, hrpolicymaker", template.getCc().getActors());
+ assertEquals("theboss, hrpolicymaker", template.getCc().getUsers());
}
public void testBcc() {
@@ -89,13 +89,13 @@
createWireContext("<objects>"
+ "<mail-template name='plate'>"
+ " <to addresses='dilbert@office, alice@work,
dogbert@house'/>"
- + " <bcc actors='thoughtpolice'/>"
+ + " <bcc groups='thoughtpolice'/>"
+ " <subject>bureaucracy</subject>"
+ "</mail-template>"
+ "</objects>");
MailTemplate template = wireContext.get(MailTemplate.class);
- assertEquals("thoughtpolice", template.getBcc().getActors());
+ assertEquals("thoughtpolice", template.getBcc().getGroups());
}
public void testSubject() {
Modified: jbpm4/trunk/pom.xml
===================================================================
--- jbpm4/trunk/pom.xml 2009-04-25 10:19:40 UTC (rev 4618)
+++ jbpm4/trunk/pom.xml 2009-04-25 21:53:13 UTC (rev 4619)
@@ -47,7 +47,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<apache.ant.version>1.7.0</apache.ant.version>
<cactus.version>13-1.7.1</cactus.version>
- <commons.email.version>1.2-SNAPSHOT</commons.email.version>
<gwt.console.version>1.0.0-SNAPSHOT</gwt.console.version>
<hibernate.version>3.2.6.ga</hibernate.version>
<hibernate.annotations.version>3.3.1.GA</hibernate.annotations.version>
@@ -61,6 +60,7 @@
<juel.version>2.1.0</juel.version>
<junit.version>3.8.1</junit.version>
<log4j.version>1.2.14</log4j.version>
+ <mail.version>1.4.1</mail.version>
<servlet-api.version>2.5</servlet-api.version>
<spring.version>2.5.4</spring.version>
<stax.api.version>1.0.1</stax.api.version>
@@ -285,6 +285,11 @@
<version>${jsr233.version}</version>
</dependency>
<dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>${mail.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>${spring.version}</version>
@@ -316,11 +321,6 @@
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
</dependency>
- <dependency>
- <groupId>commons-email</groupId>
- <artifactId>commons-email</artifactId>
- <version>${commons.email.version}</version>
- </dependency>
</dependencies>
</dependencyManagement>