Using Service Callout action to invoke a service

In this recipe, we will use a Service Callout action to call another service from a proxy service message flow.

We will use the sample setup from the first chapter of this book and add an additional service call to another service Credit Card Info Service, which returns the credit card information. The service call will be done using the Service Callout action. Both the information from the Credit Card Info Service and from the Customer Service will then be merged by the XQuery transformation into one single response returned by the proxy service.

Using Service Callout action to invoke a service

Getting ready

You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from chapter-9getting-readyusing-service-callout.

Start the soapUI mock services simulating the two external services on the CRM system by double-clicking on start-CreditCardInfoServiceCRM.cmd and start-CustomerServiceCRM.cmd in the chapter-9getting-readymisc folder.

How to do it...

First, we will create a new business service which will wrap the additional Credit Card Info Service interface on the CRM system. In Eclipse OEPE, perform the following steps:

  1. Create a new business service in the business folder and name it CreditCardInfoService.
  2. On the General tab choose WSDL Web Service for the Service Type option and click Browse.
  3. Click Consume and select URI from the Service Resource drop-down listbox.
  4. Enter the endpoint URI of the soapUI mock service http://localhost:8090/mockCreditCardInfoServiceSOAP?WSDL into the URI field and click OK.
  5. Select the CreditCardInfoServiceSOAP (port) node and click OK.
  6. Confirm the pop-up window by clicking OK.
  7. Rename the imported WSDL from mockCreditCardInfoServiceSOAP.wsdl to CreditCardInfoService.wsdl and move it into the wsdl folder.

    By doing that, we have created the new business service. Now, let's add the Service Callout action to the proxy service calling the new business service. In Eclipse OEPE, perform the following steps:

  8. Open the Message Flow tab of the CustomerManagement proxy service.
  9. In the FindCustomer branch, right-click on the Response Action flow of the Routing action and select Insert Into | Communication | Service Callout to add a Service Callout action just before the Replace action. We want to enrich the message, before the transformation to the canonical format is made.
  10. On the Properties tab of the Service Callout action, click Browse and select the CreditCardInfoService business service.
  11. Select RetrieveCreditCardById from the Invoking drop-down listbox.
  12. Select the Configure Soap Body option.
  13. Enter creditCardInfoRequest into the Request Body field and creditCardInfoResponse into the Response Body field.
    How to do it...
  14. Insert an Assign action into the Request Action flow of the Service Callout action.
  15. On the Properties tab of the Assign action, click on <Expression> and enter the following XML fragment into the Expression field:
    <soap-env:Body>
        <cred:RetrieveCreditCardById>
            <id>{$body/cus:FindCustomer/ID/text()}</id>
        </cred:RetrieveCreditCardById>
    </soap-env:Body>
  16. Navigate to the Namespace Definition tab, add a namespace with cred for the Prefix and http://www.crm.org/CreditCardInfoService/ for the URI field and click OK.
  17. Enter creditCardInfoRequest into the Variable field.

    We have added the Service Callout action to the proxy service. The message flow should look as shown in the following screenshot:

    How to do it...

    The result of the Service Callout action is available in the creditCardInfoResponse variable. We now have to adapt the XQuery transformation to merge the message from the Service Callout and the Routing into one single response message. In Eclipse OEPE, perform the following steps:

  18. Open the TransformFindCustomerResponse.xq XQuery transformation and navigate to the Source tab.
  19. Add an additional parameter to the XQuery transformation by adding the following line to the top:
    (:: pragma bea:global-element-parameter parameter="$retrieveCreditCardInfoByIdResponse1" element="ns4:RetrieveCreditCardByIdResponse" location="../wsdl/CreditCardInfoService.wsdl" ::)
  20. Declare an additional namespace:
    declare namespace ns4 = 
        "http://www.crm.org/CreditCardInfoService/";
  21. Add the parameter to the declaration of the TransformFindCustomerResponse function:
    declare function xf:TransformFindCustomerResponse
        ($retrieveCustomerByCriteriaResponse1 as 
            element(ns0:RetrieveCustomerByCriteriaResponse),
        $retrieveCreditCardInfoByIdResponse1 as 
            element(ns4:RetrieveCreditCardByIdResponse))
        as element(ns3:FindCustomerResponse) {
            <ns3:FindCustomerResponse>
  22. Declare an additional variable and add the variable to the invocation call:
    declare variable $retrieveCreditCardInfoByIdResponse1 as
        element(ns4:RetrieveCreditCardByIdResponse) external;
    
    xf:TransformFindCustomerResponse(
        $retrieveCustomerByCriteriaResponse1, 
        $retrieveCreditCardInfoByIdResponse1)
  23. Navigate back to the Design tab and the new parameter with the Credit Card Info data will be shown. Map the credit card information to the FindCustomerResponse message. The mapping should look as shown in the following screenshot:
    How to do it...

    Last but not least we have to change the existing invoke of the XQuery in the Replace action so that the additional parameter is passed. In Eclipse OEPE, perform the folowing steps:

  24. Select the Replace action following the Service Callout action and navigate to the Properties tab.
  25. Click on the link to the right of Expression to reselect the XQuery transformation.
  26. Click Browse, select the TransformFindCustomerResponse.xq XQuery resource and click OK.
  27. Enter $body/ext:RetrieveCustomerByCriteriaResponse into the retrieveCustomerByCriteriaResponse1 field and $creditCardInfoResponse/cred: RetrieveCreditCardByIdResponse into the retrieveCreditCardInfoByIdResponse1 field.
  28. Click OK.
  29. Deploy the project to the OSB server.

    Now let's test the proxy service from soapUI:

  30. Import the CustomerManagement-soapui-project.xml from the chapter-9getting-readymisc folder.
  31. Double-click on Request 1 inside the FindCustomer operation.
  32. Check that the endpoint of the proxy service is correctly set up in the drop-down listbox on the top.
  33. Click on the green arrow to execute the test and make sure that the CreditCard information is returned in the response.
    How to do it...

How it works...

We have used the Service Callout action in this recipe to invoke an additional service besides the one already called through the Routing action. By doing that, we are able to, for example, enrich a message, either before or after doing the routing. In our case, we have added the credit card information to the canonical response message returned to the consumer. By adding the Service Callout action into the Response Action of the Routing action, we decided that the callout is done after the Routing has been successfully executed.

A Service Callout only works with WSDL operation which implements the request/response message exchange pattern. One-way operations cannot be invoked by the Service Callout action, use the Publish action instead.

There's more...

In this recipe, we have seen the Service Callout in action. But what is the difference between a Service Callout and a Routing action?

A Routing action can only be used inside a Route node and will always have to be placed at the end of the proxy service message flow. No other actions can follow a routing node in the message flow. The Routing action will define where the request thread stops and where the response thread starts. The request and response pipeline of an OSB proxy service are always executed in two different threads. A Routing action supports both request/response as well as one-way message exchange patterns.

The Service Callout action can be placed anywhere where an OSB action is valid. There is no limit for the number of Service Callout actions which can be used. A Service Callout placed in the request pipeline will be performed by the request thread, a Service Callout in the response pipeline by the response thread. A Service Callout only supports the request/response message exchange pattern and will always be synchronous, that is, it waits for the response message.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset