posts - 59, comments - 244, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          在spring mvc下發布jbpm流程

          Posted on 2010-09-07 00:55 penngo 閱讀(5501) 評論(3)  編輯  收藏 所屬分類: JBPM
          本篇使用到的相關技術內容:
          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>


          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
          主站蜘蛛池模板: 二连浩特市| 合肥市| 诸城市| 华容县| 临泉县| 汨罗市| 长阳| 静海县| 明星| 新疆| 广宗县| 岗巴县| 金川县| 民权县| 江阴市| 布尔津县| 荆门市| 四子王旗| 滦平县| 韩城市| 永康市| 高雄县| 建始县| 秀山| 西乌珠穆沁旗| 鄂尔多斯市| 德江县| 本溪市| 东莞市| 祥云县| 馆陶县| 应城市| 耒阳市| 耿马| 民和| 什邡市| 揭西县| 松滋市| 林西县| 苏尼特左旗| 虹口区|