One of the data sources available with the samples installed with ALDSP is a Web service that provides customer credit rating information. In this lesson, you will generate a physical data service that can be integrated into the CustomerProfile logical data service.
The process for creating a data service based on a Web service is similar to importing relational database source metadata. The difference is that ALDSP uses the WSDL (Web services description language) metadata to introspect the Web service's operation and generate the data service.
Objectives
After completing this lesson, you will be able to:
Import a WSDL.
Use the WSDL to generate a data service.
Test the Web service by passing a SOAP request body as a query parameter.
Use a logical data service to invoke the Web service and retrieve data.
Overview
A Web service is a self-contained, platform-independent unit of business logic that is accessible to other systems on a network. The network can be a corporate intranet or the Internet. Other systems can call the Web services' functions to request data or perform an operation.
Web services are increasingly important resources for global business information. Web services can facilitate application-to-application communication and are a useful way to provide data, like stock quotes and weather reports, to an array of consumers over a corporate intranet or the Internet. But they take on additional new power in the enterprise, where they offer a flexible solution for integrating distributed systems, whether legacy systems or new technology.
WSDLs are generally publicly accessible and provide enough detail so that potential clients can figure out how to operate the service solely from reading the WSDL file. If a Web service translates English sentences into French, the WSDL file will explain how the English sentences should be sent to the Web service, and how the French translation will be returned to the requesting client.
6.1 Importing a Web Service Project into the Application
When you want to use an external Web service from within WebLogic Workshop, you should first obtain that service's WSDL file. In this exercise, you will use the WSDL for a Web service project that was created in WebLogic Workshop.
Objectives
In this exercise, you will:
Import the CreditRatingWS Web service into your sample application. This Web service provides getCreditRating() and setCreditRating() functions for retrieving and updating a customer's credit rating.
Run the Web service to test whether you can retrieve credit rating information.
Instructions
Import a Web service into the ALDSP-enabled application, by completing the following steps:
Choose File Import Project. The Import Project - New Project dialog box opens.
Select Web Service Project.
Caution:
Make sure that you select a project of type Web service. If you select another project type, then the CreditRatingWS application may not work correctly.
In the directory field, click Browse.
Navigate to <beahome>\weblogic81\samples\liquiddata\EvalGuide
Select CreditRatingWS and click Open.
Make sure that the Copy into Application directory checkbox is selected.
Click Import and then click Yes when the confirmation message to update your project appears.
Figure 6-1 Import Web Services Project
In the Application pane, verify that the following items were imported:
A CreditRatingWS project folder containing:
A controls folder, within which are the CreditRatingDB.jcx control and CreditratingDBTest.jws Web service.
A credit rating folder, within which is the Web service folder that contains the CreditRating.java file.
A WEB-INF folder.
Figure 6-2 Web Service Project
Open CreditRatingDBTest.jws in Design View. This file is located in CreditRatingWS\controls. The Web service diagram should be as displayed in Figure 6-3.
Figure 6-3 Design View of Credit Rating Web Service
Test the imported Web service, by completing the following steps:
Click the Start icon, or press Ctrl + F5, to open Workshop Test Browser.
Enter CUSTOMER3 in the customer_id field.
Click getCreditRating. The requested information displays in Workshop Test Browser.
Figure 6-4 Workshop Test Browser
Scroll down to the Service Response section and confirm that you can retrieve credit rating information for CUSTOMER3.
Figure 6-5 Web Service Results
6.2 Importing Web Service Metadata into a Project
WSDL is a standard XML document type for describing an associated Web service so that other software applications can interface with the Web service. Files with the .wsdl extension contain Web service interfaces expressed in the Web Service Description Language (WSDL).
A WSDL file contains all the information necessary for a client to invoke the methods of a Web service:
The data types used as method parameters or return values.
The individual method names and signatures (WSDL refers to methods as operations).
The protocols and message formats allowed for each method.
The URLs used to access the Web service.
Objectives
In this exercise, you will:
Import the CreditRatingWS source metadata via its WSDL, into the DataServices project, thereby generating a new data service (getCreditRatingResponse.ds).
Confirm that the new data service includes the getCreditRating() function that you tested in the previous exercise.
Instructions
In Workshop Test Browser, scroll to the top of the window.
Click the Overview tab.
Figure 6-6 Workshop Test Browser Overview
Click Complete WSDL.
Copy the WSDL URI, located in the Address field. The URI is typically: http://localhost:7001/CreditRatingWS/controls/CreditRatingDBTest.jws?WSDL=
Figure 6-7 WSDL URI
Close Workshop Test Browser.
In Workshop: Close all open files (File Close All Files).
Create a new folder within the DataServices project folder, and name it WebServices.
Import Web service source metadata into the WebServices folder, by completing the following steps:
Right-click the WebServices folder.
Choose Import Source Metadata.
Choose Web Service from the Data Source Type drop-down list. Then click Next.
Figure 6-8 Web Service Data Source Type
Paste the copied WSDL URI into the URI or WSDL File box and click Next.
Figure 6-9 Paste the URI
Expand the CreditRatingDBTestSoap and Operations folders.
Select getCreditRating operation, and click Add to populate the Selected Web Service Operations pane.
Click Next.
Figure 6-10 Selected Web Service Operations
Do not select the getCreditRating procedure as the side effect procedure in the Select Side Effect Procedures dialog box. Click Next.
Figure 6-11 Data Service Procedure Option (Unselected)
Review the Summary information, which includes:
Function name.
XML type, for Web service objects whose source metadata will be imported.
Name, for each data service that will be generated from the source metadata. (Any name conflicts appear in red and must be resolved before proceeding. However, you can modify any data service name.)
Add to Existing Data Service, to add the function to an existing data service.
Location, where the generated data service(s) will reside.
Click Finish.
Figure 6-12 Web Services Summary
Open getCreditRatingResponse.ds in Design View. This file is located in DataServices\WebServices.
Confirm that there is a function called getCreditRating().
Figure 6-13 Web Service Function Added
6.3 Testing the Web Service via a SOAP Request
Extensible Markup Language (XML) messages provide a common language by which different applications can talk to one another over a network. Most Web services communicate via XML. A client sends an XML message containing a request to the Web service, and the Web service responds with an XML message containing the results of the operation. In most cases these XML messages are formatted according to Simple Object Access Protocol (SOAP) syntax. SOAP specifies a standard format for applications to call each other's methods and pass data to one another.
Note:
Web services may communicate with XML messages that are not SOAP-formatted. The types of messages supported by a particular Web service are described in the service's WSDL file.
Objectives
In this exercise, you will:
Use the getCreditRating() function and a SOAP parameter to test getCreditRatingResponse.ds.
Review the results.
Instructions
Build the DataServices project.
Open getCreditRatingResponse.ds in Test View. (This file is located in DataServices\WebServices.)
Select getCreditRating(x1) from the Function drop-down list.
Enter the following SOAP body in the Parameter field:
<getCreditRating xmlns="http://www.openuri.org/">
<customer_id>CUSTOMER3</customer_id>
</getCreditRating>
Note:
An alternative to adding the SOAP body in the parameter field is to use a template for the input parameter by clicking Insert Template.
Figure 6-14 SOAP Parameter
Click Execute.
Review the results, which should be similar to those displayed in Figure 6-15 (Rating:600, CustomerID: CUSTOMER3). Notice that only two data elements are returned: the customer ID and the credit rating for that customer.
Figure 6-15 Web Service Results
6.4 Invoking a Web Service in a Data Service
You are now ready to use the Web service to provide the data that populates the CustomerProfile logical data service.
Objectives
In this exercise, you will:
Use the getCreditRatingResponse data service to populate the credit rating element in the CustomerProfile data service.
Test the invocation.
Review the results.
Instructions
Open CustomerProfile.ds file in Source View. The file is located in DataServices\CustomerManagement.
In the Source View, add the following namespace definitions, in addition to the ones already defined for the CustomerProfile data service:
Open the creditRatingXQuery.txt file, located in <beahome>\weblogic81\samples\LiquidData\EvalGuide in a text editor.
Copy all the code from the creditRatingXQuery.txt file.
In the CustomerProfile.ds file, expand the getAllCustomers() function.
Insert the copied text into the section where the empty CreditRating complex element is located. The empty complex element is as follows:
<creditrating>
<rating></rating/>
<customer_id></customer_id>
</creditrating>
Note:
The copied code replaces everything after: </orders> and before <valuation>.
Confirm that the <creditrating> code is as displayed in Figure 6-16.
Figure 6-16 Credit Rating Source Code
View the results, by completing the following steps:
Open CustomerProfile.ds in XQuery Editor View.
Select getAllCustomers() from the Function dropdown list. The function should be similar to that displayed in Figure 6-17.
Figure 6-17 XQuery Editor View of a Web Service Being Invoked
Open CustomerProfile.ds in Design View. The Web service is listed as a data source, in the right pane of the diagram.
Figure 6-18 Design View of a Web Service Invoked in a Data Service
Test the data service by completing the following steps:
Build the DataServices project.
Open CustomerProfile.ds in Test View.
Select getCustomerProfile(CustomerID) from the Function drop-down list.
Enter CUSTOMER3 in the xs:string CustomerID field.
Click Execute.
Confirm that you can retrieve the credit rating for Customer 3.
Figure 6-19 Customer Profile Data Integrated with Web Service Credit Rating Data
Import the CreditRatingExit1.java file from the EvalGuide folder:
Right-click the WebServices folder.
Select Import option.
Navigate to <beahome>\weblogic81\samples\LiquidData\EvalGuide and select file CreditRatingExit1.java for import. Click Import.
Build the DataServices project.
Open getCreditRatingResponse.ds in Design View. Set the UpdateOverride Class property in the Property Editor to WebServices.CreditRatingExit1. (If the Property Editor is not open, you can select it using the View menu Property Editor option.)
Click the browser symbol in the Update Override Class field.
Navigate to the DataServices.jar -> WebServices folder.
Select the CreditRatingExit1.class file. Click open.
Figure 6-20 Selecting the Update Override Class
(Optional) Open the Output window to view the data sources used to generate the Test View results. You should see the following statement, which indicates that data was pulled from the invoked Web service:
Note:
To perform this step, you need to enable auditing in the ALDSP Console.
Figure 6-21 Viewing the Data Sources in the Output Window
Lesson Summary
In this lesson, you learned how to:
Import a Web service project, locate its WSDL, and use that WSDL to generate a data source.
Test the Web service by passing a SOAP request body as a query parameter.