TECHNOLOGY: Oracle ADF
Service, Please!By Frank Nimphius
Integrate Web services with Oracle ADF and Business Components applications.
Besides being used in SOA, Web services are a common access pattern in Web application development for remote data queries, application integration, and application departmentalization. Rather than enabling developers to directly access database tables owned by other lines of business, companies can expose the services interface to ensure data integrity and consistent application of business logic on the source data.
In this column, you will learn about the Web services integration options available for Oracle Application Development Framework (Oracle ADF) applications. Stepping through a sample application, you’ll learn how to embed calls from Oracle ADF’s Business Components models into Web services for create, read, update, and delete (CRUD) operations.
Web Services Integration in Oracle ADF
SOAP-based Web services and Oracle ADF can be integrated in several different ways. Oracle ADF’s Web Service Data Control feature is easiest to configure at design time, but it does not provide much control of a service’s runtime behavior, nor of the exchanged data. Thus, using Web Service Data Control is best for simple interactions only.
On the other hand, using the JavaBean Data Control feature or Business Components feature of Oracle ADF supports deeper, more complex integration scenarios. JavaBean Data Control can be used for integrations involving plain-old Java objects (POJOs). For applications that use Business Components as the business service layer, it makes sense to integrate the Web service application at the Business Components service integration layer and take full advantage of Business Components benefits such as participating in master-detail relationships and leveraging advanced framework features such as using model-driven lists of values.
In the JavaBean Data Control or Business Components approach, the Web services are accessed through the standard Java API for XML Web Services (JAX-WS) proxy client, which gives you programmatic control for manipulating data in transit. Rather than using the JAX-WS proxy client alone, I recommend using it in conjunction with a JavaBean wrapper. The wrapper provides a stable API for your Business Components application integration, so that if the Web service changes, you’ll only need to regenerate your JAX-WS proxy client code and drop it into place.
The example provided with this column shows you how to integrate a Web service and a Business Components application by using this recommended approach. Before delving into the step-by-step development process, let’s take a closer look at the integration architecture.
Sample Application Integration Architecture
The sample applications include a basic but complete Java Platform, Enterprise Edition Web service and a starter Business Components application that you’ll extend to support integration with the Web service. The Web service obtains data from the Departments table in the Oracle HR sample database schema.
By default, Business Components queries data from database tables and views. For Business Components to work with other datasources, such as Web services, PL/SQL stored procedures, or Java Naming and Directory Interface (JNDI) services (LDAP, for example), developers create programmatic view objects and entities that override the Business Components framework default behavior.
Figure 1 shows the class hierarchy and the integration architecture used in the sample. The JAX-WS proxy client is accessed from a JavaBean wrapper in the Business Components project. The JavaBean wrapper is accessed from methods of the WsDepartments entity object and the WsDepartmentsView view object.
Figure 1: Sample Oracle ADF Web service integration architecture
The JAX-WS Proxy Client, JavaBean Wrapper, WsEntity, and WsViewObject classes are all provided in the sample workspaces. WsEntity and WsViewObject are code templates that assist in the development of programmatic view objects and entities for Web services CRUD access. In general, I recommend building templates such as these for recurring tasks in your application development projects. (Both templates are located in the oramag.sample.application.model.fmwExtensions package of the Business Components project. Examine the code to learn more.)
In the sample integration this article covers, you’ll first create the programmatic entity object WsDepartments (using a wizard in conjunction with the WsEntity class template) and then you’ll use that object as the basis for the programmatic view object WsDepartmentsView, which you’ll also create by using the wizard and the WsViewObject class template. You’ll then complete and test the integration by adding the programmatic view object on the application module, for use from the Oracle ADF Data Controls panel.
To begin, download the sample application and unzip the file. The file contains two folders:
Building a Web Service–Based Entity Object
Web services are integrated into Business Components via programmatic view objects. To implement CRUD behavior, the view objects must be based on an entity object that overrides the built-in framework methods, doDML and doSelect, of the Business Components entity object. You provide information to Oracle JDeveloper about the properties and datatypes provided by the Web service. For the example integration, the Web service Departments entity has the following properties defined:
You now have a programmatic entity object that can be used as the basis for the view object that will access the Web service. The next step is to create the programmatic view object.
Building the Programmatic View Object
When using programmatic view objects, you must override the Business Components framework methods that query the database for data. The view object methods you will typically need to override include create, executeQueryForCollection, createRowFromResultSet, getQueryHitCount, and hasNextForCollection. (See “Key Framework Methods to Override for Programmatic View Objects” in Oracle Application Development Framework Developer’s Guide For Forms/4GL Developers to learn more.) For this sample integration, the template provides much of the code, so you won’t be selecting all these methods.
As with the programmatic entity object creation, a wizard guides you through the process. These steps begin in the OraMag-AdfBcWsApp application in the Application Navigator:
At this point, you’ve created a programmatic entity object and a custom view object that uses the entity. To make these components available to integrate the Web service with the Business Components application, you must expose the custom view object by adding it to the application module. You can also then test the integration. Starting from the Application Navigator
In the opened Oracle ADF Model Tester, double-click the allWsDepartments instance to read data from the Web service.
Click the arrows to browse and modify the data, and see how the entity and view objects you created populate the UI and make changes to data on the Web service. The Business Components project also contains a pregenerated Employees entity and view object that query employee data directly from the database. As an advanced self-study exercise, create an entity association and view link between the WsDepartments entity and the Employees entity, using the DepartmentId attribute to define the parent-child relationship.
The completed-app workspaces include this extra functionality as well as a model-driven list of values on the DepartmentId attribute of the EmployeesView object (see Figure 2). I encourage you to explore the code and learn about these powerful features.
Figure 2: Web services integration application with advanced functionality
Oracle ADF enables application developers to integrate Web services into their Business Components applications at the service layer, using a standard JAX-WS proxy client in conjunction with programmatic entity and view objects.
Frank Nimphius is a senior principal product manager for Oracle JDeveloper and Oracle Application Development Framework. He is a coauthor of Oracle Fusion Developer Guide: Building Rich Internet Applications with Oracle ADF Business Components and Oracle ADF Faces (McGraw-Hill, 2010).