0 Replies Latest reply on Feb 15, 2013 7:37 AM by snowstorm tech

    How to pass process variables to a process using REST API.

    snowstorm tech Newbie

      Hi,

       

      I am using "http://localhost:8080//gwt-console-server/rs/process/definition/defaultPackage.TestProcess/new_instance" this REST API to run the process, I am able to run the process but not able to pass the variables througth this REST API.Following is code which I used to call this REST API.

       

            Java Code:

      import org.apache.commons.httpclient.*;

      import org.apache.commons.httpclient.methods.GetMethod;

      import org.apache.commons.httpclient.methods.PostMethod;

      import org.jboss.bpm.console.client.model.*;

       

       

      import java.io.IOException;

      import java.net.URLDecoder;

      import java.net.URLEncoder;

       

       

      import org.jboss.soa.bpel.console.ModelAdaptor;

       

       

      import com.google.gson.*;

       

       

       

       

       

       

      public class ManagementClient {

       

       

         

          private static final String process_start_url = "http://localhost:8080/gwt-console-server/rs/process/definition/defaultPackage.ProcessWV/new_instance";

       

          private String username;

          private String password;

       

       

          public ManagementClient(String u, String p)

          {

                username = u;

                password = p;

          }

       

        public void startProcess() throws Exception

         {

       

            getDataFromService( process_start_url, "POST");

       

        }

      private String getDataFromService(String urlpath, String method) throws Exception{

             HttpClient httpclient = new HttpClient();

       

       

             HttpMethod theMethod = null;

             StringBuffer sb = new StringBuffer();

       

       

             if ("GET".equalsIgnoreCase(method)) {

                 theMethod = new GetMethod(urlpath);

             } else if ("POST".equalsIgnoreCase(method)) {

                

                 theMethod = new PostMethod(urlpath);

              

             }

       

       

             if (username != null && password != null) {

       

       

                 try {

                     httpclient.executeMethod(theMethod);

                      NameValuePair[] data2 = {new NameValuePair("Name", "shahid"), new NameValuePair("Age", "28")};

                      theMethod.setQueryString(data2);

                 } catch (IOException e) {

                     e.printStackTrace();

                 } finally {

                     theMethod.releaseConnection();

                 }

               PostMethod authMethod = new PostMethod(authentication_url);

               NameValuePair[] data = {new NameValuePair("j_username", username), new NameValuePair("j_password", password)};

               authMethod.setRequestBody(data);

              

                 try {

                     httpclient.executeMethod(authMethod);

                 } catch (IOException e) {

                     e.printStackTrace();

                 } finally {

                     authMethod.releaseConnection();

                 }

             }

       

       

             try {

             

                   NameValuePair[] data2 = {new NameValuePair("Name", "shahid"), new NameValuePair("Age", "28")};

              

                   theMethod.setQueryString(data2);

       

               httpclient.executeMethod(theMethod);

               sb.append(theMethod.getResponseBodyAsString());

               System.out.println("JSon Result: => " + sb.toString());

             return sb.toString();

       

       

             }catch (Exception e) {

                throw e;

             }finally {

               theMethod.releaseConnection();

             }

       

       

          }

      public static void main(String[] args) throws Exception {

       

       

             ManagementClient client = new ManagementClient("admin","admin");

              client.startProcess();

             client.processFormRender();

          }

       

       

       

       

      }

       

      Process BPMN:


      <?xml version="1.0" encoding="UTF-8"?>

      <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/bpmn20" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" id="_6Jb3MHdrEeK6ToI0TrDnHQ" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" targetNamespace="http://www.omg.org/bpmn20">

        <bpmn2:itemDefinition id="_NameItem" structureRef="String"/>

        <bpmn2:itemDefinition id="_AgeItem" structureRef="Integer"/>

        <bpmn2:process id="defaultPackage.ProcessWV" drools:packageName="defaultPackage" name="ProcessWV" isExecutable="true">

          <bpmn2:property id="Name" itemSubjectRef="_NameItem"/>

          <bpmn2:property id="Age" itemSubjectRef="_AgeItem"/>

          <bpmn2:startEvent id="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14" drools:bgcolor="#9acd32" drools:selectable="true" name="">

            <bpmn2:outgoing>_3B1EC4FB-1459-4589-B014-203374D36A64</bpmn2:outgoing>

          </bpmn2:startEvent>

          <bpmn2:scriptTask id="_D306BBB0-A427-4DB6-A524-025AFB76D020" drools:selectable="true" name="Name/Age" scriptFormat="http://www.java.com/java">

            <bpmn2:incoming>_3B1EC4FB-1459-4589-B014-203374D36A64</bpmn2:incoming>

            <bpmn2:outgoing>_6841C8EE-C23C-4116-959B-2AD64BDEE50F</bpmn2:outgoing>

            <bpmn2:script><![CDATA[System.out.println("Name="+Name);]]></bpmn2:script>

          </bpmn2:scriptTask>

          <bpmn2:endEvent id="_8A6FF5AA-01EC-44B3-836B-0723F1372791" drools:bgcolor="#ff6347" drools:selectable="true" name="">

            <bpmn2:incoming>_6841C8EE-C23C-4116-959B-2AD64BDEE50F</bpmn2:incoming>

          </bpmn2:endEvent>

          <bpmn2:sequenceFlow id="_3B1EC4FB-1459-4589-B014-203374D36A64" drools:bgcolor="#000000" drools:selectable="true" sourceRef="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14" targetRef="_D306BBB0-A427-4DB6-A524-025AFB76D020"/>

          <bpmn2:sequenceFlow id="_6841C8EE-C23C-4116-959B-2AD64BDEE50F" drools:bgcolor="#000000" drools:selectable="true" sourceRef="_D306BBB0-A427-4DB6-A524-025AFB76D020" targetRef="_8A6FF5AA-01EC-44B3-836B-0723F1372791"/>

        </bpmn2:process>

        <bpmndi:BPMNDiagram id="_6Jb3MXdrEeK6ToI0TrDnHQ">

          <bpmndi:BPMNPlane id="_6Jb3MndrEeK6ToI0TrDnHQ" bpmnElement="defaultPackage.ProcessWV">

            <bpmndi:BPMNShape id="_6Jb3M3drEeK6ToI0TrDnHQ" bpmnElement="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14">

              <dc:Bounds height="30.0" width="30.0" x="165.0" y="135.0"/>

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape id="_6Jb3NHdrEeK6ToI0TrDnHQ" bpmnElement="_D306BBB0-A427-4DB6-A524-025AFB76D020">

              <dc:Bounds height="80.0" width="100.0" x="285.0" y="90.0"/>

            </bpmndi:BPMNShape>

            <bpmndi:BPMNShape id="_6JceQHdrEeK6ToI0TrDnHQ" bpmnElement="_8A6FF5AA-01EC-44B3-836B-0723F1372791">

              <dc:Bounds height="28.0" width="28.0" x="384.0" y="205.0"/>

            </bpmndi:BPMNShape>

            <bpmndi:BPMNEdge id="_6JceQXdrEeK6ToI0TrDnHQ" bpmnElement="_3B1EC4FB-1459-4589-B014-203374D36A64">

              <di:waypoint xsi:type="dc:Point" x="180.0" y="150.0"/>

              <di:waypoint xsi:type="dc:Point" x="244.0" y="150.0"/>

              <di:waypoint xsi:type="dc:Point" x="244.0" y="130.0"/>

              <di:waypoint xsi:type="dc:Point" x="335.0" y="130.0"/>

            </bpmndi:BPMNEdge>

            <bpmndi:BPMNEdge id="_6JceQndrEeK6ToI0TrDnHQ" bpmnElement="_6841C8EE-C23C-4116-959B-2AD64BDEE50F">

              <di:waypoint xsi:type="dc:Point" x="335.0" y="130.0"/>

              <di:waypoint xsi:type="dc:Point" x="400.0" y="130.0"/>

              <di:waypoint xsi:type="dc:Point" x="398.0" y="219.0"/>

            </bpmndi:BPMNEdge>

          </bpmndi:BPMNPlane>

        </bpmndi:BPMNDiagram>

        <bpmn2:relationship id="_6JceQ3drEeK6ToI0TrDnHQ">

          <bpmn2:extensionElements>

            <drools:ProcessAnalysisData>

              <drools:Scenario xsi:type="drools:Scenario" id="default" name="Simulationscenario">

                <drools:ScenarioParameters xsi:type="drools:ScenarioParameters_._type" baseTimeUnit="s"/>

                <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14" id="_6JceRHdrEeK6ToI0TrDnHQ">

                  <drools:TimeParameters xsi:type="drools:TimeParameters">

                    <drools:WaitTime xsi:type="drools:Parameter">

                      <drools:FloatingParameter value="0.0"/>

                    </drools:WaitTime>

                    <drools:TimeUnit>ms</drools:TimeUnit>

                  </drools:TimeParameters>

                </drools:ElementParameters>

                <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_D306BBB0-A427-4DB6-A524-025AFB76D020" id="_6JceRXdrEeK6ToI0TrDnHQ">

                  <drools:TimeParameters xsi:type="drools:TimeParameters">

                    <drools:ProcessingTime xsi:type="drools:Parameter">

                      <drools:RandomDistribution max="0.0" min="0.0"/>

                    </drools:ProcessingTime>

                    <drools:TimeUnit>ms</drools:TimeUnit>

                  </drools:TimeParameters>

                  <drools:CostParameters xsi:type="drools:CostParameters">

                    <drools:UnitCost xsi:type="drools:Parameter">

                      <drools:DecimalParameter value="0"/>

                    </drools:UnitCost>

                  </drools:CostParameters>

                </drools:ElementParameters>

                <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_8A6FF5AA-01EC-44B3-836B-0723F1372791" id="_6JceRndrEeK6ToI0TrDnHQ">

                  <drools:TimeParameters xsi:type="drools:TimeParameters">

                    <drools:ProcessingTime xsi:type="drools:Parameter">

                      <drools:RandomDistribution max="0.0" min="0.0"/>

                    </drools:ProcessingTime>

                    <drools:TimeUnit>ms</drools:TimeUnit>

                  </drools:TimeParameters>

                </drools:ElementParameters>

                <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_6841C8EE-C23C-4116-959B-2AD64BDEE50F" id="_6JceR3drEeK6ToI0TrDnHQ">

                  <drools:ControlParameters xsi:type="drools:ControlParameters">

                    <drools:Probability xsi:type="drools:Parameter">

                      <drools:FloatingParameter value="100.0"/>

                    </drools:Probability>

                  </drools:ControlParameters>

                </drools:ElementParameters>

                <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_3B1EC4FB-1459-4589-B014-203374D36A64" id="_6JceSHdrEeK6ToI0TrDnHQ">

                  <drools:ControlParameters xsi:type="drools:ControlParameters">

                    <drools:Probability xsi:type="drools:Parameter">

                      <drools:FloatingParameter value="100.0"/>

                    </drools:Probability>

                  </drools:ControlParameters>

                </drools:ElementParameters>

              </drools:Scenario>

            </drools:ProcessAnalysisData>

          </bpmn2:extensionElements>

          <bpmn2:source>_6Jb3MHdrEeK6ToI0TrDnHQ</bpmn2:source>

          <bpmn2:target>_6Jb3MHdrEeK6ToI0TrDnHQ</bpmn2:target>

        </bpmn2:relationship>

      </bpmn2:definitions>

       

      Process Image:

       

      defaultPackage.ProcessWV.png