[jbpm-commits] JBoss JBPM SVN: r5467 - jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Aug 12 03:06:07 EDT 2009
Author: alex.guizar at jboss.com
Date: 2009-08-12 03:06:07 -0400 (Wed, 12 Aug 2009)
New Revision: 5467
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java
projects/jsf-console/branches/jsf-console-3.2-soa/console/src/main/java/org/jbpm/web/ProcessUploadServlet.java
Log:
[JBPM-2475] sub-process name is not resolved upon deployment with Eclipse or ant-task
open jbpm context before parsing in both deploy task and upload servlet
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java 2009-08-11 22:47:33 UTC (rev 5466)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java 2009-08-12 07:06:07 UTC (rev 5467)
@@ -25,7 +25,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipInputStream;
@@ -38,100 +37,97 @@
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.jpdl.JpdlException;
+import org.jbpm.util.ArrayUtil;
/**
* ant task for deploying process archives.
*/
public class DeployProcessTask extends MatchingTask {
- String jbpmCfg = null;
- File process = null;
- List fileSets = new ArrayList();
- boolean failOnError = true;
+ String jbpmCfg;
+ File process;
+ List fileSets = new ArrayList();
+ boolean failOnError = true;
- public void execute() throws BuildException {
- // get the JbpmConfiguration
- JbpmConfiguration jbpmConfiguration = AntHelper.getJbpmConfiguration(jbpmCfg);
-
- // if attribute process is set, deploy that process file
- if (process!=null) {
- deployProcessArchive(jbpmConfiguration, process);
- }
-
- // loop over all files that are specified in the filesets
- Iterator iter = fileSets.iterator();
- while (iter.hasNext()) {
- FileSet fileSet = (FileSet) iter.next();
- DirectoryScanner dirScanner = fileSet.getDirectoryScanner(getProject());
- File baseDir = dirScanner.getBasedir();
- String[] includedFiles = dirScanner.getIncludedFiles();
- List excludedFiles = Arrays.asList(dirScanner.getExcludedFiles());
+ public void execute() throws BuildException {
+ // get the JbpmConfiguration
+ JbpmConfiguration jbpmConfiguration = AntHelper.getJbpmConfiguration(jbpmCfg);
- for (int i = 0; i < includedFiles.length; i++) {
- String fileName = includedFiles[i];
- if (!excludedFiles.contains(fileName)) {
- File file = new File(baseDir, fileName);
- deployProcessArchive(jbpmConfiguration, file);
- }
- }
- }
- }
+ // if attribute process is set, deploy that process file
+ if (process != null) {
+ handleProcessFile(jbpmConfiguration, process);
+ }
- private void deployProcessArchive(JbpmConfiguration jbpmConfiguration, File processFile) {
- try {
- log("deploying process from archive "+processFile.getName());
- ProcessDefinition processDefinition = parseProcessArchive(processFile);
- deployProcessDefinition(processDefinition, jbpmConfiguration);
- }
- catch (IOException e) {
- log("failed to read process archive " + processFile.getName(), e, Project.MSG_ERR);
- throw new BuildException(e.getMessage(), e);
- }
- catch (JpdlException e) {
- log("archive " + processFile.getName() + " contains invalid process", e, Project.MSG_ERR);
- throw e;
- }
- }
+ // iterate over file sets
+ for (Iterator iter = fileSets.iterator(); iter.hasNext();) {
+ FileSet fileSet = (FileSet) iter.next();
+ DirectoryScanner dirScanner = fileSet.getDirectoryScanner(getProject());
+ File baseDir = dirScanner.getBasedir();
+ String[] includedFiles = dirScanner.getIncludedFiles();
+ String[] excludedFiles = dirScanner.getExcludedFiles();
- private ProcessDefinition parseProcessArchive(File processFile) throws IOException {
- ZipInputStream processStream = new ZipInputStream(new FileInputStream(processFile));
- try {
- ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(processStream);
- log("created process definition " + processDefinition.getName());
- return processDefinition;
- }
- finally {
- processStream.close();
- }
- }
+ for (int i = 0; i < includedFiles.length; i++) {
+ String fileName = includedFiles[i];
+ if (!ArrayUtil.contains(excludedFiles, fileName))
+ handleProcessFile(jbpmConfiguration, new File(baseDir, fileName));
+ }
+ }
+ }
- private void deployProcessDefinition(ProcessDefinition processDefinition, JbpmConfiguration jbpmConfiguration) {
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
- jbpmContext.deployProcessDefinition(processDefinition);
- log("deployed process " + processDefinition.getName() + " successfully");
- }
- catch (RuntimeException e) {
- jbpmContext.setRollbackOnly();
- log("failed to deploy process " + processDefinition.getName(), e, Project.MSG_ERR);
- throw e;
- }
- finally {
- jbpmContext.close();
- }
- }
+ private void handleProcessFile(JbpmConfiguration jbpmConfiguration, File processFile) {
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ try {
+ log("parsing process archive " + processFile.getName());
+ ProcessDefinition processDefinition = parseProcessArchive(processFile);
+ deployProcessDefinition(processDefinition, jbpmContext);
+ }
+ catch (IOException e) {
+ log("error reading process archive " + processFile.getName(), e, Project.MSG_ERR);
+ if (failOnError) throw new BuildException(e, getLocation());
+ }
+ finally {
+ jbpmContext.close();
+ }
+ }
- public void addFileset(FileSet fileSet) {
- this.fileSets.add(fileSet);
- }
- public void setJbpmCfg(String jbpmCfg) {
- this.jbpmCfg = jbpmCfg;
- }
- public void setProcess(File process) {
- this.process = process;
- }
- public void setFailOnError(boolean failOnError) {
- this.failOnError = failOnError;
- }
+ private ProcessDefinition parseProcessArchive(File processFile) throws IOException {
+ ZipInputStream processStream = new ZipInputStream(new FileInputStream(processFile));
+ try {
+ ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(processStream);
+ log("parsed process definition " + processDefinition.getName());
+ return processDefinition;
+ }
+ finally {
+ processStream.close();
+ }
+ }
+
+ private void deployProcessDefinition(ProcessDefinition processDefinition,
+ JbpmContext jbpmContext) {
+ try {
+ jbpmContext.deployProcessDefinition(processDefinition);
+ log("process definition " + processDefinition.getName() + " deployed successfully");
+ }
+ catch (RuntimeException e) {
+ jbpmContext.setRollbackOnly();
+ log("failed to deploy process " + processDefinition.getName(), e, Project.MSG_ERR);
+ if (failOnError) throw new BuildException(e, getLocation());
+ }
+ }
+
+ public void addFileset(FileSet fileSet) {
+ this.fileSets.add(fileSet);
+ }
+
+ public void setJbpmCfg(String jbpmCfg) {
+ this.jbpmCfg = jbpmCfg;
+ }
+
+ public void setProcess(File process) {
+ this.process = process;
+ }
+
+ public void setFailOnError(boolean failOnError) {
+ this.failOnError = failOnError;
+ }
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java 2009-08-11 22:47:33 UTC (rev 5466)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ArrayUtil.java 2009-08-12 07:06:07 UTC (rev 5467)
@@ -26,71 +26,95 @@
*/
public class ArrayUtil {
- private ArrayUtil() {
- // hide default constructor to prevent instantiation
- }
+ private ArrayUtil() {
+ // hide default constructor to prevent instantiation
+ }
- /**
- * Returns a string representation of the contents of the specified array. If the array contains
- * other arrays as elements, they are converted to strings by the {@link Object#toString} method
- * inherited from <tt>Object</tt>, which describes their <i>identities</i> rather than their
- * contents.
- * <p>
- * The value returned by this method is equal to the value that would be returned by
- * <tt>Arrays.asList(a).toString()</tt>, unless <tt>a</tt> is <tt>null</tt>, in which case
- * <tt>"null"</tt> is returned.
- *
- * @param a the array whose string representation to return
- * @return a string representation of <tt>a</tt>
- * @see <a
- * href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#toString(Object[])">
- * java.util.Arrays.toString(Object[])</a>
- */
- public static String toString(Object[] a) {
- if (a == null) return "null";
- if (a.length == 0) return "[]";
+ /**
+ * Returns a string representation of the contents of the specified array. If the array
+ * contains other arrays as elements, they are converted to strings by the
+ * {@link Object#toString} method inherited from <tt>Object</tt>, which describes their
+ * <i>identities</i> rather than their contents.
+ * <p>
+ * The value returned by this method is equal to the value that would be returned by
+ * <tt>Arrays.asList(a).toString()</tt>, unless the array is <tt>null</tt>, in which case
+ * <tt>"null"</tt> is returned.
+ *
+ * @param a the array whose string representation to return
+ * @return a string representation of <tt>a</tt>
+ * @see <a
+ * href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#toString(Object[])">
+ * java.util.Arrays.toString(Object[])</a>
+ */
+ public static String toString(Object[] a) {
+ if (a == null) return "null";
+ if (a.length == 0) return "[]";
- StringBuffer buf = new StringBuffer();
+ StringBuffer buf = new StringBuffer();
+ buf.append('[').append(a[0]);
- for (int i = 0; i < a.length; i++) {
- if (i == 0)
- buf.append('[');
- else
- buf.append(", ");
+ for (int i = 1; i < a.length; i++) {
+ buf.append(", ").append(a[i]);
+ }
- buf.append(String.valueOf(a[i]));
- }
+ return buf.append(']').toString();
+ }
- buf.append("]");
- return buf.toString();
- }
+ /**
+ * Returns a string representation of the contents of the specified array. The string
+ * representation consists of a list of the array's elements, enclosed in square brackets (
+ * <tt>"[]"</tt>). Adjacent elements are separated by the characters <tt>", "</tt> (a comma
+ * followed by a space). Elements are converted to strings by <tt>String.valueOf(long)</tt>.
+ * Returns <tt>"null"</tt> if the array is <tt>null</tt>.
+ *
+ * @param a the array whose string representation to return
+ * @return a string representation of <tt>a</tt>
+ * @see <a
+ * href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#toString(long[])">
+ * java.util.Arrays.toString(long[])</a>
+ */
+ public static String toString(long[] a) {
+ if (a == null) return "null";
+ if (a.length == 0) return "[]";
- /**
- * Returns a string representation of the contents of the specified array. The string
- * representation consists of a list of the array's elements, enclosed in square brackets (
- * <tt>"[]"</tt>). Adjacent elements are separated by the characters <tt>", "</tt> (a comma
- * followed by a space). Elements are converted to strings as by <tt>String.valueOf(long)</tt>.
- * Returns <tt>"null"</tt> if <tt>a</tt> is <tt>null</tt>.
- *
- * @param a the array whose string representation to return
- * @return a string representation of <tt>a</tt>
- * @see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#toString(long[])">
- * java.util.Arrays.toString(long[])</a>
- */
- public static String toString(long[] a) {
- if (a == null) return "null";
- if (a.length == 0) return "[]";
+ StringBuffer buf = new StringBuffer();
+ buf.append('[');
+ buf.append(a[0]);
- StringBuffer buf = new StringBuffer();
- buf.append('[');
- buf.append(a[0]);
+ for (int i = 1; i < a.length; i++) {
+ buf.append(", ").append(a[i]);
+ }
- for (int i = 1; i < a.length; i++) {
- buf.append(", ");
- buf.append(a[i]);
- }
+ return buf.append(']').toString();
+ }
- buf.append("]");
- return buf.toString();
- }
+ /**
+ * Returns the index in the given array of the first occurrence of the specified element, or
+ * -1 if the array does not contain this element.
+ *
+ * @param o element to search for.
+ * @return the index of the first occurrence of the specified element, or -1 if the array does
+ * not contain this element.
+ */
+ public static int indexOf(Object[] a, Object o) {
+ if (o == null) {
+ for (int i = 0; i < a.length; i++)
+ if (a[i] == null) return i;
+ }
+ else {
+ for (int i = 0; i < a.length; i++)
+ if (o.equals(a[i])) return i;
+ }
+ return -1;
+ }
+
+ /**
+ * Tells whether the given array contains the specified element.
+ *
+ * @param o element whose presence in the array is to be tested.
+ * @return <tt>true</tt> if the array contains the specified element.
+ */
+ public static boolean contains(Object[] a, Object o) {
+ return indexOf(a, o) != -1;
+ }
}
Modified: projects/jsf-console/branches/jsf-console-3.2-soa/console/src/main/java/org/jbpm/web/ProcessUploadServlet.java
===================================================================
--- projects/jsf-console/branches/jsf-console-3.2-soa/console/src/main/java/org/jbpm/web/ProcessUploadServlet.java 2009-08-11 22:47:33 UTC (rev 5466)
+++ projects/jsf-console/branches/jsf-console-3.2-soa/console/src/main/java/org/jbpm/web/ProcessUploadServlet.java 2009-08-12 07:06:07 UTC (rev 5467)
@@ -22,6 +22,9 @@
package org.jbpm.web;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
import java.util.zip.ZipInputStream;
import org.apache.commons.fileupload.FileItem;
@@ -43,95 +46,138 @@
public class ProcessUploadServlet extends javax.servlet.http.HttpServlet {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private JbpmConfiguration jbpmConfiguration;
+ private JbpmConfiguration jbpmConfiguration;
- public void init() throws ServletException {
- String jbpmCfgResource = getServletContext().getInitParameter("jbpm.configuration.resource");
- jbpmConfiguration = JbpmConfiguration.getInstance(jbpmCfgResource);
- }
+ public void init() throws ServletException {
+ String jbpmCfgResource = getServletContext().getInitParameter("jbpm.configuration.resource");
+ jbpmConfiguration = JbpmConfiguration.getInstance(jbpmCfgResource);
+ }
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- log.debug("Handling status request");
- response.getWriter().println("Process upload module is operational");
- }
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ if (log.isTraceEnabled()) log.trace("handling status request");
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- log.debug("Handling upload request");
- response.getWriter().println(handleRequest(request));
- }
+ PrintWriter out = response.getWriter();
+ writeHeader(out);
+ out.println("<h3>Deploy a process</h3>");
+ out.println("<form name='deploy-form' method='post' enctype='multipart/form-data'>");
+ out.println(" <p>Process Archive: <input name='process-archive' type='file'/>");
+ out.println(" <p><input name='deploy-button' type='submit' value='Deploy'/>");
+ out.println("</form>");
+ writeTrailer(out);
+ }
- private String handleRequest(HttpServletRequest request) {
- // check if request is multipart content
- if (!ServletFileUpload.isMultipartContent(request)) {
- log.debug("Not a multipart request");
- return "Not a multipart request";
- }
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ if (log.isTraceEnabled()) log.trace("handling upload request");
- try {
- // Create a factory for disk-based file items
- FileItemFactory factory = new DiskFileItemFactory();
- // Create a new file upload handler
- ServletFileUpload upload = new ServletFileUpload(factory);
- // Parse the request
- List itemList= upload.parseRequest(request);
- log.debug("Upload from GPD");
- if (itemList.isEmpty()) {
- log.debug("No process file in the request");
- return "No process file in the request";
- }
- FileItem fileItem = (FileItem) itemList.get(0);
- 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 from archive " + fileItem.getName());
- ProcessDefinition processDefinition = parseProcessArchive(fileItem);
- deployProcessDefinition(processDefinition);
- return "Deployed process " + processDefinition.getName() + " successfully";
- }
- catch (IOException e) {
- log.debug("Failed to read process archive", e);
- return "IOException";
- }
- }
- catch (FileUploadException e) {
- log.debug("Failed to parse HTTP request", e);
- return "FileUploadException";
- }
- }
+ FileItem processItem = parseRequest(request, response);
+ if (processItem == null) return; // error has been sent
- private ProcessDefinition parseProcessArchive(FileItem fileItem) throws IOException {
- ZipInputStream processStream = new ZipInputStream(fileItem.getInputStream());
- try {
- ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(processStream);
- log.debug("Created process " + processDefinition.getName());
- return processDefinition;
- }
- finally {
- processStream.close();
- }
- }
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ try {
+ ProcessDefinition processDefinition = parseProcessArchive(processItem);
+ deployProcessDefinition(processDefinition, response);
+ }
+ finally {
+ jbpmContext.close();
+ }
+ }
- private void deployProcessDefinition(ProcessDefinition processDefinition) {
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
- jbpmContext.deployProcessDefinition(processDefinition);
- log.debug("Deployed process " + processDefinition.getName() + " successfully");
- }
- catch (RuntimeException e) {
- jbpmContext.setRollbackOnly();
- log.error("Failed to deploy process " + processDefinition.getName(), e);
- throw e;
- }
- finally {
- jbpmContext.close();
- }
- }
+ private void writeHeader(PrintWriter out) throws MalformedURLException {
+ out.println("<html>");
+ out.println("<head>");
+ out.println("<title>Process Deployment</title>");
+ URL css = getServletContext().getResource("/ua/jbpm.css");
+ if (css != null) {
+ out.print("<link rel='stylesheet' type='text/css' href='");
+ out.print(css.toString());
+ out.println("'/>");
+ }
+ out.println("</head>");
+ out.println("<body>");
+ }
- private static final Log log = LogFactory.getLog(ProcessUploadServlet.class);
+ private void writeTrailer(PrintWriter out) {
+ out.println("</body>");
+ out.println("</html>");
+ }
+
+ private FileItem parseRequest(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ // check if request is multipart content
+ if (!ServletFileUpload.isMultipartContent(request)) {
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Not a multipart request");
+ return null;
+ }
+
+ // Create a factory for disk-based file items
+ FileItemFactory factory = new DiskFileItemFactory();
+ // Create a new file upload handler
+ ServletFileUpload upload = new ServletFileUpload(factory);
+ try {
+ // Parse the request
+ List items = upload.parseRequest(request);
+ if (items.isEmpty()) {
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request is empty");
+ return null;
+ }
+ FileItem item = (FileItem) items.get(0);
+ if (item.isFormField()) {
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Field '" + item.getFieldName()
+ + "' is not an input file");
+ return null;
+ }
+ return item;
+ }
+ catch (FileUploadException e) {
+ log.error("failed to parse request", e);
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Failed to parse request");
+ return null;
+ }
+ }
+
+ private ProcessDefinition parseProcessArchive(FileItem fileItem) throws IOException {
+ if (log.isTraceEnabled()) log.trace("parsing process archive " + fileItem.getName());
+
+ ZipInputStream processStream = new ZipInputStream(fileItem.getInputStream());
+ try {
+ ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(processStream);
+ if (log.isTraceEnabled())
+ log.trace("parsed process definition " + processDefinition.getName());
+ return processDefinition;
+ }
+ finally {
+ processStream.close();
+ }
+ }
+
+ private void deployProcessDefinition(ProcessDefinition processDefinition,
+ HttpServletResponse response) throws IOException {
+ String processName = processDefinition.getName();
+ JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
+ try {
+ jbpmContext.deployProcessDefinition(processDefinition);
+
+ if (log.isTraceEnabled()) log.trace("deployed process definition " + processName);
+ PrintWriter out = response.getWriter();
+ writeHeader(out);
+ out.println("<h3>Deployment report</h3>");
+ out.print("<p>Deployed process ");
+ out.print(processName);
+ out.println(" successfully</p>");
+ writeTrailer(out);
+ }
+ catch (RuntimeException e) {
+ jbpmContext.setRollbackOnly();
+
+ log.error("failed to deploy process definition " + processName, e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ "Failed to deploy process");
+ }
+ }
+
+ private static final Log log = LogFactory.getLog(ProcessUploadServlet.class);
}
\ No newline at end of file
More information about the jbpm-commits
mailing list