11 Replies Latest reply on Sep 24, 2013 5:48 AM by swiderski.maciej

    calling Java method from Service Task with multiple input parameters

    jkouba

      How do you call a Java method from a service task that has more than one input parameters? For instance, two strings?

       

      What would the interface xml look like? For instance, this works when MyMethod just takes one string as an input parameter:

       

      public String MyMethod(String inputString)

       

      <itemDefinition id="_4_InMessageType" structureRef="java.lang.String" />

        <message id="_4_InMessage" itemRef="_4_InMessageType" />

        <interface id="_4_ServiceInterface" name="com.test.MyService">

          <operation id="_4_ServiceOperation" name="MyMethod">

            <inMessageRef>_4_InMessage</inMessageRef>

          </operation>

        </interface>

       

      But how would you define the interface if it takes two strings as input?

       

      public String MyMethod(String inputString1, String inputString2)

       

      I tried something like this without success...

       

      <itemDefinition id="_4_InMessageType" structureRef="java.lang.String" />

        <message id="_4_InMessage" itemRef="_4_InMessageType" />

        <message id="_4_InMessage2" itemRef="_4_InMessageType" />

      <interface id="_4_ServiceInterface" name="com.test.MyService"> 

          <operation id="_4_ServiceOperation" name="MyMethod">

            <inMessageRef>_4_InMessage</inMessageRef>

            <inMessageRef>_4_InMessage2</inMessageRef>

          </operation>

        </interface>

       

      with the service task being

       

      <serviceTask id="_4" name="MyService" operationRef="_4_ServiceOperation" implementation="Other" >

            <ioSpecification>

              <dataInput id="_4_param1Ref" name="Parameter" />

              <dataInput id="_4_param2Ref" name="Parameter" />

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

              <inputSet>

                <dataInputRefs>_4_param1Ref</dataInputRefs>

                <dataInputRefs>_4_param2Ref</dataInputRefs>

              </inputSet>

              <outputSet>

                <dataOutputRefs>_4_result</dataOutputRefs>

              </outputSet>

            </ioSpecification>

            <dataInputAssociation>

              <sourceRef>ipAddress</sourceRef>

              <targetRef>_4_param1Ref</targetRef>

            </dataInputAssociation>

            <dataInputAssociation>

               <sourceRef>serialInterface</sourceRef>

               <targetRef>_4_param2Ref</targetRef>

            </dataInputAssociation>

            <dataOutputAssociation>

              <sourceRef>_4_result</sourceRef>

              <targetRef>thisResult</targetRef>

            </dataOutputAssociation>

          </serviceTask>

       

      thanks...

        • 1. Re: calling Java method from Service Task with multiple input parameters
          swiderski.maciej

          Unfortunately that is the limitation of the ServiceTaskHandler implementation. It supports only one parameter of any type. So one alternatives would be use either some kind of Java bean or Map/List as parameter.

           

          Attached you can find bit enhanced version of the service task handler that allows any number of parameters to be given but of the same type, it has limitation as well ;(

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: calling Java method from Service Task with multiple input parameters
            jkouba

            Thanks for confirming the "limitation." This morning I hit upon the idea of using a bean as the "one parameter" sent to the method, and that is working just fine.

            • 3. Re: calling Java method from Service Task with multiple input parameters
              sridhar532

              Hi jeff,

               

              Can you please share your example. The Handler and BPMN file. Thanks

              • 4. Re: calling Java method from Service Task with multiple input parameters
                chrisgut33

                Hi!

                 

                I have a question, is the problem already solved at the service task handler with the multiple parameters or still have to make it with the help of Java bean or Map/List?

                 

                Can I use the ExtendedServiceTaskHandler example also for Web Services, when I adjust the example?

                 

                Thanks

                • 5. Re: calling Java method from Service Task with multiple input parameters
                  swiderski.maciej

                  ServiceTask by definition (according to BPMN2 spec) accepts single parameter that can be a complex type. The extended service task handler can be used for custom work items that allows multiple parameters to be given.

                   

                  HTH

                  • 6. Re: calling Java method from Service Task with multiple input parameters
                    chrisgut33

                    Hi Maciej!

                     

                    Thank you for your reply!

                     

                    I again read through the standard exactly and you're right. But I do not quite understand why only one parameter is allowed. Do you know why the standard of BPMN 2.0 has introduced this constraint?

                     

                    For me it does not really make sense. At a Service Task you need also the element / attribute "inputSet" at a IOSpecification and for me that means multiple inputs (parameters) are allowed. Or?

                     

                    A web service often has multiple parameters, a service task would not make any sense in this case or should I use a receive and send task for a web service? Here the standard allows multiple inputs.

                     

                    Thanks

                    • 7. Re: calling Java method from Service Task with multiple input parameters
                      swiderski.maciej

                      I believe that this is sort of continuation of the web service world that in general is moving away from RPC style and relying on Document style of web service end point invocation. Where document is single entry/parameter to the service that is sort of wrapping all required data.

                       

                      If you interact with web services that are more in RPC style (multiple parameters) then it probably makes sense to have dedicated work item and work item handler that can fit these requirements. You can use send and receive tasks for that just keep in mind that this choice directly imposes async interaction as you have two steps in the process.

                       

                      Service task and send/receive tasks are work items in jBPM so you can choose whatever work item handler implementation for them. As an example you can see the ExtendedServiceTaskHandler so there are options to choose from.

                       

                      HTH

                      • 8. Re: calling Java method from Service Task with multiple input parameters
                        chrisgut33

                        Hi Maciej!

                         

                        Thank you for your reply!

                         

                        But I have found an example (https://github.com/mswiderski/jbpm-examples/blob/master/jbpm-ws-sample/src/main/resources/WeatherWSServiceProcess.bpmn2) in which are more than one data inputs used at a service task. You can see the service task code below.

                         

                        Now my question: Is it still BPMN standard confirm and if so why? Because on the p. 158 in BPMN standard you can read that only one inputset with only one data input is allowed. The same what you said in a post above.

                         

                        Thanks!!

                         

                         

                        Example Service Task:

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

                              <bpmn2:incoming>_21-_2</bpmn2:incoming>

                              <bpmn2:outgoing>_2-_3</bpmn2:outgoing>

                              <bpmn2:ioSpecification id="InputOutputSpecification_1">

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

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

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

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

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

                                <bpmn2:inputSet id="InputSet_1">

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

                                  <bpmn2:dataInputRefs>DataInput_1</bpmn2:dataInputRefs>

                                </bpmn2:inputSet>

                                <bpmn2:outputSet id="OutputSet_1">

                                  <bpmn2:dataOutputRefs>_2_listOutOutput</bpmn2:dataOutputRefs>

                                </bpmn2:outputSet>

                              </bpmn2:ioSpecification>

                              <bpmn2:dataInputAssociation id="DataInputAssociation_1">

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

                                <bpmn2:assignment id="Assignment_1">

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

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

                                </bpmn2:assignment>

                              </bpmn2:dataInputAssociation>

                              <bpmn2:dataInputAssociation id="DataInputAssociation_2">

                                <bpmn2:sourceRef>mode</bpmn2:sourceRef>

                                <bpmn2:targetRef>DataInput_1</bpmn2:targetRef>

                              </bpmn2:dataInputAssociation>

                              <bpmn2:dataInputAssociation id="DataInputAssociation_10000">

                                <bpmn2:sourceRef>list</bpmn2:sourceRef>

                                <bpmn2:targetRef>_2_listInput</bpmn2:targetRef>

                              </bpmn2:dataInputAssociation>

                              <bpmn2:dataOutputAssociation id="DataOutputAssociation_1">

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

                                <bpmn2:targetRef>itemOut</bpmn2:targetRef>

                              </bpmn2:dataOutputAssociation>

                              <bpmn2:multiInstanceLoopCharacteristics id="MultiInstanceLoopCharacteristics_1">

                                <bpmn2:loopDataInputRef>_2_input</bpmn2:loopDataInputRef>

                                <bpmn2:loopDataOutputRef>_2_listOutOutput</bpmn2:loopDataOutputRef>

                                <bpmn2:inputDataItem xsi:type="bpmn2:tDataInput" id="item" itemSubjectRef="_2_multiInstanceItemType"/>

                                <bpmn2:outputDataItem xsi:type="bpmn2:tDataOutput" id="itemOut" itemSubjectRef="_2_multiInstanceItemOutType"/>

                              </bpmn2:multiInstanceLoopCharacteristics>

                            </bpmn2:serviceTask>

                        • 9. Re: calling Java method from Service Task with multiple input parameters
                          swiderski.maciej

                          it is according to BPMN2. Multiple inputsets are there because this is multi instance activity and thus we need to declare what is the incoming/outgoing collection (list and listOut) for processing it as multi instance. In the end the actual service invocation will be with single parameter takes from incoming collection.

                           

                          HTH

                          • 10. Re: calling Java method from Service Task with multiple input parameters
                            chrisgut33

                            Hi Maciej!

                             

                            Thank you for your reply!

                             

                            I understand that in this example only one parameter is gone through to the webservice, but the service task has three data inputs and that is not allowed according to the BPMN specification (or at least I think so).

                             

                            So I don't unterstand why this is BPMN conform?

                             

                            Thanks

                            • 11. Re: calling Java method from Service Task with multiple input parameters
                              swiderski.maciej

                              Chris, you should not cosider these additional dataInputs (for multi instance) as the actual dataInputs for the service task. When you look in the spec about the mulitinstance characteristic you will notive that they actually refer to dataInputs to be able to operate and thus they must be there. You could see it as two elements:

                              1. sort of container that is in fact coordinating multi instance characteristic - additional dataInputs

                              2. service task that will be executed multiple times because of multi instance and it then has single dataInput.

                               

                              so that is still according to the spec. I hope it does make sense.

                               

                              HTH