Web service invocation with Bonita's workflow
Bonita Studio provides connectors which are a specific functions to interact with other services. And here, we will see how we can invoke a SOAP 1.2 based web service at an activity using the connector. In this tutorial, I focus on the WS connector creation instead of the details about workflow design. Hence, you shoud practice the previous TP to be clear with the workflow design before working on this tutorial.
We will design a simple “text processing” workflow. At the Get result step, we will call a web service to process and display a text you give as input. The web service will convert the text into capital letters and separate all letters by a special character called token that you give as input.
Design the "Text processing" workflow
Using Bonita Studio, create a workflow as following:
Set the Details of the activities as following:
Name |
Description |
Type |
Priority |
Enter your word |
User enter a text and a token |
Human |
Normal |
Get result |
Convert the text into capital letters and separate the letters with the token using a web service |
Service |
|
Gate |
|
XOR |
|
Display result |
The processed text is displayed to the user |
Human |
Normal |
no result found |
A message is displayed to the user if no result is found |
Human |
Normal |
Declare three global variables:
Name |
Description |
Data type |
wordInput |
The user's text |
Text |
tokenInput |
The user's token |
Text |
processedWord |
The result of processing the word input |
Text |
At the
enter you word activity, we will design a simple form for submitting the word and token. To do this, click on the activity, then
Execution → Contract, then
Add. Add two variables called
word and
token. These variables will contain the values entered by the user in the form. They will be later assigned to the global variables
wordInput and
tokenInput.
Click on
Form. Select
UI Designer. In
Target form select
Create a new form.
Name the form as
InputForm. You can see that you have two text fields automatically created with the same labels as the contract variables' names. The values entered by the user will be assigned to the variables
formInput.word and
formInput.token which correspond to the contract variables you created in a previous step.
Save and close the form.
Click on
Operations. Now we will assign the values of
word and
token to the global variables we crearted earlier
wordInput and
tokenInput. Click on
Add and fill the parameters as shown in the figure below.
Now, we set the transition conditions on the gateway. Select the transition from the gateway to display result and check default flow in General tab.
Select the transition from the
gateway to
no result found and fill in as following:
Now, we add the forms for the activities
Display result and
no result found. Select
Display result, then
Execution–>form. Select
create a new form as you did in the previous steps. Name the form
OutputForm. drag and drop the
Input widget. Click on it and in the right hand panel, enter
Result for the label.
the
Result text field will display the result of the web service which will be stored in the variable
processedWord. To do so, click on
create a new variable in the form. Enter the details as shown below:
The variable name is
result, its type is
External API. Its value is retrieved from the
processedWord variable which can be obtained from the activity of the current running process indicated by
{{task.caseID}}
Click on
Save, then click on the
Result text field. In the right side panel, go to
Value and fill it with
result.value.
Save and close the form
By the same way, add a no_result_form form to no result found task that contains a Message element whose Initial value is No result found and a Submit button.
Save the no_result_form form and the process is completely designed now. However, our main task which is invoking a web service at the activity Get result has not been done yet. Now, it's time do it.
Invoking the Web service
Get the
WSDL file of the text processing service. Open it and have a look on its content to get the data for the web service connector configuration.
At the
Get result activity, select
Connectors in. Click on
Access the bonita marketplace to install the
webservice connector.
Once the installation is complete, click on
Add. Select
SOAP web services and
Webservice SOAP 1.2. click
Next
Name the connector
StringProcessing_Connector. Click
Next.
Enter the
WSDL url and click
Introspect.
If you are propmted to enter a username and password, enter bonita default ones:
username: walter.bates, password: bpm.
The parameters will be filled automatically. In the
Operation drop down list you can see all the operations of the web service. Choose
AllUpperCaseWithToken. In the
Parameters, you can see that the operation takes two inputs named
sAString and
Token. Enter the value
wordInput for the first parameter and
tokenInput for the second.
click
Next –> Next. In the
Response Configuration, Check
Returns Body. Then
Next.
In
Output operations, choose
processedWord variable from the first list. Click on the
Pencil icon in the second list to assign a value for the
processedWord variable. Add the following code:
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
// Clean response xml document
responseDocumentBody.normalizeDocument();
// Get result node
NodeList resultList = responseDocumentBody.getElementsByTagNameNS("*", "AllUppercaseWithTokenResult")
Element resultElement = (Element) resultList.item(0);
String resultData = resultElement.getTextContent();
return resultData;
Name it
result and in
Return type, choose
java.lang.String and click
Ok Then
Finish.
Save the process and
Run it. Enter the word
hello world and token
- and click
submit.
Refresh the take list, and the activity
display result will be available with the result displayed in the result field.
Done.
Exercices
Can you find an operation other than AllUpperCaseWithToken provided by the service TextCasing?
If yes, can you invoke the corresponding operation?
-
Back to top