简体   繁体   English

如何捕获在 Alfresco 的 Activiti 6 中发送电子邮件时发生的错误?

[英]How to catch errors that occurred while sending an email in Alfresco's Activiti 6?

I need to send emails, and I use a service task for it:我需要发送电子邮件,为此我使用了一个service task

<serviceTask id="SendEmail_1" name="Sending a notification by email" activiti:type="mail">
  <documentation></documentation>
  <extensionElements>
    <activiti:field name="to">
      <activiti:expression><![CDATA[${to}]]></activiti:expression>
    </activiti:field>
    <activiti:field name="subject">
      <activiti:expression><![CDATA[${subject}]]></activiti:expression>
    </activiti:field>
    <activiti:field name="text">
      <activiti:expression><![CDATA[${body}]]></activiti:expression>
    </activiti:field>
    <activiti:field name="ignoreException">
      <activiti:string><![CDATA[true]]></activiti:string>
    </activiti:field>
    <activiti:field name="charset">
      <activiti:string><![CDATA[utf8]]></activiti:string>
    </activiti:field>
  </extensionElements>
</serviceTask>

I also need to catch the errors that occur when sending mail.我还需要捕获发送邮件时发生的错误。 In the user guide, I read that in order to get a description of the error, you need to read from the variables of the process the value of the variable " exceptionVariableName ".在用户指南中,我读到为了获得错误的描述,您需要从进程的变量中读取变量“ exceptionVariableName ”的值。 As you can see above, I added this to the service task, but so far I have not seen that it works.正如您在上面看到的,我将其添加到服务任务中,但到目前为止我还没有看到它起作用。 I tried to give him non-existent addresses of recipients, but there was no error.我试图给他不存在的收件人地址,但没有错误。 Does it even work?它甚至有效吗? When does it work?它什么时候起作用? Or is there another mechanism for getting error descriptions?或者是否有另一种获取错误描述的机制?

PS I use Activiti 6.0.0. PS 我使用 Activiti 6.0.0。

PSS I tried to add the block below in the " extensionElements " tag: PSS 我试图在“ extensionElements ”标签中添加下面的块:

<activiti:field name="exceptionVariableName">
  <activiti:string><![CDATA[error]]></activiti:string>
</activiti:field>

And it also did not help me (for example, if the recipients are not correct).而且它也没有帮助我(例如,如果收件人不正确)。

PSSS I specified the wrong smtp server host (while creating the process configuration bean), and I got the error description (the Java code for receiving it is presented below), but it is uninformative. PSSS 我指定了错误的 smtp 服务器主机(在创建进程配置 bean 时),我得到了错误描述(用于接收它的 Java 代码如下所示),但它没有提供任何信息。

public void logEmailSending(DelegateExecution execution) {
    Object error = execution.getVariable("error");
    if (error != null)
        logger.error("An error occurred while sending the email: " + error);
}

it almost solved my problem, but, as I wrote above, I would like to be more concrete by mistake, and it still does not catch the error in the recipients addresses它几乎解决了我的问题,但是,正如我上面写的,我想错误地更具体一些,但它仍然没有发现收件人地址中的错误

We hit the same wall in Activiti BPM 6.0.0 .我们在Activiti BPM 6.0.0中遇到了同样的问题。 We solved our problem with the following steps.我们通过以下步骤解决了我们的问题。


  1. Implementing a new service task eg SendEmailServiceTask which extends org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior .实现一个新的服务任务,例如扩展org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior的 SendEmailServiceTask。 This was necessary in order to override the method handleException which takes care of exception handling.这是必要的,以便覆盖负责异常处理的方法handleException

From the Activiti documentation 8.5.6.来自 Activiti 文档8.5.6。 Email Task note that the mail task is not an official task of the BPMN 2.0 spec (and it does not have a dedicated icon as a consequence).电子邮件任务请注意,邮件任务不是 BPMN 2.0 规范的官方任务(因此它没有专用图标)。 Hence, in Activiti the mail task is implemented as a dedicated service task.因此,在 Activiti 中,邮件任务被实现为一个专门的服务任务。

In our service task implementation we took care of:在我们的服务任务实施中,我们负责:

  • Catching the EmailException, SendFailedException due to errors on SMTP.由于 SMTP 上的错误捕获 EmailException、SendFailedException。
  • Parsing informative data from exception and logging into application logs and user action journals.从异常中解析信息数据并记录到应用程序日志和用户操作日志中。
  • Setting our custom BPM process variables in order to control the further execution flow.设置我们的自定义 BPM 流程变量以控制进一步的执行流程。

  1. Modifying the BPMN process definition, more precisely replacing the mail task activiti with our new service task from point 1.修改 BPMN 流程定义,更准确地说,用第 1 点中的新服务任务替换邮件任务 activiti。

In order to reproduce the same functionality of default mail task provided by Activiti we had to set class fields from , bcc , subject and text .为了重现 Activiti 提供的默认邮件任务的相同功能,我们必须设置类字段frombccsubjecttext The same values were set as on previously defined mail task.设置与先前定义的邮件任务相同的值。

And most important we had to set ignoreException to true in order to prevent BPM engine to throw ActivitiException due to exceptions on SMTP (invalid recipient, SMTP server domain, etc.) while sending email to the recipient.最重要的是,我们必须将ignoreException设置为true ,以防止 BPM 引擎在向收件人发送电子邮件时由于 SMTP 异常(无效收件人、SMTP 服务器域等)而抛出 ActivitiException。

Our business requirement was to either sucessfully send mail to all recipients in bcc field or fail.我们的业务需求是要么成功地向密件抄送字段中的所有收件人发送邮件,要么失败。 For this reason we didn't model our service task as multiinstance element.出于这个原因,我们没有将我们的服务任务建模为多实例元素。


I am absolutely aware there exist other solutions for this particular problem.我绝对知道这个特定问题存在其他解决方案。 We managed to solve it as described above.我们设法如上所述解决了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM