posts - 59, comments - 244, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

在spring mvc下发布jbpm流程

Posted on 2010-09-07 00:55 penngo 阅读(5487) 评论(3)  编辑  收藏 所属分类: JBPM
本篇使用到的相关技术内容:
spring 3.0
jbpm4.4
hsqldb
hibernate
其中hsqldb和hibernate都是从jbpm4.4的lib文件夹里面拷过去的。
本篇不再介绍jbpm与spring集成和spring mvc两方面的内容,有需要,请看之前的文章
jbpm4.3与spring集成请看http://www.blogjava.net/pengo/archive/2010/01/04/308219.html
spring3.0 mvc和rest小例子请看http://www.blogjava.net/pengo/archive/2010/07/03/325164.html

本篇只实现两个功能,上传流程定义文件和发布该上传的流程定义文件。
使用的流程定义文件是使用上一篇jbpm流程设计器生成的定义文件,
有关jbpm流程设计器介绍,请看http://www.blogjava.net/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>


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

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>
14alert('<%=deploy%>');
15
</script>
16<form name="upform" action="deployAction" method="POST" enctype="multipart/form-data">  
17    &nbsp;&nbsp;&nbsp;&nbsp;
18    <input type ="file" name="file1" id="file1"/>&nbsp;&nbsp;<br/>
19    <!--  <input type ="file" name="file2" id="file2"/>&nbsp;&nbsp; -->
20    <input type="submit" value="上传" /><br/>  
21  </form>  
22</body>
23</html>

运行效果:




本人测试环境:jdk6 + tomcat6.0.20
源码: jbpm4.4_spring3

评论

# re: 在spring mvc下发布jbpm流程[未登录]  回复  更多评论   

2012-08-22 14:02 by paul
能给我发一套源码吗?谢谢liufeng_4466@sina.com

# re: 在spring mvc下发布jbpm流程  回复  更多评论   

2013-04-09 10:58 by lyl
求一套源码 谢谢 l_y_l@126.com

# re: 在spring mvc下发布jbpm流程  回复  更多评论   

2013-05-06 20:05 by 郭贝
东西不错 求源码啊!下载不了 hanyijun85@163.com

只有注册用户登录后才能发表评论。


网站导航: