diff --git a/modules/flowable5-engine/pom.xml b/modules/flowable5-engine/pom.xml
index a0f78d758e6..11fa0ccc13b 100644
--- a/modules/flowable5-engine/pom.xml
+++ b/modules/flowable5-engine/pom.xml
@@ -31,8 +31,8 @@
flowable-image-generator
- org.apache.commons
- commons-email
+ org.flowable
+ flowable-mail
org.apache.commons
diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/ProcessEngineConfiguration.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/ProcessEngineConfiguration.java
index ea027d2cd2c..d0396a911b7 100644
--- a/modules/flowable5-engine/src/main/java/org/activiti/engine/ProcessEngineConfiguration.java
+++ b/modules/flowable5-engine/src/main/java/org/activiti/engine/ProcessEngineConfiguration.java
@@ -30,6 +30,7 @@
import org.flowable.common.engine.impl.runtime.Clock;
import org.flowable.image.ProcessDiagramGenerator;
import org.flowable.job.service.impl.asyncexecutor.AsyncExecutor;
+import org.flowable.mail.common.api.client.FlowableMailClient;
/**
* Configuration information from which a process engine can be build.
@@ -113,16 +114,11 @@ public abstract class ProcessEngineConfiguration {
protected String history = HistoryLevel.AUDIT.getKey();
protected boolean asyncExecutorActivate;
- protected String mailServerHost = "localhost";
- protected String mailServerUsername; // by default no name and password are provided, which
- protected String mailServerPassword; // means no authentication for mail server
- protected int mailServerPort = 25;
- protected int mailServerSSLPort = 465;
- protected boolean useSSL;
- protected boolean useTLS;
- protected String mailServerDefaultFrom = "activiti@localhost";
+ protected FlowableMailClient defaultMailClient;
+ protected MailServerInfo defaultMailServer;
protected String mailSessionJndi;
protected Map mailServers = new HashMap<>();
+ protected Map mailClients = new HashMap<>();
protected Map mailSessionsJndi = new HashMap<>();
protected String databaseType;
@@ -322,30 +318,59 @@ public ProcessEngineConfiguration setHistory(String history) {
return this;
}
+ public FlowableMailClient getDefaultMailClient() {
+ return defaultMailClient;
+ }
+
+ public ProcessEngineConfiguration setDefaultMailClient(FlowableMailClient defaultMailClient) {
+ this.defaultMailClient = defaultMailClient;
+ return this;
+ }
+
+ public MailServerInfo getDefaultMailServer() {
+ return getOrCreateDefaultMaiLServer();
+ }
+
+ public ProcessEngineConfiguration setDefaultMailServer(MailServerInfo defaultMailServer) {
+ this.defaultMailServer = defaultMailServer;
+ return this;
+ }
+
+ protected MailServerInfo getOrCreateDefaultMaiLServer() {
+ if (defaultMailServer == null) {
+ defaultMailServer = new MailServerInfo();
+ defaultMailServer.setMailServerHost("localhost");
+ defaultMailServer.setMailServerPort(25);
+ defaultMailServer.setMailServerSSLPort(465);
+ defaultMailServer.setMailServerDefaultFrom("flowable@localhost");
+ }
+ return defaultMailServer;
+ }
+
public String getMailServerHost() {
- return mailServerHost;
+ return getOrCreateDefaultMaiLServer().getMailServerHost();
}
public ProcessEngineConfiguration setMailServerHost(String mailServerHost) {
- this.mailServerHost = mailServerHost;
+ getOrCreateDefaultMaiLServer().setMailServerHost(mailServerHost);
return this;
}
public String getMailServerUsername() {
- return mailServerUsername;
+ return getOrCreateDefaultMaiLServer().getMailServerUsername();
}
public ProcessEngineConfiguration setMailServerUsername(String mailServerUsername) {
- this.mailServerUsername = mailServerUsername;
+ getOrCreateDefaultMaiLServer().setMailServerUsername(mailServerUsername);
return this;
}
public String getMailServerPassword() {
- return mailServerPassword;
+ return getOrCreateDefaultMaiLServer().getMailServerPassword();
}
public ProcessEngineConfiguration setMailServerPassword(String mailServerPassword) {
- this.mailServerPassword = mailServerPassword;
+ getOrCreateDefaultMaiLServer().setMailServerPassword(mailServerPassword);
return this;
}
@@ -359,47 +384,47 @@ public ProcessEngineConfiguration setMailSessionJndi(String mailSessionJndi) {
}
public int getMailServerPort() {
- return mailServerPort;
+ return getOrCreateDefaultMaiLServer().getMailServerPort();
}
public ProcessEngineConfiguration setMailServerPort(int mailServerPort) {
- this.mailServerPort = mailServerPort;
+ getOrCreateDefaultMaiLServer().setMailServerPort(mailServerPort);
return this;
}
public int getMailServerSSLPort() {
- return mailServerSSLPort;
+ return getOrCreateDefaultMaiLServer().getMailServerSSLPort();
}
public ProcessEngineConfiguration setMailServerSSLPort(int mailServerSSLPort) {
- this.mailServerSSLPort = mailServerSSLPort;
+ getOrCreateDefaultMaiLServer().setMailServerSSLPort(mailServerSSLPort);
return this;
}
public boolean getMailServerUseSSL() {
- return useSSL;
+ return getOrCreateDefaultMaiLServer().isMailServerUseSSL();
}
public ProcessEngineConfiguration setMailServerUseSSL(boolean useSSL) {
- this.useSSL = useSSL;
+ getOrCreateDefaultMaiLServer().setMailServerUseSSL(useSSL);
return this;
}
public boolean getMailServerUseTLS() {
- return useTLS;
+ return getOrCreateDefaultMaiLServer().isMailServerUseTLS();
}
public ProcessEngineConfiguration setMailServerUseTLS(boolean useTLS) {
- this.useTLS = useTLS;
+ getOrCreateDefaultMaiLServer().setMailServerUseTLS(useTLS);
return this;
}
public String getMailServerDefaultFrom() {
- return mailServerDefaultFrom;
+ return getOrCreateDefaultMaiLServer().getMailServerDefaultFrom();
}
public ProcessEngineConfiguration setMailServerDefaultFrom(String mailServerDefaultFrom) {
- this.mailServerDefaultFrom = mailServerDefaultFrom;
+ getOrCreateDefaultMaiLServer().setMailServerDefaultFrom(mailServerDefaultFrom);
return this;
}
@@ -416,6 +441,19 @@ public ProcessEngineConfiguration setMailServers(Map mai
return this;
}
+ public FlowableMailClient getMailClient(String tenantId) {
+ return mailClients.get(tenantId);
+ }
+
+ public Map getMailClients() {
+ return mailClients;
+ }
+
+ public ProcessEngineConfiguration setMailClients(Map mailClients) {
+ this.mailClients.putAll(mailClients);
+ return this;
+ }
+
public String getMailSessionJndi(String tenantId) {
return mailSessionsJndi.get(tenantId);
}
diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/MailActivityBehavior.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/MailActivityBehavior.java
deleted file mode 100644
index 812ad5ed375..00000000000
--- a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/MailActivityBehavior.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/* Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.activiti.engine.impl.bpmn.behavior;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.activation.DataSource;
-import javax.naming.NamingException;
-
-import org.activiti.engine.ActivitiException;
-import org.activiti.engine.ActivitiIllegalArgumentException;
-import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
-import org.activiti.engine.impl.context.Context;
-import org.activiti.engine.impl.pvm.delegate.ActivityExecution;
-import org.apache.commons.mail.Email;
-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 org.flowable.common.engine.api.delegate.Expression;
-import org.flowable.common.engine.impl.cfg.mail.MailServerInfo;
-import org.flowable.engine.delegate.DelegateExecution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author Joram Barrez
- * @author Frederik Heremans
- * @author Tim Stephenson
- */
-public class MailActivityBehavior extends AbstractBpmnActivityBehavior {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MailActivityBehavior.class);
-
- private static final Class>[] ALLOWED_ATT_TYPES = new Class>[]{
- File.class, File[].class, String.class, String[].class, DataSource.class, DataSource[].class
- };
-
- protected Expression to;
- protected Expression from;
- protected Expression cc;
- protected Expression bcc;
- protected Expression subject;
- protected Expression text;
- protected Expression textVar;
- protected Expression html;
- protected Expression htmlVar;
- protected Expression charset;
- protected Expression ignoreException;
- protected Expression exceptionVariableName;
- protected Expression attachments;
-
- @Override
- public void execute(DelegateExecution execution) {
-
- boolean doIgnoreException = Boolean.parseBoolean(getStringFromField(ignoreException, execution));
- String exceptionVariable = getStringFromField(exceptionVariableName, execution);
- Email email = null;
- try {
- String toStr = getStringFromField(to, execution);
- String fromStr = getStringFromField(from, execution);
- String ccStr = getStringFromField(cc, execution);
- String bccStr = getStringFromField(bcc, execution);
- String subjectStr = getStringFromField(subject, execution);
- String textStr = textVar == null ? getStringFromField(text, execution)
- : getStringFromField(getExpression(execution, textVar), execution);
- String htmlStr = htmlVar == null ? getStringFromField(html, execution)
- : getStringFromField(getExpression(execution, htmlVar), execution);
- String charSetStr = getStringFromField(charset, execution);
- List files = new LinkedList<>();
- List dataSources = new LinkedList<>();
- getFilesFromFields(attachments, execution, files, dataSources);
-
- email = createEmail(textStr, htmlStr, attachmentsExist(files, dataSources));
- addTo(email, toStr);
- setFrom(email, fromStr, execution.getTenantId());
- addCc(email, ccStr);
- addBcc(email, bccStr);
- setSubject(email, subjectStr);
- setMailServerProperties(email, execution.getTenantId());
- setCharset(email, charSetStr);
- attach(email, files, dataSources);
-
- email.send();
-
- } catch (ActivitiException e) {
- handleException(execution, e.getMessage(), e, doIgnoreException, exceptionVariable);
- } catch (EmailException e) {
- handleException(execution, "Could not send e-mail in execution " + execution.getId(), e, doIgnoreException, exceptionVariable);
- }
-
- leave((ActivityExecution) execution);
- }
-
- private boolean attachmentsExist(List files, List dataSources) {
- return !((files == null || files.isEmpty()) && (dataSources == null || dataSources.isEmpty()));
- }
-
- protected Email createEmail(String text, String html, boolean attachmentsExist) {
- if (html != null) {
- return createHtmlEmail(text, html);
- } else if (text != null) {
- if (!attachmentsExist) {
- return createTextOnlyEmail(text);
- } else {
- return createMultiPartEmail(text);
- }
- } else {
- throw new ActivitiIllegalArgumentException("'html' or 'text' is required to be defined when using the mail activity");
- }
- }
-
- protected HtmlEmail createHtmlEmail(String text, String html) {
- HtmlEmail email = new HtmlEmail();
- try {
- email.setHtmlMsg(html);
- if (text != null) { // for email clients that don't support html
- email.setTextMsg(text);
- }
- return email;
- } catch (EmailException e) {
- throw new ActivitiException("Could not create HTML email", e);
- }
- }
-
- protected SimpleEmail createTextOnlyEmail(String text) {
- SimpleEmail email = new SimpleEmail();
- try {
- email.setMsg(text);
- return email;
- } catch (EmailException e) {
- throw new ActivitiException("Could not create text-only email", e);
- }
- }
-
- protected MultiPartEmail createMultiPartEmail(String text) {
- MultiPartEmail email = new MultiPartEmail();
- try {
- email.setMsg(text);
- return email;
- } catch (EmailException e) {
- throw new ActivitiException("Could not create text-only email", e);
- }
- }
-
- protected void addTo(Email email, String to) {
- String[] tos = splitAndTrim(to);
- if (tos != null) {
- for (String t : tos) {
- try {
- email.addTo(t);
- } catch (EmailException e) {
- throw new ActivitiException("Could not add " + t + " as recipient", e);
- }
- }
- } else {
- throw new ActivitiException("No recipient could be found for sending email");
- }
- }
-
- protected void setFrom(Email email, String from, String tenantId) {
- String fromAddress = null;
-
- if (from != null) {
- fromAddress = from;
- } else { // use default configured from address in process engine config
- if (tenantId != null && tenantId.length() > 0) {
- Map mailServers = Context.getProcessEngineConfiguration().getMailServers();
- if (mailServers != null && mailServers.containsKey(tenantId)) {
- MailServerInfo mailServerInfo = mailServers.get(tenantId);
- fromAddress = mailServerInfo.getMailServerDefaultFrom();
- }
- }
-
- if (fromAddress == null) {
- fromAddress = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
- }
- }
-
- try {
- email.setFrom(fromAddress);
- } catch (EmailException e) {
- throw new ActivitiException("Could not set " + from + " as from address in email", e);
- }
- }
-
- protected void addCc(Email email, String cc) {
- String[] ccs = splitAndTrim(cc);
- if (ccs != null) {
- for (String c : ccs) {
- try {
- email.addCc(c);
- } catch (EmailException e) {
- throw new ActivitiException("Could not add " + c + " as cc recipient", e);
- }
- }
- }
- }
-
- protected void addBcc(Email email, String bcc) {
- String[] bccs = splitAndTrim(bcc);
- if (bccs != null) {
- for (String b : bccs) {
- try {
- email.addBcc(b);
- } catch (EmailException e) {
- throw new ActivitiException("Could not add " + b + " as bcc recipient", e);
- }
- }
- }
- }
-
- protected void attach(Email email, List files, List dataSources) throws EmailException {
- if (!(email instanceof MultiPartEmail && attachmentsExist(files, dataSources))) {
- return;
- }
- MultiPartEmail mpEmail = (MultiPartEmail) email;
- for (File file : files) {
- mpEmail.attach(file);
- }
- for (DataSource ds : dataSources) {
- if (ds != null) {
- mpEmail.attach(ds, ds.getName(), null);
- }
- }
- }
-
- protected void setSubject(Email email, String subject) {
- email.setSubject(subject != null ? subject : "");
- }
-
- protected void setMailServerProperties(Email email, String tenantId) {
- ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
-
- boolean isMailServerSet = false;
- if (tenantId != null && tenantId.length() > 0) {
- if (processEngineConfiguration.getMailSessionJndi(tenantId) != null) {
- setEmailSession(email, processEngineConfiguration.getMailSessionJndi(tenantId));
- isMailServerSet = true;
-
- } else if (processEngineConfiguration.getMailServer(tenantId) != null) {
- MailServerInfo mailServerInfo = processEngineConfiguration.getMailServer(tenantId);
- String host = mailServerInfo.getMailServerHost();
- if (host == null) {
- throw new ActivitiException("Could not send email: no SMTP host is configured for tenantId " + tenantId);
- }
- email.setHostName(host);
-
- email.setSmtpPort(mailServerInfo.getMailServerPort());
- email.setSslSmtpPort(Integer.toString(mailServerInfo.getMailServerSSLPort()));
-
- email.setSSLOnConnect(processEngineConfiguration.getMailServerUseSSL());
- email.setStartTLSEnabled(processEngineConfiguration.getMailServerUseTLS());
-
- String user = mailServerInfo.getMailServerUsername();
- String password = mailServerInfo.getMailServerPassword();
- if (user != null && password != null) {
- email.setAuthentication(user, password);
- }
-
- isMailServerSet = true;
- }
- }
-
- if (!isMailServerSet) {
- String mailSessionJndi = processEngineConfiguration.getMailSessionJndi();
- if (mailSessionJndi != null) {
- setEmailSession(email, mailSessionJndi);
-
- } else {
- String host = processEngineConfiguration.getMailServerHost();
- if (host == null) {
- throw new ActivitiException("Could not send email: no SMTP host is configured");
- }
- email.setHostName(host);
-
- int port = processEngineConfiguration.getMailServerPort();
- email.setSmtpPort(port);
- email.setSslSmtpPort(Integer.toString(processEngineConfiguration.getMailServerSSLPort()));
-
- email.setSSLOnConnect(processEngineConfiguration.getMailServerUseSSL());
- email.setStartTLSEnabled(processEngineConfiguration.getMailServerUseTLS());
-
- String user = processEngineConfiguration.getMailServerUsername();
- String password = processEngineConfiguration.getMailServerPassword();
- if (user != null && password != null) {
- email.setAuthentication(user, password);
- }
- }
- }
- }
-
- protected void setEmailSession(Email email, String mailSessionJndi) {
- try {
- email.setMailSessionFromJNDI(mailSessionJndi);
- } catch (NamingException e) {
- throw new ActivitiException("Could not send email: Incorrect JNDI configuration", e);
- }
- }
-
- protected void setCharset(Email email, String charSetStr) {
- if (charset != null) {
- email.setCharset(charSetStr);
- }
- }
-
- protected String[] splitAndTrim(String str) {
- if (str != null) {
- String[] splittedStrings = str.split(",");
- for (int i = 0; i < splittedStrings.length; i++) {
- splittedStrings[i] = splittedStrings[i].trim();
- }
- return splittedStrings;
- }
- return null;
- }
-
- protected String getStringFromField(Expression expression, DelegateExecution execution) {
- if (expression != null) {
- Object value = expression.getValue(execution);
- if (value != null) {
- return value.toString();
- }
- }
- return null;
- }
-
- private void getFilesFromFields(Expression expression, DelegateExecution execution, List files, List dataSources) {
- Object value = checkAllowedTypes(expression, execution);
- if (value != null) {
- if (value instanceof File) {
- files.add((File) value);
- } else if (value instanceof String) {
- files.add(new File((String) value));
- } else if (value instanceof File[]) {
- Collections.addAll(files, (File[]) value);
- } else if (value instanceof String[]) {
- String[] paths = (String[]) value;
- for (String path : paths) {
- files.add(new File(path));
- }
- } else if (value instanceof DataSource) {
- dataSources.add((DataSource) value);
- } else if (value instanceof DataSource[]) {
- for (DataSource ds : (DataSource[]) value) {
- if (ds != null) {
- dataSources.add(ds);
- }
- }
- }
- }
- for (Iterator it = files.iterator(); it.hasNext(); ) {
- File file = it.next();
- if (!fileExists(file)) {
- it.remove();
- }
- }
- }
-
- private Object checkAllowedTypes(Expression expression, DelegateExecution execution) {
- if (expression == null) {
- return null;
- }
- Object value = expression.getValue(execution);
- if (value == null) {
- return null;
- }
- for (Class> allowedType : ALLOWED_ATT_TYPES) {
- if (allowedType.isInstance(value)) {
- return value;
- }
- }
- throw new ActivitiException("Invalid attachment type: " + value.getClass());
- }
-
- protected boolean fileExists(File file) {
- return file != null && file.exists() && file.isFile() && file.canRead();
- }
-
- protected Expression getExpression(DelegateExecution execution, Expression var) {
- String variable = (String) execution.getVariable(var.getExpressionText());
- return Context.getProcessEngineConfiguration().getExpressionManager().createExpression(variable);
- }
-
- protected void handleException(DelegateExecution execution, String msg, Exception e, boolean doIgnoreException, String exceptionVariable) {
- if (doIgnoreException) {
- LOGGER.info("Ignoring email send error: {}", msg, e);
- if (exceptionVariable != null && exceptionVariable.length() > 0) {
- execution.setVariable(exceptionVariable, msg);
- }
- } else {
- if (e instanceof ActivitiException) {
- throw (ActivitiException) e;
- } else {
- throw new ActivitiException(msg, e);
- }
- }
- }
-}
diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/mail/BpmnMailActivityDelegate.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/mail/BpmnMailActivityDelegate.java
new file mode 100644
index 00000000000..d59ef168253
--- /dev/null
+++ b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/mail/BpmnMailActivityDelegate.java
@@ -0,0 +1,59 @@
+/* Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.activiti.engine.impl.bpmn.mail;
+
+import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
+import org.activiti.engine.impl.context.Context;
+import org.apache.commons.lang3.StringUtils;
+import org.flowable.common.engine.api.delegate.Expression;
+import org.flowable.content.api.ContentService;
+import org.flowable.engine.delegate.DelegateExecution;
+import org.flowable.engine.delegate.JavaDelegate;
+import org.flowable.mail.common.api.client.FlowableMailClient;
+import org.flowable.mail.common.impl.BaseMailActivityDelegate;
+
+public class BpmnMailActivityDelegate extends BaseMailActivityDelegate
+ implements JavaDelegate {
+
+ @Override
+ public void execute(DelegateExecution execution) {
+ prepareAndExecuteRequest(execution);
+ }
+
+ @Override
+ protected FlowableMailClient getMailClient(DelegateExecution execution) {
+ ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
+ String tenantId = execution.getTenantId();
+ FlowableMailClient mailClient = null;
+ if (StringUtils.isNotBlank(tenantId)) {
+ mailClient = processEngineConfiguration.getMailClient(tenantId);
+ }
+
+ if (mailClient == null) {
+ mailClient = processEngineConfiguration.getDefaultMailClient();
+ }
+
+ return mailClient;
+ }
+
+ @Override
+ protected Expression createExpression(String expressionText) {
+ return Context.getProcessEngineConfiguration().getExpressionManager().createExpression(expressionText);
+ }
+
+ @Override
+ protected ContentService getContentService() {
+ return null;
+ }
+
+}
diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/ActivityBehaviorFactory.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/ActivityBehaviorFactory.java
index 0dbaee7c0d1..58fd5ed6368 100644
--- a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/ActivityBehaviorFactory.java
+++ b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/ActivityBehaviorFactory.java
@@ -27,7 +27,6 @@
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowCompensationEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowNoneEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowSignalEventActivityBehavior;
-import org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.ManualTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.NoneStartEventActivityBehavior;
@@ -123,9 +122,9 @@ public interface ActivityBehaviorFactory {
public abstract WebServiceActivityBehavior createWebServiceActivityBehavior(SendTask sendTask, BpmnModel bpmnModel);
- public abstract MailActivityBehavior createMailActivityBehavior(ServiceTask serviceTask);
+ public abstract ActivityBehavior createMailActivityBehavior(ServiceTask serviceTask);
- public abstract MailActivityBehavior createMailActivityBehavior(SendTask sendTask);
+ public abstract ActivityBehavior createMailActivityBehavior(SendTask sendTask);
public abstract ActivityBehavior createCamelActivityBehavior(ServiceTask serviceTask, BpmnModel bpmnModel);
diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/DefaultActivityBehaviorFactory.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/DefaultActivityBehaviorFactory.java
index 35256080e1a..96c10beae32 100644
--- a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/DefaultActivityBehaviorFactory.java
+++ b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/bpmn/parser/factory/DefaultActivityBehaviorFactory.java
@@ -31,7 +31,6 @@
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowCompensationEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowNoneEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowSignalEventActivityBehavior;
-import org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.ManualTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.NoneStartEventActivityBehavior;
@@ -50,6 +49,7 @@
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.WebServiceActivityBehavior;
import org.activiti.engine.impl.bpmn.helper.ClassDelegate;
+import org.activiti.engine.impl.bpmn.mail.BpmnMailActivityDelegate;
import org.activiti.engine.impl.bpmn.parser.CompensateEventDefinition;
import org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration;
import org.activiti.engine.impl.bpmn.parser.FieldDeclaration;
@@ -198,18 +198,18 @@ public WebServiceActivityBehavior createWebServiceActivityBehavior(SendTask send
}
@Override
- public MailActivityBehavior createMailActivityBehavior(ServiceTask serviceTask) {
+ public ActivityBehavior createMailActivityBehavior(ServiceTask serviceTask) {
return createMailActivityBehavior(serviceTask.getId(), serviceTask.getFieldExtensions());
}
@Override
- public MailActivityBehavior createMailActivityBehavior(SendTask sendTask) {
+ public ActivityBehavior createMailActivityBehavior(SendTask sendTask) {
return createMailActivityBehavior(sendTask.getId(), sendTask.getFieldExtensions());
}
- protected MailActivityBehavior createMailActivityBehavior(String taskId, List fields) {
+ protected ActivityBehavior createMailActivityBehavior(String taskId, List fields) {
List fieldDeclarations = createFieldDeclarations(fields);
- return (MailActivityBehavior) ClassDelegate.defaultInstantiateDelegate(MailActivityBehavior.class, fieldDeclarations);
+ return new ClassDelegate(BpmnMailActivityDelegate.class, fieldDeclarations);
}
// We do not want a hard dependency on Camel, hence we return ActivityBehavior and instantiate
diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java
index 4632a13e0d1..ddc3ad96d19 100644
--- a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java
+++ b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java
@@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -199,12 +200,15 @@
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
import org.apache.ibatis.type.JdbcType;
import org.flowable.bpmn.model.BpmnModel;
+import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.calendar.BusinessCalendarManager;
import org.flowable.common.engine.impl.calendar.CycleBusinessCalendar;
import org.flowable.common.engine.impl.calendar.DueDateBusinessCalendar;
import org.flowable.common.engine.impl.calendar.DurationBusinessCalendar;
import org.flowable.common.engine.impl.calendar.MapBusinessCalendarManager;
+import org.flowable.common.engine.impl.cfg.mail.FlowableMailClientCreator;
+import org.flowable.common.engine.impl.cfg.mail.MailServerInfo;
import org.flowable.common.engine.impl.history.HistoryLevel;
import org.flowable.common.engine.impl.persistence.deploy.DefaultDeploymentCache;
import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache;
@@ -576,6 +580,7 @@ protected void init() {
initProcessDiagramGenerator();
initHistoryLevel();
initExpressionManager();
+ initMailClients();
initVariableTypes();
initBeans();
initFormEngines();
@@ -1433,6 +1438,45 @@ protected void initExpressionManager() {
}
}
+ public void initMailClients() {
+ if (defaultMailClient == null) {
+ String sessionJndi = getMailSessionJndi();
+ if (sessionJndi != null) {
+ defaultMailClient = FlowableMailClientCreator.createSessionClient(sessionJndi, getDefaultMailServer());
+ } else {
+ MailServerInfo mailServer = getDefaultMailServer();
+ String host = mailServer.getMailServerHost();
+ if (host == null) {
+ throw new FlowableException("no SMTP host is configured for the default mail server");
+ }
+ defaultMailClient = FlowableMailClientCreator.createHostClient(host, mailServer);
+ }
+ }
+
+ Collection tenantIds = new HashSet<>(mailSessionsJndi.keySet());
+ tenantIds.addAll(mailServers.keySet());
+
+ if (!tenantIds.isEmpty()) {
+ MailServerInfo defaultMailServer = getDefaultMailServer();
+ for (String tenantId : tenantIds) {
+ if (mailClients.containsKey(tenantId)) {
+ continue;
+ }
+ String sessionJndi = mailSessionsJndi.get(tenantId);
+ MailServerInfo tenantMailServer = mailServers.get(tenantId);
+ if (sessionJndi != null) {
+ mailClients.put(tenantId, FlowableMailClientCreator.createSessionClient(sessionJndi, tenantMailServer, defaultMailServer));
+ } else if (tenantMailServer != null) {
+ String host = tenantMailServer.getMailServerHost();
+ if (host == null) {
+ throw new FlowableException("no SMTP host is configured for the mail server for tenant " + tenantId);
+ }
+ mailClients.put(tenantId, FlowableMailClientCreator.createHostClient(host, tenantMailServer, defaultMailServer));
+ }
+ }
+ }
+ }
+
protected void initBusinessCalendarManager() {
if (businessCalendarManager == null) {
MapBusinessCalendarManager mapBusinessCalendarManager = new MapBusinessCalendarManager();
diff --git a/modules/flowable5-test/src/main/java/org/activiti/engine/test/TestActivityBehaviorFactory.java b/modules/flowable5-test/src/main/java/org/activiti/engine/test/TestActivityBehaviorFactory.java
index 96938478134..18c5fc04756 100644
--- a/modules/flowable5-test/src/main/java/org/activiti/engine/test/TestActivityBehaviorFactory.java
+++ b/modules/flowable5-test/src/main/java/org/activiti/engine/test/TestActivityBehaviorFactory.java
@@ -34,7 +34,6 @@
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowCompensationEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowNoneEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.IntermediateThrowSignalEventActivityBehavior;
-import org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.ManualTaskActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior;
import org.activiti.engine.impl.bpmn.behavior.NoneStartEventActivityBehavior;
@@ -200,12 +199,12 @@ public WebServiceActivityBehavior createWebServiceActivityBehavior(SendTask send
}
@Override
- public MailActivityBehavior createMailActivityBehavior(ServiceTask serviceTask) {
+ public ActivityBehavior createMailActivityBehavior(ServiceTask serviceTask) {
return wrappedActivityBehaviorFactory.createMailActivityBehavior(serviceTask);
}
@Override
- public MailActivityBehavior createMailActivityBehavior(SendTask sendTask) {
+ public ActivityBehavior createMailActivityBehavior(SendTask sendTask) {
return wrappedActivityBehaviorFactory.createMailActivityBehavior(sendTask);
}