In any real time project there would be a basic need to do some rest calls to external system apis , let it is be GET,POST,PUT etc. So it is important for Bpm developers to know how we can implement this.
To achieve this we can use available toolkit like Rest-Utilities , Kolban toolkit etc.
In this blog I will show you how we can achieve this using Kolban one. I won’t be importing the whole toolkit but I will just add the JAR file to server which is used for doing rest calls so that I reduce the size of my process application.
You can get the Jar file from my git project here
Once you download this Jar file to local, you need to upload this to bpm server
The idea here is to create a service using this JAR file , so that when ever there is a need to implement rest call, we can just use that service.
I have created a Integration service. Then since we need to call a Jar I have taken Java Integration from the palette to my diagram. Then in the definition section where we have Java class we need to select this JAR file and then we need to select the Method which we need to call from this JAR .In this Jar we have only doRest method so I have selected.
In the image we can see that the method is expecting 6 parameters which we can see in the Data Mapping. Since these method is expecting these values I have created 6 input variables and then did the bindings and then as output I have created one variable as responseText
Now the service is ready and when ever there is a need to do rest call you can use this Execute Rest call service
I will show an example how we can do a POST call using the service which we created.First I need to create the variables which are necessary to be passed to the service.Here command is nothing but type of call .So it is “POST”. Next URL variable is created. Content variable is created to pass the data to that call in body and Header Map is the variable to pass headers.
Then we need to take a nested service and bind Execute Rest Call service . I need to pass headers to the service which I will pass in the script
Then bind the input variables to the service. I don’t have userId and password , so I will ignore that. Also bind the output variable.
If you need to parse your response you can do that by adding script after the nested service and pass it as output variables like reponseCode ,responseMessage etc
In this blog I have used bpm 8.5.6 . Even in the higher versions we can implement this similarly with/without minor modifications.
This way we can easily implement rest calls from bpm
Please do comment if you have any questions . Hope this helps someone and have a good day!