本篇使用到的相關技術內容:
spring 3.0
jbpm4.4
hsqldb
hibernate
其中hsqldb和hibernate都是從jbpm4.4的lib文件夾里面拷過去的。
本篇不再介紹jbpm與spring集成和spring mvc兩方面的內容,有需要,請看之前的文章
jbpm4.3與spring集成請看http://www.aygfsteel.com/pengo/archive/2010/01/04/308219.html
spring3.0 mvc和rest小例子請看http://www.aygfsteel.com/pengo/archive/2010/07/03/325164.html
本篇只實現兩個功能,上傳流程定義文件和發布該上傳的流程定義文件。
使用的流程定義文件是使用上一篇jbpm流程設計器生成的定義文件,
有關jbpm流程設計器介紹,請看http://www.aygfsteel.com/pengo/archive/2010/08/31/330346.html
流程圖:

把流程圖保存為test.jpdl.xml
deploy.jsp代碼:
運行效果:


本人測試環境:jdk6 + tomcat6.0.20
源碼: jbpm4.4_spring3
spring 3.0
jbpm4.4
hsqldb
hibernate
其中hsqldb和hibernate都是從jbpm4.4的lib文件夾里面拷過去的。
本篇不再介紹jbpm與spring集成和spring mvc兩方面的內容,有需要,請看之前的文章
jbpm4.3與spring集成請看http://www.aygfsteel.com/pengo/archive/2010/01/04/308219.html
spring3.0 mvc和rest小例子請看http://www.aygfsteel.com/pengo/archive/2010/07/03/325164.html
本篇只實現兩個功能,上傳流程定義文件和發布該上傳的流程定義文件。
使用的流程定義文件是使用上一篇jbpm流程設計器生成的定義文件,
有關jbpm流程設計器介紹,請看http://www.aygfsteel.com/pengo/archive/2010/08/31/330346.html
流程圖:

把流程圖保存為test.jpdl.xml
1
<?xml version="1.0" encoding="GBK"?>
2
<process name="process" xmlns="http://jbpm.org/4.4/jpdl">
3
<start name="開始" g="83,34,40,40">
4
<transition name="to 任務" g="0,0" to="任務" />
5
</start>
6
<task name="任務" g="231,78,80,40">
7
<transition name="to 結束" g="0,0" to="結束" />
8
</task>
9
<end name="結束" g="173,188,40,40" />
10
</process>

2

3

4

5

6

7

8

9

10

RestController.java的發布處理代碼:
1
@RequestMapping(value = "/deployAction", method = RequestMethod.POST)
2
public ModelAndView deployAction(HttpServletRequest request,
3
HttpServletResponse response, ModelMap modelMap) {
4
String realPath = request.getSession().getServletContext().getRealPath(
5
"")
6
+ "/WEB-INF/deploy/";
7
try {
8
if (ServletFileUpload.isMultipartContent(request)) {
9
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
10
for (Iterator it = multipartRequest.getFileNames(); it
11
.hasNext();) {
12
String key = (String) it.next();
13
MultipartFile file = multipartRequest.getFile(key);
14
if (file.getOriginalFilename().length() > 0) {
15
String filename = file.getOriginalFilename();
16
File saveFile = new File(realPath + filename);
17
FileOutputStream fos = new FileOutputStream(saveFile);
18
//保存上傳的流程定義文件
19
fos.write(file.getBytes());
20
fos.flush();
21
fos.close();
22
23
ApplicationContext ctx = new ClassPathXmlApplicationContext(
24
"applicationContext.xml");
25
//調用已定義的Bean
26
ProcessEngine processEngine = (ProcessEngine) ctx
27
.getBean("processEngine");
28
File deployFile = new File(saveFile.getAbsolutePath());
29
if (deployFile.exists()) {
30
// 發布流程
31
String deploymentId = processEngine
32
.getRepositoryService().createDeployment()
33
.addResourceFromFile(deployFile).deploy();
34
System.out.println("========================ID:"
35
+ deploymentId);
36
modelMap.put("deploy", "發布成功,版本號為:" + deploymentId);
37
}
38
39
}
40
}
41
}
42
} catch (Exception e) {
43
modelMap.put("deploy", "發布失敗!" );
44
e.printStackTrace();
45
}
46
47
return new ModelAndView("/deploy", modelMap);
48
}
49

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

deploy.jsp代碼:
1
<%@ page language="java" contentType="text/html; charset=GBK"
2
pageEncoding="GBK"%>
3
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4
<html>
5
<head>
6
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
7
<title>上傳</title>
8
</head>
9
<body>
10
<%
11
String deploy = request.getAttribute("deploy").toString();
12
%>
13
<script>
14
alert('<%=deploy%>');
15
</script>
16
<form name="upform" action="deployAction" method="POST" enctype="multipart/form-data">
17
18
<input type ="file" name="file1" id="file1"/> <br/>
19
<!-- <input type ="file" name="file2" id="file2"/> -->
20
<input type="submit" value="上傳" /><br/>
21
</form>
22
</body>
23
</html>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

運行效果:


本人測試環境:jdk6 + tomcat6.0.20
源碼: jbpm4.4_spring3