6 Replies Latest reply on Feb 8, 2013 12:39 PM by swiderski.maciej

    How to call external web service in jbpm process.

    snowstormuser

      Hi,

      I have a scenario where I want to call the external web service.

      Please hlep me.

      Thanks.

        • 1. Re: How to call external web service in jbpm process.
          kornilovs
          • 2. Re: How to call external web service in jbpm process.
            snowstormuser

            Thanks for relpy,

             

            I have already used the above link example that you have provided.But i am facing an error while execuation of the code.

            here i'm provding the bpmn file, java code and error

             

            The web service that i used is:-

            http://schemas.xmlsoap.org/wsdl/" location="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL" namespace="http://ws.cdyne.com/WeatherWS/

             

            And i also used the class which are genrated for the webservice above specified in my project class path.

             

            bpmn file:-


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

            <definitions id="Definition"

                         targetNamespace="http://www.example.org/MinimalExample"

                         typeLanguage="http://www.java.com/javaTypes"

                         expressionLanguage="http://www.mvel.org/2.0"

                         xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"

                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                         xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"

                         xmlns:g="http://www.jboss.org/drools/flow/gpd"

                         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:tns="http://www.jboss.org/drools">

             

              <import importType="http://schemas.xmlsoap.org/wsdl/" location="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL" namespace="http://ws.cdyne.com/WeatherWS/"/>

             

             

              <itemDefinition id="_sItem"/>

             

             

              <itemDefinition id="_listItem" structureRef="java.util.Collection"/>

             

              <itemDefinition id="_listItemOut" structureRef="java.util.Collection"/>

              <itemDefinition id="_map" structureRef="java.util.Map"/>

             

             

              <itemDefinition id="_2-2-4-itemItem" />

             

             

              <itemDefinition id="_5-listItem" />

             

             

              <itemDefinition id="_2_multiInstanceItemType" />

             

              <itemDefinition id="_2_multiInstanceItemOutType"/>

             

             

              <itemDefinition id="_2-2-4_InMessageType" />

              <message id="_2-2-4_InMessage" itemRef="_2-2-4_InMessageType" />

              <interface id="_2-2-4_ServiceInterface" name="" implementationRef="WeatherSoap">

                <operation id="_2-2-4_ServiceOperation" implementationRef="GetCityWeatherByZIP" name="">

                  <inMessageRef>_2-2-4_InMessage</inMessageRef>

                </operation>

              </interface>

             

             

              <process processType="Private" isExecutable="true" id="WeatherWSServiceProcess" name="WeatherWSServiceProcess" tns:packageName="defaultPackage">

             

             

                <!-- process variables -->

                <property id="list" itemSubjectRef="_listItem"/>

                <property id="listOut" itemSubjectRef="_listItemOut"/>

                <property id="mode" itemSubjectRef="_sItem"/>

                <property id="map" itemSubjectRef="_map"/>

             

             

                <!-- nodes -->

                <startEvent id="_1" name="StartProcess" >

                </startEvent>

                 <scriptTask id="_21" name="Prepare input" scriptFormat="http://www.java.com/java" >

                  <script>

                  System.out.println("Get zip code result is " + map);

                  list =  new java.util.ArrayList(map.values());

                  list.remove("Complete");

                  listOut =  new java.util.ArrayList();

                  kcontext.setVariable("list", list);

                  kcontext.setVariable("listOut", listOut);

                 </script>

                </scriptTask>

                <serviceTask id="_2" name="Get weather forecast" operationRef="_2-2-4_ServiceOperation" implementation="##WebService" >

                <extensionElements>

                    <tns:onEntry-script scriptFormat="http://www.java.com/java">

                      <script>System.out.println("WS1");</script>

                    </tns:onEntry-script>

                    <tns:onExit-script>

                      <script>System.out.println("WS2");</script>

                    </tns:onExit-script>

                  </extensionElements>

                  <ioSpecification>

                    <dataInput id="_2-2-4_param" name="Parameter" />

                    <dataInput id="DataInput_1" name="mode"/>

             

                    <dataInput id="_2_listInput" name="list"/>

                    <dataOutput id="_2_listOutOutput" name="listOut"/>

                    <dataOutput id="_2-2-4_result" name="Result" />

                    <inputSet>

                      <dataInputRefs>_2-2-4_param</dataInputRefs>

                      <dataInputRefs>DataInput_1</dataInputRefs>

                    </inputSet>

                    <outputSet>

                      <dataOutputRefs>_2_listOutOutput</dataOutputRefs>

                    </outputSet>

                  </ioSpecification>

                   <dataInputAssociation>

                    <targetRef>_2-2-4_param</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression">#{item}</from>

                      <to xsi:type="tFormalExpression">_2-2-4_param</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <sourceRef>mode</sourceRef>

                    <targetRef>DataInput_1</targetRef>

                  </dataInputAssociation>

                  <dataInputAssociation id="DataInputAssociation_1">

                    <sourceRef>list</sourceRef>

                    <targetRef>_2_listInput</targetRef>

                  </dataInputAssociation>

                  <dataOutputAssociation>

                    <sourceRef>_2-2-4_result</sourceRef>

                    <targetRef>itemOut</targetRef>

                  </dataOutputAssociation>

                  <multiInstanceLoopCharacteristics>

                    <loopDataInputRef>_2_input</loopDataInputRef>

                    <loopDataOutputRef>_2_listOutOutput</loopDataOutputRef>

                    <inputDataItem id="item" itemSubjectRef="_2_multiInstanceItemType"/>

                    <outputDataItem id="itemOut" itemSubjectRef="_2_multiInstanceItemOutType"/>

                  </multiInstanceLoopCharacteristics>

                </serviceTask>

             

                <scriptTask id="_3" name="Log result" >

                  <script>System.out.println("Service result " + listOut);</script>

                </scriptTask>

                <endEvent id="_4" name="EndProcess" >

                    <terminateEventDefinition/>

                </endEvent>

                <userTask id="_5" name="Get zip codes" >

                                <ioSpecification>

                    <dataInput id="_2_CommentInput" name="Comment" />

                    <dataInput id="_2_SkippableInput" name="Skippable" />

                    <dataInput id="_2_TaskNameInput" name="TaskName" />

                    <dataInput id="_2_GroupIdInput" name="GroupId" />

                    <dataInput id="_2_PriorityInput" name="Priority" />

                    <dataOutput id="_2_ResultOutput" name="Result" />

                    <inputSet>

                      <dataInputRefs>_2_CommentInput</dataInputRefs>

                      <dataInputRefs>_2_SkippableInput</dataInputRefs>

                      <dataInputRefs>_2_TaskNameInput</dataInputRefs>

                      <dataInputRefs>_2_GroupIdInput</dataInputRefs>

                      <dataInputRefs>_2_PriorityInput</dataInputRefs>

                    </inputSet>

                    <outputSet>

                      <dataOutputRefs>_2_ResultOutput</dataOutputRefs>

                    </outputSet>

                  </ioSpecification>

                  <dataInputAssociation>

                    <targetRef>_2_CommentInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression"></from>

                      <to xsi:type="tFormalExpression">_2_CommentInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_2_SkippableInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression">false</from>

                      <to xsi:type="tFormalExpression">_2_SkippableInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_2_TaskNameInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression">firstTask</from>

                      <to xsi:type="tFormalExpression">_2_TaskNameInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_2_GroupIdInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression"></from>

                      <to xsi:type="tFormalExpression">_2_GroupIdInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_2_PriorityInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression"></from>

                      <to xsi:type="tFormalExpression">_2_PriorityInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataOutputAssociation>

                    <sourceRef>_2_ResultOutput</sourceRef>

                    <targetRef>map</targetRef>

                  </dataOutputAssociation>

                  <potentialOwner>

                    <resourceAssignmentExpression>

                      <formalExpression>john</formalExpression>

                    </resourceAssignmentExpression>

                  </potentialOwner>

                </userTask>

             

                <userTask id="_6" name="Show forecast" >

                  <ioSpecification>

                    <dataInput id="_4_outputInput" name="output" />

                    <dataInput id="_4_CommentInput" name="Comment" />

                    <dataInput id="_4_SkippableInput" name="Skippable" />

                    <dataInput id="_4_TaskNameInput" name="TaskName" />

                    <dataInput id="_4_GroupIdInput" name="GroupId" />

                    <dataInput id="_4_PriorityInput" name="Priority" />

                    <inputSet>

                      <dataInputRefs>_4_outputInput</dataInputRefs>

                      <dataInputRefs>_4_CommentInput</dataInputRefs>

                      <dataInputRefs>_4_SkippableInput</dataInputRefs>

                      <dataInputRefs>_4_TaskNameInput</dataInputRefs>

                      <dataInputRefs>_4_GroupIdInput</dataInputRefs>

                      <dataInputRefs>_4_PriorityInput</dataInputRefs>

                    </inputSet>

                    <outputSet>

                    </outputSet>

                  </ioSpecification>

                  <dataInputAssociation>

                    <sourceRef>listOut</sourceRef>

                    <targetRef>_4_outputInput</targetRef>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_4_CommentInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression"></from>

                      <to xsi:type="tFormalExpression">_4_CommentInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_4_SkippableInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression">false</from>

                      <to xsi:type="tFormalExpression">_4_SkippableInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_4_TaskNameInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression">secondTask</from>

                      <to xsi:type="tFormalExpression">_4_TaskNameInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_4_GroupIdInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression"></from>

                      <to xsi:type="tFormalExpression">_4_GroupIdInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <dataInputAssociation>

                    <targetRef>_4_PriorityInput</targetRef>

                    <assignment>

                      <from xsi:type="tFormalExpression"></from>

                      <to xsi:type="tFormalExpression">_4_PriorityInput</to>

                    </assignment>

                  </dataInputAssociation>

                  <potentialOwner>

                    <resourceAssignmentExpression>

                      <formalExpression>john</formalExpression>

                    </resourceAssignmentExpression>

                  </potentialOwner>

                </userTask>

             

             

                <!-- connections -->

                <sequenceFlow id="_21-_2" sourceRef="_21" targetRef="_2" />

                <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

                <sequenceFlow id="_3-_6" sourceRef="_3" targetRef="_6" />

                <sequenceFlow id="_1-_5" sourceRef="_1" targetRef="_5" />

                <sequenceFlow id="_5-_21" sourceRef="_5" targetRef="_21" />

                <sequenceFlow id="_6-_4" sourceRef="_6" targetRef="_4" />

             

             

              </process>

             

             

              <bpmndi:BPMNDiagram>

                <bpmndi:BPMNPlane bpmnElement="WeatherWSServiceProcess" >

                  <bpmndi:BPMNShape bpmnElement="_1" >

                    <dc:Bounds x="16" y="67" width="48" height="48" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNShape bpmnElement="_2" >

                    <dc:Bounds x="228" y="16" width="200" height="150" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNShape bpmnElement="_21" >

                    <dc:Bounds x="128" y="26" width="200" height="150" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNShape bpmnElement="_3" >

                    <dc:Bounds x="460" y="67" width="92" height="48" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNShape bpmnElement="_4" >

                    <dc:Bounds x="584" y="67" width="48" height="48" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNShape bpmnElement="_5" >

                    <dc:Bounds x="96" y="67" width="100" height="48" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNShape bpmnElement="_6" >

                    <dc:Bounds x="96" y="67" width="140" height="148" />

                  </bpmndi:BPMNShape>

                  <bpmndi:BPMNEdge bpmnElement="_21-_2" >

                    <di:waypoint x="140" y="50" />

                    <di:waypoint x="144" y="117" />

                  </bpmndi:BPMNEdge>

                  <bpmndi:BPMNEdge bpmnElement="_2-_3" >

                    <di:waypoint x="42" y="49" />

                    <di:waypoint x="140" y="50" />

                  </bpmndi:BPMNEdge>

                  <bpmndi:BPMNEdge bpmnElement="_3-_6" >

                    <di:waypoint x="146" y="91" />

                    <di:waypoint x="328" y="91" />

                  </bpmndi:BPMNEdge>

                  <bpmndi:BPMNEdge bpmnElement="_1-_5" >

                    <di:waypoint x="328" y="91" />

                    <di:waypoint x="506" y="91" />

                  </bpmndi:BPMNEdge>

                  <bpmndi:BPMNEdge bpmnElement="_5-_21" >

                    <di:waypoint x="506" y="91" />

                    <di:waypoint x="608" y="91" />

                  </bpmndi:BPMNEdge>

                  <bpmndi:BPMNEdge bpmnElement="_6-_4" >

                    <di:waypoint x="40" y="91" />

                    <di:waypoint x="146" y="91" />

                  </bpmndi:BPMNEdge>

                </bpmndi:BPMNPlane>

              </bpmndi:BPMNDiagram>

             

             

            </definitions>

             

            Java code:-


            import java.util.*;

             

             

            import javax.xml.ws.Endpoint;

             

             

            import org.drools.KnowledgeBase;

            import org.drools.builder.KnowledgeBuilder;

            import org.drools.builder.KnowledgeBuilderFactory;

            import org.drools.builder.ResourceType;

            import org.drools.definition.process.Connection;

            import org.drools.definition.process.Node;

            import org.drools.io.ResourceFactory;

            import org.drools.runtime.StatefulKnowledgeSession;

            import org.drools.runtime.process.NodeInstance;

            import org.drools.runtime.process.WorkItem;

            import org.drools.runtime.process.WorkItemHandler;

            import org.drools.runtime.process.WorkItemManager;

            import org.jbpm.bpmn2.handler.ServiceTaskHandler;

            import org.jbpm.process.instance.ProcessInstance;

            import org.jbpm.process.workitem.wsht.CommandBasedWSHumanTaskHandler;

            import org.jbpm.task.service.TaskClientHandler;

            import org.jbpm.workflow.core.node.HumanTaskNode;

            import org.jbpm.workflow.instance.WorkflowProcessInstance;

            import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;

             

             

            public class ProcessMain {

             

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

             

             

             

             

                                    KnowledgeBase kbase = readKnowledgeBase();

                                    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                        TestWorkItemHandler htHandler = new TestWorkItemHandler();

                              ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());

                              ksession.getWorkItemManager().registerWorkItemHandler("Human Task", htHandler);

                              Map<String, Object> params = new HashMap<String, Object>();

                              params.put("mode", "async");

                              WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("WeatherWSServiceProcess", params);

                              params = new HashMap<String, Object>();

                              params.put("r1", "14025");

                              HashMap<String, Object> results = new HashMap<String, Object>();

                              results.put("Result", params);

                              ksession.getWorkItemManager().completeWorkItem(htHandler.getWorkItem().getId(), results);

                              Thread.sleep(5000);

                                          ksession.getWorkItemManager().completeWorkItem(htHandler.getWorkItem().getId(), null);

             

                      }

                       static class TestWorkItemHandler implements WorkItemHandler {

             

             

                                          private static TestWorkItemHandler INSTANCE = new TestWorkItemHandler();

             

             

                                          private WorkItem workItem;

                                          private WorkItem aborted;

             

             

                                          public static TestWorkItemHandler getInstance() {

                                                    return INSTANCE;

                                          }

             

             

                                          public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

                                                    this.workItem = workItem;

                                          }

             

             

                                          public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {

                                                    this.aborted = workItem;

                                          }

             

             

                                          public WorkItem getWorkItem() {

                                                    WorkItem result = workItem;

                                                    workItem = null;

                                                    return result;

                                          }

             

             

                                          public WorkItem getAbortedWorkItem() {

                                                    WorkItem result = aborted;

                                                    aborted = null;

                                                    return result;

                                          }

             

             

                                }

            }

             

             

            Error:-


            Get zip code result is {r1=14025}

             

            java.lang.ClassNotFoundException:

             

            • 3. Re: How to call external web service in jbpm process.
              kornilovs

              maybe not valid java code in script?

              local variables list, listOut  without a type

              • 4. Re: How to call external web service in jbpm process.
                snowstormuser

                Thanks Sergey Kornilov for your reply,

                 

                I have define the local variables list, listOut  with a type, but I am still getting  same error.

                 

                Thanks.

                • 5. Re: How to call external web service in jbpm process.
                  roxy1987

                  Just create a client class and call client method from your script task. You will need to create a process variable of the client class in your process and then in script node you can just call the method using the variable.

                  • 6. Re: How to call external web service in jbpm process.
                    swiderski.maciej

                    in the blog post there is a link to a complete maven project that has test cases for it, can you try running it from there and then follow the same approach to run the example?

                     

                    HTH