< Previous | Next >

Create the mediation flow implementation

Finally, it is time to create the implementation for the HelloWorldMediation component. This component is a mediation flow and was created for you when you created the mediation module, although you could also create one by dragging a mediation flow from the palette. Because of the type of the component, you will use the mediation flow editor to implement it.

  1. Double-click on the HelloWorldMediation component and click Yes in the Open window and click OK in the Generate Implementation window. The mediation flow editor opens.

  2. At the top of the mediation flow editor, you see callHello on the left and getHello on the right. This is the single operation from this component's interface and the single operation from this component's reference, respectively. (Note that it is valid to have multiple interfaces and references for each component, and multiple operations for each interface and reference. But this is Hello World). Select the callHello interface operation and drag the yellow wire to the getHello reference operation, as shown here:
    Wired operations in mediation flow
    What you have indicated here is that you will be invoking the getHello operation as part of implementing the callHello operation for this component.

  3. Next you want to implement the flow for the callHello operation. Because this is a request response operation, you ultimately need one flow for the request and another for the response, but you start first with the request. Click callHello to see the flow in the section below, as shown here:
    Request flow

    In the flow area, you see an input node on the left, which represents control reaching your request flow by way of the callHello operation being invoked. On the right, there are two output nodes: the top one, which represents calling out to the getHello reference operation and the bottom one that represents returning to the caller of this flow. If you wire to the top callout output node, you will invoke whatever that reference is wired to, which in this case is an external Web service. If you wire to the bottom input response output node, you will end the flow and send a response back to whatever is wired to this component, which in this case is an SCA export component. However, typically the result is returned in the response flow versus this input response node.

    The flow editor allows you to place primitives between the input and output nodes and wire them together, producing a flow upon which the message travels. The message is the parameter data for the input operation, which in this case is the payload for callHello – namely, a FullName business object.

  4. You want to wire the input node to the callout output node, but you cannot do so directly from the input node because the type of the message coming in is different than the type of the message going out. (That is, the parameters of the callHello input operation are different than the parameters of the getHello output operation.) So you need to map between the two. In the palette, expand Transformation, and drag the XSL Transformation primitive to the canvas.

  5. Wire from the right edge of the input node's output terminal to the left edge of the XSLTransformation1 primitive's input terminal, as shown here:
    Request flow after wiring XSL transformation primitive
  6. Similarly, wire the right edge of the topmost output terminal of the XSLTransformation1 primitive to the input terminal of the callout output node (which is the right-most node).
    Note: The bottom output terminal is the “fail” terminal, and normally you would wire it to primitives to handle the situation where this primitive failed for some reason. For example, if you received unexpected input, the map might fail.

  7. Press Ctrl-S to save your work. Note the red X on the XSLTransformation1 primitive because you don't have a map defined yet, as shown in the following figure:
    Wired flow showing error on XSLT primitive

  8. Double-click the XSLTransformation1 primitive to create its map. The New XML Mapping window opens. Click Finish. The XML mapping editor opens.

  9. In the XML mapping editor, fully expand the left and right trees. Wire title on the left to name on the right. This creates a Move map operation.

  10. Wire firstName on the left to the Move operation in the middle. This changes the operation into a Concat operation.

  11. Wire lastName on the left to the Concat operation in the middle. You now see three wires coming in, and one going out, as shown here:
    XML mapping editor

  12. Select the Concat operation and then go to the Properties view and click the General tab.

  13. In the table, click in the Delimiter cell for title and enter a blank. Press the Enter key after typing. Repeat for the Delimiter cell for firstname.
  14. Save and close the XML mapping editor.

  15. Save the mediation flow editor and notice that the error marker goes away.

  16. Now you must wire the mediation response flow, to process the response from the Web service you invoked in the request flow and turn it into a response to the caller of this component. Select the Response:callHello tab at the bottom of the flow editor, as shown here:
    Response flow

  17. This time use a shortcut. Wire the input node on the left to the output node on the right. Because the types do not match, an XSL Transformation primitive is automatically inserted on the wire for you, as shown in the following figure:
    Wired response flow

  18. Double-click the XSLTransformation1 primitive and create the map. Map the incoming output1 field to the outgoing result field, as shown in the following figure:
    Mapping the output1 field to the result field

  19. Save and close the XML mapping editor.

  20. Finally, you want to get rid of the warning that you have not wired the fail terminal for the callout response node, as shown in the following figure:
    Warning on callout response

    The warning occurs because you have not dealt with the case when the call to the Web service fails. Expand the Error Handling category in the palette, and drag the Fail primitive to the canvas, and then wire the Callout Response fail terminal to this primitive. Then from the context menu of the Fail primitive, select Show in Properties. Go to the Details property page and enter a string like “Oops, call failed!” to include in the fault that gets sent to the caller, as shown in the following figure:

    Fail primitive details

  21. Save and close the mediation flow editor and the assembly editor.

Congratulations – the authoring steps are done! Now it is time to test.





Feedback



(C) Copyright IBM Corporation 2007, 2008. All Rights Reserved.

< Previous | Next >