Design the Interaction Between Your Business Process and a Web Service

This section describes how to create the activities that are performed when the condition defined in your Decision node evaluates to true. The condition evaluates to true if the value of shipAddress/state in the XML document received from a client, equals any one of the following: CA, California, NJ, or New Jersey.

In this section, you learn how to invoke a Web service from your business process, and create a callback handler to receive the data returned by the Web service. It includes the following tasks:

To Create an Instance of the Web Service Control in Your Project

  1. If Design View is not visible, click the Design View tab.
  2. If the Controls tab is not visible in WebLogic Workshop, choose View —> Windows —> Data Palette from the menu bar.
  3. Click Add on the Data Palette Controls tab. A drop-down list of controls that represent the resources with which your business process can interact is displayed.
  4. Choose Web Service. The Insert Control dialog box is displayed.
  5. image

  6. In the Insert Control dialog box:
    1. In Step 1, enter taxCalculation as the variable name for this control.
    2. In Step 2, ensure that the following option is selected: Use a Web Service control already defined by a JCX file.
    3. Click Browse beside the JCX file field, choose TaxCalcControl.jcx from the \requestquote\services folder in your application, then click Select. The file browser closes and requestquote\services\taxCalcControl.jcx is entered in the field.
  7. Click Create. The Insert Control dialog box closes.
  8. An instance of a Web Service control, named taxCalculation, is created in your project and displayed on the Data Palette Controls tab.

    image

  9. From the Workshop menu, select File —> Save All.

To Call the Tax Calculation Web Service From Your Business Process

In this step, you create the logic to call the tax calculation control from your business process.

  1. In the Data Palette, click the + beside the taxCalculation control. The list of methods available on the taxCalculation control is displayed.
  2. From the list of taxCalculation control methods, click the following method:
  3. void requestTaxRate(java.lang.String stateID) 
    
  4. Drag and drop the method onto the business process, placing it on the Sales Tax Calculation Needed? node immediately below the condition (Yes) node
  5. image

    A Control Send node is created representing the asynchronous call to your taxCalculation Web Service control. The node is named according to the name of the method you dragged onto the business process—in this case: requestTaxRate.

    Note: This interaction is designed to be asynchronous, meaning that the business process can send a request to the taxCalculation control from this node, and does not block waiting for a response from the control. In other words, the business process can continue processing and receive a response from the taxCalculation service when that service completes the request.

  6. Double-click the requestTaxRate node. The node builder opens on the General Settings tab. The Control instance and target methods are already selected: taxCalculation and void request TaxRate(String stateID), respectively.
  7. Click the Send Data tab.
  8. By default, the Send Data tab opens on the Variable Assignment pane. The Control Expects field is populated with the data type expected by the requestTaxRate() method exposed by the taxCalculation Web services: String stateID.

    Note: As you learned in a previous step, Send Data tabs have two modes:

    In this case, you must switch to the Transformation mode because the data type required as input to the taxCalculation control is a Java String type, and the variable in which the Request for Quote message (which includes the value of shipAddress/state) is stored, is of type XML (that is, QuoteRequestDocument, which is valid against an XML Schema).

    WebLogic Integration provides a data mapping tool to map between heterogeneous data types. The data transformations you create using the tool are stored in Data Transformation Format (DTF) files. You can think of DTF files as another resource with which your business process interacts via controls. That is, when DTF files containing your data transformations are built, they are built as controls. The controls expose transformation methods, which business processes invoke to map disparate data types.

  9. Click Transformation. A pane that allows you to define a transformation between your variable and the expected data type of the parameter on the control method.
  10. In Step 1, click Select Variable to display the variables in your project, then choose requestXML (QuoteRequestDocument)—that is, the variable you created for the Client Request node at the start of your business process.
  11. image

  12. In Step 2, click Create Transformation. The Transformation tool opens, which displays a representation of the QuoteRequest XML document in the Source pane, and a String in the Target pane.
  13. Click state in the Source pane and drag your mouse pointer over to String in the Target pane. A line is drawn between the state and String elements in the XML Map pane. It represents the transformation between the two data types.
  14. image

  15. To return to the process, in the Application pane, double-click the RequestQuote.jpd.
  16. Note: Creating the transformation in the preceding steps creates a Transformation control in your project: A DTF file, named RequestQuoteTransformation.dtf is created. An XQ file, which contains the query (written in the XQuery language) for the transformation method is also created. Both the DTF and XQ files are displayed in the Application tab. Also, an instance of the Transformation control was created and is represented as image transformations in the Data Palette (Controls tab).

  17. Click the X in top right-hand corner of the Request Tax Rate node builder to close it.
  18. This step completes the design of the Request Tax Rate node.

To Receive the Tax Rate Calculation From the Web Service

The interaction between the business process and the tax calculation control is asynchronous, which means that the business process can continue performing other work while the tax calculation service prepares its response. The tax calculation service notifies the business process when the response is ready.

In the preceding section you designed a call to the tax calculation Web service (via a control). To add the logic in your business process that receives the tax rate returned by the tax calculation control, complete the following steps:

  1. In the Data Palette, if needed, click the + beside the taxCalculation control to expand the list of methods available on the taxCalculation control.
  2. From the list of taxCalculation control methods, click the following method:
  3. void returnTaxRate(float taxRate) 
    
  4. Drag and drop the method onto the business process placing it on the Sales Tax Calculation Needed? node immediately below the requestTaxRate node:
  5. A Control Receive node is created representing the asynchronous response from your Web Service control.

    image

    The node is named according to the name of the method you dragged onto the business process—in this case: returnTaxRate.

  6. Double-click the returnTaxRate node. The node builder opens on the General Settings tab. The Control instance and target methods are already selected: taxCalculation and returnTaxRate(float taxRate), respectively.
  7. Click the Receive Data tab. The tab opens with the Variable Assignment pane selected.
  8. The Control Expects field is populated with the data type and name of the parameter returned by the returnTaxRate() method on the taxCalculation control: float taxRate.

  9. In the Variable Assignment pane, click the arrow in the field under Select variables to assign, then select Create new variable.... The Create Variable dialog box opens.
  10. In the Variable Name field, enter taxRate.
  11. In the Select Variable Type field, ensure that Java is selected, then select float.
  12. In the Default value field, enter 0. This initializes the value of taxRate to zero.
  13. image

  14. Click OK. Your new variable, to which the sales tax rate is assigned at run time, is created and is listed as a Java variable in the Variables tab.
  15. Click the X in the top right-hand corner of the node builder. The Control Receive node builder closes.
  16. This step completes the design of your returnTaxRate node and the design of the activities performed by your business process when the condition on the Decision node evaluates to true. In the Design View, your business process resembles that shown in the following figure:

    image

    Note that the Start node icon changed from image to image after you added the asynchronous call to the Web Service control. The former icon indicates that your business process is stateless, and the latter indicates that it is stateful.

    The icons reflect the specification for the stateless property for your business process. To see whether the stateless property is defined as true or false, click the Start node icon image and view the Property Editor. To learn about stateful and stateless business processes, see Building Stateless and Stateful Business Processes.

    Note: If the Property Editor is not displayed in WebLogic Workshop, choose View —> Property Editor from menu bar.

  17. From the Workshop menu, select File —> Save All.
  18. Note: No further design is required for this Decision node. If the condition evaluates to true, the path of execution proceeds via the Yes path and the tax rate for the order is calculated. If the condition evaluates to false—no sales tax is required—the path of execution proceeds via the No path and a value of zero is assigned to the variable taxRate. Remember, you specified that taxRate is initialized to zero when you designed the taxRate variable in the preceding section.

Related Topics

Interacting With Resources Using Controls

Creating and Testing Maps

Guide to Data Transformation

Building Stateless and Stateful Business Processes

Previous Document Next Document