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

          在spring mvc下發(fā)布jbpm流程

          Posted on 2010-09-07 00:55 penngo 閱讀(5508) 評論(3)  編輯  收藏 所屬分類: JBPM
          本篇使用到的相關(guān)技術(shù)內(nèi)容:
          spring 3.0
          jbpm4.4
          hsqldb
          hibernate
          其中hsqldb和hibernate都是從jbpm4.4的lib文件夾里面拷過去的。
          本篇不再介紹jbpm與spring集成和spring mvc兩方面的內(nèi)容,有需要,請看之前的文章
          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

          本篇只實現(xiàn)兩個功能,上傳流程定義文件和發(fā)布該上傳的流程定義文件。
          使用的流程定義文件是使用上一篇jbpm流程設計器生成的定義文件,
          有關(guān)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 結(jié)束" g="0,0" to="結(jié)束" />
           8</task>
           9<end name="結(jié)束" g="173,188,40,40" />
          10</process>


          RestController.java的發(fā)布處理代碼:

           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        //調(diào)用已定義的Bean
          26      ProcessEngine processEngine = (ProcessEngine) ctx
          27        .getBean("processEngine");
          28      File deployFile = new File(saveFile.getAbsolutePath());
          29      if (deployFile.exists()) {
          30       // 發(fā)布流程
          31       String deploymentId = processEngine
          32         .getRepositoryService().createDeployment()
          33         .addResourceFromFile(deployFile).deploy();
          34       System.out.println("========================ID:"
          35         + deploymentId);
          36       modelMap.put("deploy""發(fā)布成功,版本號為:" + deploymentId);
          37      }

          38
          39     }

          40    }

          41   }

          42  }
           catch (Exception e) {
          43   modelMap.put("deploy""發(fā)布失敗!" );
          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>

          運行效果:




          本人測試環(huán)境:jdk6 + tomcat6.0.20
          源碼: jbpm4.4_spring3

          評論

          # re: 在spring mvc下發(fā)布jbpm流程[未登錄]  回復  更多評論   

          2012-08-22 14:02 by paul
          能給我發(fā)一套源碼嗎?謝謝liufeng_4466@sina.com

          # re: 在spring mvc下發(fā)布jbpm流程  回復  更多評論   

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

          # re: 在spring mvc下發(fā)布jbpm流程  回復  更多評論   

          2013-05-06 20:05 by 郭貝
          東西不錯 求源碼啊!下載不了 hanyijun85@163.com
          主站蜘蛛池模板: 额济纳旗| 米泉市| 禹城市| 富民县| 昭觉县| 万安县| 芒康县| 沭阳县| 五华县| 台安县| 南漳县| 甘肃省| 繁峙县| 东山县| 临沂市| 鄄城县| 蒙阴县| 宜春市| 安吉县| 龙岩市| 开化县| 高唐县| 九江市| 张家港市| 高碑店市| 嫩江县| 新乐市| 荔波县| 南城县| 保亭| 舞钢市| 徐水县| 邵东县| 扎鲁特旗| 贺兰县| 阜宁县| 长春市| 防城港市| 英超| 永安市| 招远市|