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

  1. Using Bonita Studio, create a workflow as following:


  2. 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
  3. 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
  4. 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.


  5. Click on Form. Select UI Designer. In Target form select Create a new form.


  6. 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.


  7. Save and close the form.
  8. 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.


  9. 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.
  10. Select the transition from the gateway to no result found and fill in as following:


  11. 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.


  12. 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:


  13. 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}}
  14. Click on Save, then click on the Result text field. In the right side panel, go to Value and fill it with result.value.


  15. Save and close the form
  16. 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.
  17. 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

  1. 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.
  2. At the Get result activity, select Connectors in. Click on Access the bonita marketplace to install the webservice connector.


  3. Once the installation is complete, click on Add. Select SOAP web services and Webservice SOAP 1.2. click Next


  4. Name the connector StringProcessing_Connector. Click Next.


  5. Enter the WSDL url and click Introspect.


  6. If you are propmted to enter a username and password, enter bonita default ones: username: walter.bates, password: bpm.


  7. 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.


  8. click Next –> Next. In the Response Configuration, Check Returns Body. Then Next.


  9. 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;
  10. Name it result and in Return type, choose java.lang.String and click Ok Then Finish.


  11. Save the process and Run it. Enter the word hello world and token - and click submit.


  12. Refresh the take list, and the activity display result will be available with the result displayed in the result field.


  13. Done.

Exercices

  1. Can you find an operation other than AllUpperCaseWithToken provided by the service TextCasing?
  2. If yes, can you invoke the corresponding operation?
  3. Can you invoke the sayHello operation from WS_HelloWorld service from first web service TP
teaching_assistant/workflow/web_service_invocation_with_bonita_s_workflow_1.txt · Last modified: 2022/01/06 13:54 by Nour
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0