12 Replies Latest reply on Apr 1, 2014 7:25 AM by swiderski.maciej

    Service Task - REST example

    oiler

      I need to call a REST service in a process I'm designing in the jBPM workbench.  I noticed there is a Service Task->REST node but I can't seem to find any documentation on how to use it.  Can anyone point me in the right direction or have a working example?

       

      Thanks in advance

        • 1. Re: Service Task - REST example
          marcj

          Hi Kalleen,

          I´m currently working on the same issue. A simple test case would be a call to this REST service:

           

          http://www.webservicex.net/currencyconvertor.asmx/ConversionRate?FromCurrency=EUR&ToCurrency=USD

           

          I´d like to set the two currency parameters provided in the URL in the jBPM process. I also didn´t succeed with the REST Service Task yet.


          Did anyone ever implement a REST service call and could provide some support?

          • 2. Re: Service Task - REST example
            oiler

            Yeah there needs to be some way to put variables in the URL.  I know you can set process variables is there any way those can be inserted into variables in the URL for the task?  For example

             

            http://www.webservicex.net/currencyconvertor.asmx/ConversionRate?FromCurrency={From}&ToCurrency={To}

            • 3. Re: Service Task - REST example
              oiler

              From what I can gather the provided REST Task is fairly simple and to build something more sophisticated requires building a custom work item handler which is described here.

               

              jBPM6 - Custom Work Item: Hello Process Example

              • 4. Re: Service Task - REST example
                marcj

                Still, calling a REST service with a URL containing variables set in the business process should be a fairly simple task and therefore sould be possible without extensive coding, right? I wonder if someone can provide some more information regarding both WS and REST service tasks.

                • 5. Re: Service Task - REST example
                  oiler

                  I hear you just not sure that's supported presently.  I'm working on getting a simple REST call going with the provided REST service task then will try code up a more flexible one and report back.

                  • 6. Re: Service Task - REST example
                    oiler

                    I found this below in the jBPM 6 user guide section 6.6.1. Variables.  Not sure if it applies in our use case where we want to modify a URL.  I will try it out.

                     

                    Service tasks (and reusable sub-processes) can pass the value of process variables to the outside world (or another process instance) by mapping the variable to an outgoing parameter. For example, the parameter mapping of a service task could define that the value of the process variable x should be mapped to a task parameter y right before the service is being invoked. You can also inject the value of process variable into a hard-coded parameter String using #{expression}. For example, the description of a human task could be defined as You need to contact person #{person.getName()} (where person is a process variable), which will replace this expression by the actual name of the person when the service needs to be invoked. Similarly results of a service (or reusable sub-process) can also be copied back to a variable using a result mapping.

                    • 7. Re: Service Task - REST example
                      marcj

                      Hi Kallen,

                      would be very interested if you did succeed.

                      I implemented the aforementioned ConversionRate web service with a custom event handler, so if you'd be interested I can outline my solution. WIth a WSDL though, not with REST. I still try to figure out how a custom REST work item handler has to be implemented.

                      • 8. Re: Service Task - REST example
                        oiler

                        Just getting back to this.  So when I create a simple one task process that makes a simple REST call I get the following error message.

                         

                        Process Instances failed to start: [examples.restexample:42 - REST:3] -- java.lang.String cannot be cast to java.lang.Integer

                         

                        How do I go about debugging this?  According to org.jbpm.process.workitem.rest.RESTWorkItemHandler (http://docs.jboss.org/jbpm/v6.0/repository/Rest/) it doesnt take integers as parameters and only the URL must be specified.

                         

                        Under "Assignments" for the REST task I set the "To Value" or the Url parameter to the endpoint I'm trying to reach, am I missing something?

                        • 9. Re: Service Task - REST example
                          swiderski.maciej

                          here you can find test cases for REST work item handler that should give you all the details needed to operate on it.

                           

                          HTH

                          • 10. Re: Service Task - REST example
                            oiler

                            Maciej thanks for your help.  Sorry I wasn't clear up above but I'm trying to build and run my use case within the KIE Workbench.  It should be just a matter of going to the task properties then under "assignment" setting the URL under the "To Value" correct?  Any idea why the task, according to the error message, is expecting an Integer?

                             

                            Thanks

                            • 11. Re: Service Task - REST example
                              oiler

                              I managed to get this working in the KIE workbench along with the variable injection.  I ended up removing the optional DataInputs and assignments so all I was left with was the Url and method.  Must be a mapping problem there with the default optional parameters.  For the Url assignment I was able to inject a process variable into the Url at runtime.

                               

                              i.e.

                               

                              http://MyHost:8085/MyResource/#{ProcessVariable}

                              • 12. Re: Service Task - REST example
                                swiderski.maciej

                                I believe you ran into this issue. Will be fixed soon but as workaround removing the optional parameters would do the trick (as you have already confirmed).

                                 

                                HTH