no prob. here's the whole sample program demonstrating how to simulate
synchronous response from a workflow. my idea is to place a
participant with a store (role-bravo and Store.bravo in this case) at
the end of the workflow, while the previous participants are automatic
and they produce some output in workitem. at the end, the workflow
pauses at the last participant and the workitem is accessible in
respective store. in the meantime, the client app asks the engine if
there is a workitem of its interest present in the specified store. if
yes, then the workitem is fetched, the client can process it and
return it back, so the workflow can finish (of course, only if this
participant was the last expression of the workflow).
this is an answer for the problem I posted here a month ago, namely:
how to launch workflows synchronously. it's a workaround of course,
but it works :). I hope you'll find it useful.
---cut
here---------------------------------------------------------------------------------------------------------------------
package wftest;
import java.lang.*;
import java.net.URL;
import java.net.URLConnection;
import java.rmi.Naming;
import java.util.*;
import openwfe.org.engine.expressions.FlowExpressionId;
import openwfe.org.rmi.session.WorkSessionServer;
import openwfe.org.engine.workitem.LaunchItem;
import openwfe.org.engine.workitem.InFlowWorkItem;
import openwfe.org.worklist.Header;
import openwfe.org.worklist.WorkSession;
import openwfe.org.engine.workitem.StringAttribute;
import java.io.*;
import org.jdom.input.*;
import org.jdom.*;
import java.util.regex.*;
/**
*
* @author bart
*/
public class Main
{
public static void main(String[] args)
{
// TODO code application logic here
String worklistURL = "rmi://localhost:7099/workSessionServer";
String engineURL = "http://localhost:7079/";
String workflowName = "chujnia.xml";
try
{
WorkSessionServer sessionServer =
(WorkSessionServer)Naming.lookup(worklistURL);
WorkSession workSession =
(WorkSession)sessionServer.login("admin", "admin");
LaunchItem li = new LaunchItem();
// telling which flow will get launched
li.setWorkflowDefinitionUrl(engineURL + workflowName);
// adding something to the payload
li.getAttributes().put("__subject__", "chujnia nie spi");
// launching the flow on the engine "mainEngine"
String wfid = workSession.launch("mainEngine", li);
Pattern p = Pattern.compile("[0-9]{7,}");
Matcher m = p.matcher(wfid);
if(m.find())
wfid = m.group();
// polling engine for the presence of any workitems in "Store.bravo"
while(true)
{
URL url = new URL("http://localhost:7078");
URLConnection c = url.openConnection(); // connect to
openwfe's "Status" web service
InputStream is = c.getInputStream();
SAXBuilder b = new SAXBuilder();
Document status = b.build(is);
// get the <realStorage> element
Element rs = status.getRootElement().getChild("realStorage");
if(rs != null)
{
// now get the <stores> element
Element stores = rs.getChild("stores");
if(stores != null)
{
// if <Store.bravo> element is present, it
means there is at least one workitem present
if(stores.getChild("Store.bravo") != null)
{
// get the workitem headers from our store
List l = workSession.getHeaders("Store.bravo", 10);
if(l.size() > 0)
{
// while break condition
boolean brk = false;
for(int i=0; i<l.size(); i++)
{
Header h = (Header)l.get(i);
if(wfid.equals(h.getExpressionId().getWorkflowInstanceId()))
{
InFlowWorkItem wi =
workSession.getAndLock("Store.bravo", h.getExpressionId());
// pass the workitem forward
workSession.proceed("Store.bravo", wi);
brk = true;
break;
}
}
if(brk)
break;
}
}
}
}
}
}
catch(Exception e)
{
System.out.println("err");
e.printStackTrace();
}
}
}
---cut
here---------------------------------------------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"OpenWFE users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/openwfe-users?hl=en
-~----------~----~----~----~------~----~------~--~---