JBoss Community

Re: How to expose a jbpm workflow as web service.

created by lalit jangra in jBPM - View the full discussion

Hi All,

 

You can use the following code to trigger a workflow in java.

 

/**
     * Method to trigger workflow dynamically.
     */
    public void exposeWorkflowAsWebService(){
        JbpmContext jbpmContext = null;
        try{
            System.out.println("Invoking a workflow");
            jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
            ProcessInstance processInstance = jbpmContext.newProcessInstance("NotificationWorkflow");
            while (!processInstance.isTerminatedImplicitly()) {
                processInstance.signal();           
            }
        }catch (Exception e) {
            System.out.println("Error while invoking workflow : "+e.getMessage());
            e.printStackTrace();
        }finally {       
            System.out.println("Finally closing jbpmContext.");
            jbpmContext.close();   
            }
    } 

 

This java code can be exposed as web service & used as needed.

Reply to this message by going to Community

Start a new discussion in jBPM at Community