Discussion:
[jboss-user] [jBPM] - How to start new process from workItemHandler in jBpm 5.4
vijay saini
2013-02-18 06:04:26 UTC
Permalink
vijay saini [https://community.jboss.org/people/vijaykr] created the discussion

"How to start new process from workItemHandler in jBpm 5.4"

To view the discussion, visit: https://community.jboss.org/message/798110#798110

--------------------------------------------------------------
I want to start new instance of a process from workItemHandler of a customize service task.
To achive this I created Service task in Process 1 and call Process 2 from workItemHandler class of service using RestFul link
"/gwt-console-server/rs/process/definition/{id}/new_instance".but when I start Process 1 I am getting Exception

* URL: ' http://localhost:8080/gwt-console-server/rs/process/definition/hello/new_instance http://localhost:8080/gwt-console-server/rs/process/definition/hello/new_instance' 
* Action: 'org.jboss.bpm.console.client.process.StartNewInstanceAction'
* Exception: 'class java.io.IOException'
Request timeout

Please any one can help me to do this intercommunication between two Processes using Restful link.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/798110#798110]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vijay saini
2013-02-18 11:46:39 UTC
Permalink
vijay saini [https://community.jboss.org/people/vijaykr] created the discussion

"Re: How to start new process from workItemHandler in jBpm 5.4"

To view the discussion, visit: https://community.jboss.org/message/798146#798146

--------------------------------------------------------------
can any one answer my query..?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/798146#798146]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
snowstorm tech
2013-02-22 06:34:19 UTC
Permalink
snowstorm tech [https://community.jboss.org/people/snowstormuser] created the discussion

"Re: How to start new process from workItemHandler in jBpm 5.4"

To view the discussion, visit: https://community.jboss.org/message/799008#799008

--------------------------------------------------------------
Hi https://community.jboss.org/people/vijaykr vijay saini,
Use the following programme may be help you,
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
public class StartProcessWV {
     private static final String authentication_url = " http://localhost:8080/gwt-console-server/rs/identity/secure/j_security_check http://localhost:8080/gwt-console-server/rs/identity/secure/j_security_check";
//private static final String process_start_url = " http://localhost:8080/gwt-console-server/rs/process/definition/defaultPackage.ProcessWV/new_instance http://localhost:8080/gwt-console-server/rs/process/definition/defaultPackage.ProcessWV/new_instance";
private static final String process_start_url = " http://localhost:8080/gwt-console-server/rs/form/process/defaultPackage.ProcessWV/complete http://localhost:8080/gwt-console-server/rs/form/process/defaultPackage.ProcessWV/complete";
private static final String render_form_url = " http://localhost:8080/gwt-console-server/rs/form/process/defaultPackage.ProcessWV/render http://localhost:8080/gwt-console-server/rs/form/process/defaultPackage.ProcessWV/render";
     public static String KEY_USERNAME = "j_username";
public static String KEY_PASSWORD = "j_password";
private DefaultHttpClient httpClient = new DefaultHttpClient(); // keep this out of the method in order to reuse the object for calling other services without losing session
public String authenticate(String address, String username, String password) {
        String responseString = "";
      //  new NameValuePair("j_username", username)
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair(KEY_USERNAME, username));
        formparams.add(new BasicNameValuePair(KEY_PASSWORD, password));
HttpPost httpPost = new HttpPost( address );
       // HttpPost httpPost = new HttpPost(" http:// http://" + address + "/gwt-console-server/rs/process/j_security_check");
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        try {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
            //UrlEncodedFormEntity entity=new UrlEncodedFormEntity(formparams, "multipart/form-data");
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost);
            InputStream inputStream = response.getEntity().getContent();
            inputStreamReader = new InputStreamReader(inputStream);
            bufferedReader = new BufferedReader(inputStreamReader);
            StringBuilder stringBuilder = new StringBuilder();
            String line = bufferedReader.readLine();
         //   System.out.println("line==>"+line);
            while (line != null) {
                stringBuilder.append(line);
                line = bufferedReader.readLine();
            }
            responseString = stringBuilder.toString();
        } catch (Exception e) {
            //throw new RuntimeException(e);
            System.out.println("e = " + e);
        } finally {
            if (inputStreamReader != null) {
                try {
                    inputStreamReader.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return responseString;
    }
public String requestPostService(String url, Map<String, Object> parameters, boolean multipart) {
        String responseString = "";
        MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        List<BasicNameValuePair> formparams = new ArrayList<BasicNameValuePair>();
        if (parameters == null) {
            parameters = new HashMap<String, Object>();
        }
        Set<String> keys = parameters.keySet();
        for (Iterator<String> keysIterator = keys.iterator(); keysIterator.hasNext();) {
            String keyString = keysIterator.next();
            String value = parameters.get(keyString).toString();
            formparams.add(new BasicNameValuePair(keyString, value));
            if (multipart) {
                try {
                    StringBody stringBody = new StringBody(value, Charset.forName("UTF-8"));
                    //System.out.println(stringBody.);
                    multiPartEntity.addPart(keyString, (ContentBody) stringBody);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        HttpPost httpPost = new HttpPost(url);
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        try {
            if (multipart) {
                httpPost.setEntity(multiPartEntity);
            } else {
                UrlEncodedFormEntity entity =new UrlEncodedFormEntity(formparams, "UTF-8");// new UrlEncodedFormEntity(formparams, "multipart/form-data");
                ////
                httpPost.setEntity(entity);
            }
            HttpResponse response = httpClient.execute(httpPost);
            InputStream inputStream = response.getEntity().getContent();
            inputStreamReader = new InputStreamReader(inputStream);
            bufferedReader = new BufferedReader(inputStreamReader);
            StringBuilder stringBuilder = new StringBuilder();
            String line = bufferedReader.readLine();
            while (line != null) {
                stringBuilder.append(line);
                line = bufferedReader.readLine();
            }
            responseString = stringBuilder.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (inputStreamReader != null) {
                try {
                    inputStreamReader.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return responseString;
}
public String requestGetService(String url, Map<String, Object> parameters, boolean multipart) {
        String responseString = "";
        HttpGet httpGet = new HttpGet(url);
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;
        try {
            HttpResponse response = httpClient.execute(httpGet);
            InputStream inputStream = response.getEntity().getContent();
            inputStreamReader = new InputStreamReader(inputStream);
            bufferedReader = new BufferedReader(inputStreamReader);
            StringBuilder stringBuilder = new StringBuilder();
            String line = bufferedReader.readLine();
           // System.out.println("line = " + line);
            while (line != null) {
                stringBuilder.append(line);
                line = bufferedReader.readLine();
            }
            responseString = stringBuilder.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (inputStreamReader != null) {
                try {
                    inputStreamReader.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return responseString;
}
public static  void main(String args[])
{
    StartProcessWV startProcessWV=new StartProcessWV();
     Map map=new HashMap();
    map.put("name", "Shahid Iqbal");
  //  map.put("age", "29");
    System.out.println("Login Form==> "+startProcessWV.requestGetService(render_form_url, null, true));
   System.out.println(startProcessWV.authenticate(authentication_url, "admin", "admin")+"\n");
  System.out.println("Render Form==> "+startProcessWV.requestGetService(render_form_url, null, true)+"\n");
   System.out.println("Process start Output==> "+startProcessWV.requestPostService(process_start_url, map, true));
}
}
change the process id in this code and use the following jars
Loading Image... Loading Image...
Your process should have the process form.

I hope so it will helpfull for you.
Sorry for my english
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799008#799008]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
vijay saini
2013-02-22 10:01:35 UTC
Permalink
vijay saini [https://community.jboss.org/people/vijaykr] created the discussion

"Re: How to start new process from workItemHandler in jBpm 5.4"

To view the discussion, visit: https://community.jboss.org/message/799037#799037

--------------------------------------------------------------
Hi snowstorm ,

Thanks for your respose ,I already tried this code as i mentioned I am getting Exception as mention in my post above.this is happning when  both process on same machine.Now i try keeping each processes on seperate machine and It worked fine.But My question is why It is not working if both process on same machine.

And one more query I have .After starting 2nd process I want my customized  respone(i.e 2nd processes data) back in 1st process.By default I am getting json object .How can I get 2nd Process data in response.

Thanks n Regards
Vijay
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799037#799037]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...