Samples Tutorial

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Configuring Alternatives for Unavailable Data Sources

Sometimes a particular data source is either temporarily unavailable or very slow to send a response back to a consuming application. In such cases, you need to be able to run an alternative data source. ALDSP enables you create an alternative data source that will be called if the primary data source does not respond within a specified time frame.

 


Objectives

After completing this lesson, you will be able to:

 


Overview

Enabling an alternative data source is implemented by calling the fn-bea:timeout() function. The syntax for the function is as follows:

fn-bea:timeout($seq as item()*, $millis as xs:int, $alt as item()*) as item()*

where:

To implement this functionality, the return types of both the primary and alternative expression should be available when the project is compiled. This ensures that the function's return type is correctly inferred. In other words, the source metadata must be available at compile time, because the alternative source function provides only runtime failover capability.

 


28.1 Setting the Demonstration Conditions

You will import a slow Web service into your application, thereby enabling the demonstration of configuring alternatives for unavailable data sources.

Objectives

In this exercise, you will:

Instructions

  1. Right-click the Evaluation folder and then import the <beahome>\weblogic81\samples\LiquidData\EvalGuide\CreditWS file as a Web Service Project. This will import a simple Web service that does nothing but sleep for 3 seconds. Click `Yes' when asked for "Files required for Web Services are not in the project. Do you wish to add them?"
  2. Build the CreditWS project.
  3. Test the slow Web service by completing the following steps:
    1. Open the NewCreditReport.jws, located in the CreditWS folder.
    2. Click the Start icon (or press Ctrl + F5). The Workshop test browser opens.
    3. Enter CUSTOMER3 in the cid field and click NewLookupCredit.
    4. Confirm that you can get credit rating information.
    5. Figure 28-1 Test Browser View of the Slow Web Service


      Test Browser View of the Slow Web Service

  4. Create a physical data service for the slow Web service, by completing the following steps:
    1. Select the Overview tab in the Workshop Test Browser.
    2. Click Complete WSDL.
    3. Copy the WSDL URI, which you will use to import an alternative data service. The URI typically is:
    4. http://localhost:7001/CreditWS/NewCreditReport.jws?WSDL=
    5. In the Application pane of WebLogic Workshop, right-click the WebServices folder (located in DataServices).
    6. Choose Import Source Metadata.
    7. Select Web Service from the Data Source Type drop-down list and click Next.
    8. Paste the WSDL URI into the URI field, then click Next.
    9. Expand the folders and select the NewLookupCredit operation.
    10. Click Add to populate the Selected Web Service Operations pane and click Next.
    11. Note: Do not select NewLookCredit as a side-effect procedure.
    12. Review the Summary information and click Finish.
  5. Check the Application pane. There should be a new physical data service called NewLookupCreditResponse.ds.
  6. Open NewLookupCreditResponse.ds in Design View. There should be a function called NewLookupCredit.
  7. Figure 28-2 Design View of Web Service-Based Data Service


    Design View of Web Service-Based Data Service

 


28.2 Configuring Alternative Sources

Because the CreditWS Web service is slow, you need to configure an alternative source to obtain the credit rating information in a timely manner.

Objectives

In this exercise, you will:

Instructions

  1. Open CustomerProfile.ds in Source View. (The file is located in DataServices\CustomerManagement.
  2. Add the following code to the namespace declaration:
  3. declare namespace ws3="ld:DataServices/WebServices/NewLookupCreditResponse";
    declare namespace ws4 = "http://www.openuri.org/";
  4. Locate the getAllCustomers() function.
  5. Locate the following entry:
  6. { 	
    for $rating  in ws1:getCreditRating( 
        <ws2:getCreditRating>
            <ws2:customer_id>{data($CUSTOMER/CUSTOMER_ID)}</ws2:customer_id>
        </ws2:getCreditRating> )
    return 
        <creditrating>      
            <rating>{data($rating/ws2:getCreditRatingResult/ws2:Rating)}</rating>
            <customer_id>{data($rating/ws2:getCreditRatingResult/ws2:Customer_id)}</customer_id>
        </creditrating>                                       
    }
  7. Replace that entry with the following code and note the use of the fn-bea:timeout() function.:
  8. {
    <creditrating>      
      <rating>
        {
        fn-bea:timeout(
            data(
                ws3:NewLookupCredit( 
                    <ws4:NewLookupCredit>
                        <ws4:cid>{data($CUSTOMER/CUSTOMER_ID)}</ws4:cid>
                    </ws4:NewLookupCredit>
                    )/ws4:NewLookupCreditResult/ws4:CreditCode
            )  
            , 2000,             
            data(
                ws1:getCreditRating( 
                    <ws2:getCreditRating>
                        <ws2:customer_id>{data($CUSTOMER/CUSTOMER_ID)}</ws2:customer_id>
                    </ws2:getCreditRating> )/ws2:getCreditRatingResult/ws2:Rating)
            )                    
        }
      </rating>
      <customer_id>{data($CUSTOMER/CUSTOMER_ID)}</customer_id>
    </creditrating>                                       
    }

 


28.3 Testing an Alternative Source

Testing getAllCustomers() function will let you confirm that the query is retrieving data from the alternative source, rather than the CreditWS.

Objectives

In this exercise, you will:

Instructions

  1. Build the DataServices project.
  2. Enable auditing for the getAllCustomers() function using the AquaLogic Data Services Platform Console. For details about auditing, refer to http://download.oracle.com/docs/cd/E13167_01/aldsp/docs21/admin/monitor.html.
  3. Open CustomerProfile.ds located in CustomerManagement folder in Test View.
  4. Select getAllCustomers() from the function drop-down list.
  5. Click Execute.
  6. Open the Output window, scroll to the bottom, and then confirm that the CreditWS Web service times out and then the CreditRating Web service is called. The output should display as shown in Figure 28-3.

    Figure 28-3 Output Window


    Output Window

    The invocation of the first Web service NewLookupCreditResponse fails because the thread times out. Because this Web service has failed it will not be invoked again. Instead, the alternate Web service is invoked.

 


Lesson Summary

In this lesson, you learned how to:


  Back to Top       Previous  Next