2008-05-30
一次部署多个jbpm 流程定义文件
关键字: jbpm 部署
通常我们在部署流程定义文件都需要借助jbpm的eclipse plugin,但是该插件有一个问题,就是每次打开一个流程文件非常的慢,而且一次只能deploy一个流程定义文件,如果有多个流程的话,就需要我们在插件中同时打开多个流程定义文件,这让人感觉非常麻烦.于是我们对流程部署进行了一下改进.
在插件中部署一个流程定义,其实就是将processdefinition.xml文件上传到一个指定的servlet,这个servlet就是org.jbpm.web.ProcessUploadServlet, 而对应的url地址是web.xml中定义的:
因此我们只需要自己写一个jsp页面,将要上传的文件提交到该url(http://myhost:myport/myapp/upload)即可.
通过参看ProcessUploadServlet的源代码,我们发现,它要求上传的文件必须是经过压缩的:
也就是说,我们在上传流程定义文件之间必须将其压缩成zip文件(而且还不能嵌套其他的文件夹,zip里只能包含processdefinition.xml), 因此我们需要对其进行改造一下,能让我们直接上传流程定义xml文件:
接下来是写jsp文件:
这里我借鉴了一下javaeye的application.js来添加多个上传文件:)
在插件中部署一个流程定义,其实就是将processdefinition.xml文件上传到一个指定的servlet,这个servlet就是org.jbpm.web.ProcessUploadServlet, 而对应的url地址是web.xml中定义的:
<servlet> <servlet-name>UploadServlet</servlet-name> <servlet-class> org.jbpm.web.ProcessUploadServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>UploadServlet</servlet-name> <url-pattern>/upload</url-pattern> </servlet-mapping>
因此我们只需要自己写一个jsp页面,将要上传的文件提交到该url(http://myhost:myport/myapp/upload)即可.
通过参看ProcessUploadServlet的源代码,我们发现,它要求上传的文件必须是经过压缩的:
if (fileItem.getContentType().indexOf("application/x-zip-compressed") == -1) {
log.debug("Not a process archive");
return "Not a process archive";
}
try {
log.debug("Deploying process archive " + fileItem.getName());
ZipInputStream zipInputStream = new ZipInputStream(fileItem.getInputStream());
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
log.debug("Preparing to parse process archive");
ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream);
log.debug("Created a processdefinition : " + processDefinition.getName());
jbpmContext.deployProcessDefinition(processDefinition);
zipInputStream.close();
return "Deployed archive " + processDefinition.getName() + " successfully";
} catch (IOException e) {
return "IOException";
}
也就是说,我们在上传流程定义文件之间必须将其压缩成zip文件(而且还不能嵌套其他的文件夹,zip里只能包含processdefinition.xml), 因此我们需要对其进行改造一下,能让我们直接上传流程定义xml文件:
private String handleRequest(HttpServletRequest request) {
//check if request is multipart content
log.debug("Handling upload request");
if (!FileUpload.isMultipartContent(request)) {
log.debug("Not a multipart request");
return "Not a multipart request";
}
String result = "";
try {
DiskFileUpload fileUpload = new DiskFileUpload();
List list = fileUpload.parseRequest(request);
log.debug("Upload from GPD");
for (Iterator it = list.iterator(); it.hasNext();) {
FileItem fileItem = (FileItem) it.next();
if (fileItem.getContentType() == null || fileItem.getContentType().indexOf("text/xml") == -1) {
log.debug("Not a process archive");
continue;
}
try {
log.debug("Deploying process archive " + fileItem.getName());
InputStream is = fileItem.getInputStream();
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
log.debug("Preparing to parse process archive");
ProcessDefinition processDefinition = ProcessDefinition.parseXmlInputStream(is);
log.debug("Created a processdefinition : " + processDefinition.getName());
jbpmContext.deployProcessDefinition(processDefinition);
is.close();
if (StringUtils.isNotEmpty(result)) {
result += ",";
}
result += processDefinition.getName();
} catch (IOException e) {
return "IOException";
}
}
} catch (FileUploadException e) {
e.printStackTrace();
return "FileUploadException";
}
if (StringUtils.isEmpty(result)) {
log.debug("No process file in the request");
return "No process file in the request";
}
return "Deployed process [" + result + "] successfully";
}
接下来是写jsp文件:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Upload Process Definition Xml files</title>
<script src="upload.js" type="text/javascript"></script>
<style>
fieldset {
border: 1px solid #eee;
padding: 5px 10px;
margin: 0;
}
fieldset ul {
list-style: none;
margin: 0 0 1.5em 0;
padding: 0;
}
fieldset ul li {
list-style: none;
margin: 0 0 0.5em 0;
padding: 0;
}
</style>
</head>
<body>
<body>
<form action="<%=request.getContextPath()%>/upload" enctype="multipart/form-data"
id="process_form" method="post">
<fieldset>
<ul>
<li>
<label>
新增流程定义文件
</label>
<input type="file" id="process_upload" />
</li>
<li style="text-align: center">
<input class="submit" id="submit_button" name="commit"
type="submit" value="提交" />
</li>
</ul>
</fieldset>
</form>
<script type="text/javascript">
var multiple_upload_process_counter = 0;
multiple_upload_process($("process_upload"));
</script>
</body>
</html>
这里我借鉴了一下javaeye的application.js来添加多个上传文件:)
评论
还有几种方法来一次性deploy多个流程定义:
1.
<bean id="jbpmConfiguration"
class="xxx.xxx.jbpm.JbpmConfigurationFactoryBean"> -spring-modules的jbpm包里有
<property name="sessionFactory" ref="jbpmSessionFactory" />
<property name="configuration"
value="classpath:jbpm.cfg.xml" />
<property name="processDefinitions">
<list>
<ref local="flow1" />
<ref local="flow2" />
<ref local="flow3" />
</list>
</property>
<property name="createSchema" value="false" />
</bean>
<bean id="flow1"
class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
<property name="definitionLocation"
value="classpath:/flow1/processdefinition.xml" />
2.用ant - DeployProcessTask
1.
<bean id="jbpmConfiguration"
class="xxx.xxx.jbpm.JbpmConfigurationFactoryBean"> -spring-modules的jbpm包里有
<property name="sessionFactory" ref="jbpmSessionFactory" />
<property name="configuration"
value="classpath:jbpm.cfg.xml" />
<property name="processDefinitions">
<list>
<ref local="flow1" />
<ref local="flow2" />
<ref local="flow3" />
</list>
</property>
<property name="createSchema" value="false" />
</bean>
<bean id="flow1"
class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
<property name="definitionLocation"
value="classpath:/flow1/processdefinition.xml" />
2.用ant - DeployProcessTask
发表评论
我的相册
P1100915
共 146 张
共 146 张
最近加入圈子
链接
最新评论
-
电话面试收集
不错,博主应该已经面试过很多人了吧!
-- by sunrise353 -
28岁转行做IT(zt)
25岁以前我还在见证钢铁是怎样炼成的,25岁的时候我想知道网站是怎么回事,于是我 ...
-- by wangyifeng -
28岁转行做IT(zt)
26岁 办证刻章
-- by hellowei -
28岁转行做IT(zt)
我26岁半,以前做通信,见到此文,很高兴.另外,我在ext论坛上好像看到一个 e ...
-- by llp20_2000 -
jms学习笔记
你好,我正在研究JMS,其中有很多问题不明白,希望你能够教我一下,谢谢了,我的q ...
-- by 6308907







评论排行榜