Web service invocation with Bonita's workflow

Bonita Studio provides connectors which are a specific function 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 “Displaying a weather report” workflow. At the Get Weather step, we will call a web service to display the weather in your city.

Design the "Displaying your city weather" 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 city User enter the country and city Human Normal
    Get weather Get the weather report using a web service Service
    Gate XOR
    Display weather report The weather report 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
    city The user's city Text
    country The user's country Text
    weather The weather report Text
  4. At the enter you city activity, we will design a simple form for submitting the city and country names. To do this, click on Application → Pageflow, then Add. Name the form as get_city_form and the Description as The form used for getting the city and country. Uncheck the global variable weather and click Finish.


  5. Click on the submit button in get_city_form and fill in the General description as following


  6. Save and close the get_city_form Form.
  7. Now, we set the transition conditions on the gateway. Select the transition from the gateway to display weather report and check default flow in General tab.
  8. Select the transition from the gateway to no result found and fill in as following:


  9. Now, we add the forms for the activities Display weather report and no result found. Select Display weather report, then Application–>Pageflow–>Add. Name the form as display_form and leave the global variables checked. click Finish. Remove the Weather variable from the form and drag a Text Area from the palette.
  10. Select on the text area, then rename its label as weather data in General tab.


  11. In General–>data, set the Initial value as weather. Save the display_form.
  12. 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.
  13. 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 weather has not been done yet. Now, it's time do it.

Invoking the Web service

  1. Get the WSDL file of the weather service. Open it and have a look on its content to get the data for the web service connector configuration.
  2. At the Get weather activity, select General –> Connectors –> add. Choose SOAP web services –> Web services SOAP 1.2 from the list and click Next.
  3. Name it as WeatherReport_Connector. Set Select event as enter. Click Next.


  4. Fill in the Connection parameters from the wsdl file as following and click Next:


  5. By the same way, fill in the Request parameters from the wsdl file as following:


    for your project, we may need to use SOAPUI to have the correct message structure
  6. The code for the Envelope request is as following:
    <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
      <env:Body>
        <tns:GetWeather xmlns:tns="http://www.webserviceX.NET">
          <tns:CityName>${city}</tns:CityName>
          <tns:CountryName>${country}</tns:CountryName>
        </tns:GetWeather>
      </env:Body>
    </env:Envelope>
  7. Click Next –> Next. In Response Configuration, check the Returns body box. click Next.
  8. In Output operations, choose weather variable from the first list. Click on the Pencil icon in the second list to assign a value for the weather variable. Choose script in the Edit operation form and 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.getElementsByTagName("GetWeatherResult");
    Element resultElement = (Element) resultList.item(0);
    String weatherData = resultElement.getTextContent();
    return  weatherData;

we may need to use for your project the function getElementsByTagNameNS instead of getElementsByTagName

  1. Name it result and in Return type, choose java.lang.String and click Ok Then Finish.


  2. Save the process and Run it. Enter the city Melun and country France and click get weather report. Wait a few seconds, and the activity Get weather will be available. Click on it to get the response from the WS server. You can see now the weather report displayed in Weather data text area


  3. Done.

Exercices

  1. Can we assign directly the result variable to the weather (steps 8,9)?
  2. Can you find an operation other than GetWeather provided by the service GlobalWeather in the WSDL file?
  3. If yes, can you invoke the corresponding operation?
  4. The response of the GetWeather operation is in the form of an XML file (step 10). Re-configure the connector at Display weather report to get the information from the response.
  5. Can you display the above results in a table?
  6. 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.txt · Last modified: 2021/12/06 10:55 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