一次部署多个jbpm 流程定义文件

通常我们在部署流程定义文件都需要借助jbpm的eclipse plugin,但是该插件有一个问题,就是每次打开一个流程文件非常的慢,而且一次只能deploy一个流程定义文件,如果有多个流程的话,就需要我们在插件中同时打开多个流程定义文件,这让人感觉非常麻烦.于是我们对流程部署进行了一下改进.
在插件中部署一个流程定义,其实就是将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来添加多个上传文件:)
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页