JBPM5.4发送email

JBPM5.4配置参考: http://panyongzheng.iteye.com/blog/1879279
本文参考: https://community.jboss.org/thread/201336
发送邮件的功能,只有三个控件,开始事件,邮件事件,结束时间。
dpmn文件:
<?xml version="1.0" encoding="UTF-8"?> 
<definitions id="Definition"
             targetNamespace="http://www.jboss.org/drools"
             typeLanguage="http://www.java.com/javaTypes"
             expressionLanguage="http://www.mvel.org/2.0"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
             xmlns:g="http://www.jboss.org/drools/flow/gpd"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
             xmlns:tns="http://www.jboss.org/drools">

  <process processType="Private" isExecutable="true" id="com.sample.email.bpmn" name="Sample Process" tns:packageName="defaultPackage" >

    <!-- nodes -->
    <startEvent id="_1" name="StartProcess" />
    <endEvent id="_2" name="End" >
        <terminateEventDefinition/>
    </endEvent>
    <task id="_3" name="Email" tns:taskName="Email" >
      <ioSpecification>
        <dataInput id="_3_BodyInput" name="Body" />
        <dataInput id="_3_SubjectInput" name="Subject" />
        <dataInput id="_3_ToInput" name="To" />
        <dataInput id="_3_FromInput" name="From" />
        <inputSet>
          <dataInputRefs>_3_BodyInput</dataInputRefs>
          <dataInputRefs>_3_SubjectInput</dataInputRefs>
          <dataInputRefs>_3_ToInput</dataInputRefs>
          <dataInputRefs>_3_FromInput</dataInputRefs>
        </inputSet>
        <outputSet>
        </outputSet>
      </ioSpecification>
      <dataInputAssociation>
        <targetRef>_3_BodyInput</targetRef>
        <assignment>
          <from xsi:type="tFormalExpression">This is a test mail.</from>
          <to xsi:type="tFormalExpression">_3_BodyInput</to>
        </assignment>
      </dataInputAssociation>
      <dataInputAssociation>
        <targetRef>_3_SubjectInput</targetRef>
        <assignment>
          <from xsi:type="tFormalExpression">JBPM5.4 Email Event</from>
          <to xsi:type="tFormalExpression">_3_SubjectInput</to>
        </assignment>
      </dataInputAssociation>
      <dataInputAssociation>
        <targetRef>_3_ToInput</targetRef>
        <assignment>
          <from xsi:type="tFormalExpression">[email protected]</from>
          <to xsi:type="tFormalExpression">_3_ToInput</to>
        </assignment>
      </dataInputAssociation>
      <dataInputAssociation>
        <targetRef>_3_FromInput</targetRef>
        <assignment>
          <from xsi:type="tFormalExpression">[email protected]</from>
          <to xsi:type="tFormalExpression">_3_FromInput</to>
        </assignment>
      </dataInputAssociation>
    </task>

    <!-- connections -->
    <sequenceFlow id="_3-_2" sourceRef="_3" targetRef="_2" />
    <sequenceFlow id="_1-_3" sourceRef="_1" targetRef="_3" />

  </process>

  <bpmndi:BPMNDiagram>
    <bpmndi:BPMNPlane bpmnElement="com.sample.email.bpmn" >
      <bpmndi:BPMNShape bpmnElement="_1" >
        <dc:Bounds x="47" y="157" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_2" >
        <dc:Bounds x="704" y="150" width="48" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" >
        <dc:Bounds x="349" y="156" width="100" height="48" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_3-_2" >
        <di:waypoint x="399" y="180" />
        <di:waypoint x="728" y="174" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_1-_3" >
        <di:waypoint x="71" y="181" />
        <di:waypoint x="399" y="180" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>

</definitions>



java代码:
package com.gds.web;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.drools.command.Context;
import org.drools.command.impl.GenericCommand;
import org.drools.command.impl.KnowledgeCommandContext;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.WorkflowProcessInstance;
import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.instance.context.variable.VariableScopeInstance;
import org.jbpm.process.workitem.email.EmailWorkItemHandler;
import org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler;
import org.jbpm.task.Task;
import org.jbpm.task.TaskData;
import org.jbpm.task.TaskService;
import org.jbpm.task.query.TaskSummary;
import org.jbpm.task.service.ContentData;
import org.jbpm.task.utils.ContentMarshallerHelper;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gds.jbpm.MyLocalTaskService;
import com.gds.jbpm.Order;

@Controller
public class EmailController {

	private Logger log = Logger.getLogger(this.getClass());

	@Resource
	@Qualifier("myLocalTaskService")
	private MyLocalTaskService myLocalTaskService;
	@Resource
	@Qualifier("ksession")
	private StatefulKnowledgeSession ksession;

	public void registerWorkItemHandler() {
		LocalHTWorkItemHandler humanTaskHandler = new LocalHTWorkItemHandler(
				myLocalTaskService.getLocalTaskService(), ksession);
		humanTaskHandler.setLocal(true);
		humanTaskHandler.connect();
		ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
				humanTaskHandler);
		System.out
				.println("----------------------------------------------------->LocalHTWorkItemHandler");
		EmailWorkItemHandler emailHandler1 = new EmailWorkItemHandler();
		emailHandler1.setConnection("smtp.163.com", "25", "[email protected]", "123");
		emailHandler1.getConnection().setStartTls(true);
		ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler1);
		System.out
				.println("----------------------------------------------------->EmailWorkItemHandler");
	}

	@RequestMapping(value = "email.do", method = { GET, POST, PUT })
	public String doCreate(Model model) {
		System.out.println("JBPM5.4的邮件测试");
		ksession = myLocalTaskService.getKsession();
		registerWorkItemHandler();
		ksession.startProcess("com.sample.email.bpmn");
		ksession.fireAllRules();
		model.addAttribute("message", "process created!");
		return "create";
	}

}

EmailWorkItemHandler emailHandler1 = new EmailWorkItemHandler();
emailHandler1.setConnection("smtp.163.com", "25", "[email protected]", "123");
emailHandler1.getConnection().setStartTls(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler1);

你可能感兴趣的:(email)