I've tried a million methods for trying to create and deploy a .Par file from within an ActionHandler. Does anyone have sample code that accomplishes this?
Here is my code that never quite works (you can see all the different methods I used by looked at the commented code.) | package com.sample.action; | | import java.io.File; | import java.io.FileInputStream; | import java.io.FileOutputStream; | import java.io.FileWriter; | import java.io.BufferedWriter; | import java.io.IOException; | import java.io.BufferedInputStream; | import java.io.InputStream; | import java.util.zip.ZipInputStream; | import java.util.zip.ZipOutputStream; | import java.util.zip.ZipEntry; | import com.sample.action.ZipUtilityDefinitiva; | | import org.jbpm.instantiation.ClassLoaderUtil; | import org.jbpm.jpdl.par.ProcessArchive; | import org.jbpm.jpdl.par.ProcessArchiveDeployerDbTest; | | import org.apache.commons.logging.Log; | import org.apache.commons.logging.LogFactory; | | | import org.jbpm.graph.def.ActionHandler; | import org.jbpm.graph.def.ProcessDefinition; | import org.jbpm.graph.exe.ExecutionContext; | import org.jbpm.jpdl.par.ProcessArchiveDeployer; | | public class CreateEmailPestActionHandler implements ActionHandler { | | static final int BUFFERSIZE = 4096; | | private static void addEntry(ZipOutputStream zipOutputStream, String entryName, String resource) throws IOException { | FileInputStream fi = new FileInputStream(resource); | InputStream inputStream = fi; | //InputStream inputStream = ClassLoaderUtil.getStream(resource); | byte[] bytes = readBytes(inputStream); | addEntry(zipOutputStream, entryName, bytes); | } | | private static void addEntry(ZipOutputStream zipOutputStream, String entryName, byte[] content) throws IOException { | ZipEntry zipEntry = new ZipEntry(entryName); | zipOutputStream.putNextEntry(zipEntry); | zipOutputStream.write(content); | } | | private static final long serialVersionUID = 1L; | | /** | * Logger for this class | */ | private static final Log logger = LogFactory.getLog(CreateEmailPestActionHandler.class); | | //String email_pest_to; | //String from; | //String subject; | //String body; | //String timerDue; | //String repeatTimer; | | /** | * A message process variable is assigned the value of the message | * member. The process variable is created if it doesn't exist yet. | */ | | //String getTestClassesDir() { | // return ProcessArchiveDeployerDbTest.class.getProtectionDomain().getCodeSource().getLocation().getFile(); | //} | | static byte[] readBytes(InputStream inputStream) throws IOException { | byte[] bytes = null; | if (inputStream==null) { | throw new NullPointerException("inputStream is null in ProcessArchive.readBytes()"); | } | byte[] buffer = new byte[BUFFERSIZE]; | int bytesRead = 0; | while ( (bytesRead = inputStream.read(buffer)) != -1) { | if (bytes!=null) { | byte[] oldBytes = bytes; | bytes = new byte[oldBytes.length+bytesRead]; | System.arraycopy(oldBytes, 0, bytes, 0, oldBytes.length); | System.arraycopy(buffer, 0, bytes, oldBytes.length, bytesRead); | } else { | bytes = new byte[bytesRead]; | System.arraycopy(buffer, 0, bytes, 0, bytesRead); | } | } | return bytes; | } | | public void execute(ExecutionContext context) throws Exception { | | String to = context.getVariable("email_pest_to").toString(); | String from = context.getVariable("email_pest_from").toString(); | String subject = context.getVariable("email_pest_subject").toString(); | String body = context.getVariable("email_pest_body").toString(); | String time_due = context.getVariable("email_pest_due").toString(); | String time_repeat = context.getVariable("email_pest_repeat").toString(); | logger.debug("****updated???To: "+ to +" From: " + from +" Time Due: "+ time_due ); | | try { | BufferedWriter out = new BufferedWriter(new FileWriter("/temp/processdefinition.xml")); | out.write( | //ProcessDefinition pd = ProcessDefinition.parseXmlString( | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | "<process-definition name=\"Email_Launcher\">\n" + | "<start-state name=\"Updated version from Actionclass\">\n" + | "<task>" + | "<controller>" + | "<variable name=\"email_pest_to\" access=\"write\" mapped-name=\"From Email Timer par\"></variable>" + | "</controller>" + | "</task>" + | "<transition name=\"tr1\" to=\"Task With Timer and Reminder\"></transition>\n" + | "</start-state>\n" + | "<task-node name=\"Task With Timer and Reminder\">\n" + | "<task name=\"Task Finished?\">\n" + | "<assignment class=\"com.sample.action.GenericAssignmentHandler\">\n" + | "</assignment>\n" + | "<controller>\n" + | "<variable name=\"finished\" mapped-name=\"differenceDid they finish task?\"></variable>\n" + | "</controller>\n" + | "<timer name=\"Email reminder\" duedate=\"30 seconds\" repeat=\"60 seconds\">\n" + | "<action class='com.sample.action.EmailTimerActionHandler'>\n" + | "<to>[EMAIL PROTECTED]</to>\n" + | "<from>[EMAIL PROTECTED]</from>\n" + | "<subject>Here is the subject from EmailActionHandler</subject>\n" + | "<body>Here is the body from EmailActionHandler</body>\n" + | "</action>\n" + | "</timer>\n" + | "</task>\n" + | "<transition name=\"tr1\" to=\"end1\"></transition>\n" + | "</task-node>\n" + | "<end-state name=\"end1\"></end-state>\n" + | "</process-definition>" | ); | | //ProcessArchiveDeployer.deployProcessDefinition(pd); | out.close(); | } catch (IOException e) { | } | | //FileInputStream fi = new FileInputStream("/usr/local/jbpm.3/src/processes.to.deploy/EmailTimerProcess.par/processdefinition.xml"); | //BufferedInputStream bufferedInputStream = new BufferedInputStream(fi); | //ZipEntry entry = new ZipEntry("processdefinition.xml"); | //ZipOutputStream zipOutputStream=null; | | //this.filesCompression("/temp/EmailTimerProcess.par","/usr/local/jbpm.3/src/processes.to.deploy/EmailTimerProcess.par"); | //File anotherName = new File("/usr/local/jbpm.3/src/processes.to.deploy/EmailTimerProcess.par"); | | //ZipUtilityDefinitiva.filesCompression(anotherName, "/temp/EmailTimerProcess.par" ); | | // create a process archive file and save it to disk | //logger.debug("****************About to start creating .Par file***********"); | | String fileName = "/usr/local/jbpm.3/build/EmailTimerClasses.par"; | FileOutputStream fileOutputStream = new FileOutputStream(fileName); | ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream); | addEntry(zipOutputStream, "processdefinition.xml", "/temp/processdefinition.xml"); | addEntry(zipOutputStream, "gpd.xml", "/temp/gpd.xml"); | addEntry(zipOutputStream, "processimage.jpg", "/temp/processimage.jpg"); | zipOutputStream.close(); | logger.debug("*****It looks like the par file is being created okay, check it****"); | | | //String parFileName = "/usr/local/jbpm.3/build/EmailTimerProcess.par"; | //ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(parFileName)); | //ZipEntry zipEntry = new ZipEntry(processdefbytearray); | | | ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream("/usr/local/jbpm.3/build/EmailTimerClasses.par")); | logger.debug("*****Zip file is being uptaken..next is deployment ****"); | ProcessArchiveDeployer.deployZipInputStream(zipInputStream); | | | | | | } | } | View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3911880#3911880 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3911880 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user