浏览 3984 次
锁定老帖子 主题: jbpm与ssh完整示例(二)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-01-10
代码如下: 1 deployjbpm.jsp下选择zip压缩文件上传 <%@ page contentType="text/html;charset=UTF-8"%> <%@ include file="/commons/taglibs.jsp"%> <html> <head> </head> <body> <form action="${ctx}/jbpmdeploy.do?method=deploy" enctype="multipart/form-data" method="post" /> 选择zip类型流程上传 : <input type="file" name="file" /> <br/> <input type="submit"> </form> </body> </html> 2 struts中的action文件 import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.shane.commons.core.web.StrutsAction; import com.shane.security.service.UploadProcessManager; public class JbpmAction extends StrutsAction { private static Log log = LogFactory.getLog(JbpmAction.class); private UploadProcessManager uploadProcessManager; public void setUploadProcessManager(UploadProcessManager uploadProcessManager) { this.uploadProcessManager = uploadProcessManager; } /** * 上传流程文件 * @param mapping * @param form * @param request * @param response * @return */ public ActionForward deploy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception { log.info("执行流程部署!"); log.info(uploadProcessManager.handleRequest(request)); return mapping.findForward("delpoyindex"); } } 3 Service类,使用时要修改自已的hibernate的封装。代码中使用spring的设置式注入方式。相关文件可以自行编写。本方式是根据jbpm自带的示例改写。 3.1接口定义 import java.io.IOException; import javax.servlet.http.HttpServletRequest; public interface UploadProcessManager { public void printInput(HttpServletRequest request) throws IOException; public String handleRequest(HttpServletRequest request); } 3.2实现类 import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import java.util.List; import java.util.zip.ZipInputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload.DiskFileUpload; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUpload; import org.apache.commons.fileupload.FileUploadException; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.graph.def.ProcessDefinition; import com.shane.commons.core.dao.HibernateEntityDao; public class UploadProcessManagerImpl extends HibernateEntityDao implements UploadProcessManager{ private JbpmConfiguration jbpmConfiguration; public void printInput(HttpServletRequest request) throws IOException { InputStream inputStream = request.getInputStream(); StringBuffer buffer = new StringBuffer(); int read; while ((read = inputStream.read()) != -1) { buffer.append((char)read); } } public String handleRequest(HttpServletRequest request) { if (!FileUpload.isMultipartContent(request)) { return "Not a multipart request"; } try { DiskFileUpload fileUpload = new DiskFileUpload(); List list = fileUpload.parseRequest(request); Iterator iterator = list.iterator(); if (!iterator.hasNext()) { return "No process file in the request"; } FileItem fileItem = (FileItem)iterator.next(); if (fileItem.getContentType().indexOf("application/x-zip-compressed") == -1) { return "Not a process archive"; } return doDeployment(fileItem); } catch (FileUploadException e) { e.printStackTrace(); return "FileUploadException"; } } public String doDeployment(FileItem fileItem) { try { ZipInputStream zipInputStream = new ZipInputStream(fileItem.getInputStream()); JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext(); if(jbpmContext == null) { jbpmContext = this.getJbpmContext(); } ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream); jbpmContext.deployProcessDefinition(processDefinition); zipInputStream.close(); return "Deployed archive " + processDefinition.getName() + " successfully"; } catch (IOException e) { return "IOException"; } } private JbpmContext getJbpmContext(){ JbpmContext context = jbpmConfiguration.getInstance().createJbpmContext(); context.setSession(this.getSession()); return context; } public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) { this.jbpmConfiguration = jbpmConfiguration; } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-01-12
谢谢啊, 好文章, 学到很多东西。
期待更新,谢谢 ! |
|
返回顶楼 | |
发表时间:2009-02-12
期待上传完整的项目。哈哈。
|
|
返回顶楼 | |
发表时间:2009-06-15
如果有完整的项目就好了
|
|
返回顶楼 | |