- Designing Interoperability
- Publishing Enduring Web Services Contracts
- Effectively Using Business-Tier Systems
- Planning a Robust Production Environment
- Summary
Effectively Using Business-Tier Systems
Web services are usually built on existing business-tier systems. To effectively interface with these systems, you have to take into consideration the communication, frequency of interaction, and degree of exposure to the business components. For example, a purchase order web service must effectively interface with the underlying ERP systems.
Facilitating Asynchronous Communication
Web services can be designed to be synchronous or asynchronous in nature. In synchronous mode, a web service implements a call-and-response RPC mode of interaction. Here, when the service is invoked, the business logic behind the web service executes the logic while the client is waiting for a response. For example, this can be used in getting price quotes and stock quotes.
For complex processes such as orders and order changes, processing might take minutes or even days to complete. This is particularly true when the web service implementation depends on batch processing or manual steps that require human intervention. This is an asynchronous web service. The client does not wait for the response to do the next steps. It either checks back periodically to see if the process is completed on the web service producer side, or acts as a listener to any updates.
Web services standards include the infrastructure and mechanisms on which asynchronous operations can be based. Handling web services interactions asynchronously is useful to accommodate user interactions, legacy IT systems, and partner IT systems. In these instances, systems must not block one another, and relevant systems and data must be easy to connect. This is also essential for scalability.
To effectively build composite, asynchronous applications, Workshop provides a model for web service conversations. A conversation is a series of message exchanges in both directions that are related and share some context. The Workshop framework automatically manages a unique ID for each conversation, and messages in a conversation are related through a conversation ID. In addition, any class member variables are automatically persisted and available later as the conversation continues. To use conversations in Workshop, methods must be annotated as starting, continuing, or finishing a conversation. To start a conversation, you can use the following tag:
* @jws:operation * @jws:conversation phase="start"
SOAP conversation is a SOAP- and WSDL-based specification that defines long-running and asynchronous interactions between SOAP-based senders and receivers.Workshop web service conversations enable you to easily build asynchronous web services without having to write the underlying infrastructure typically associated with these types of applications (see Figure 5.4).
Figure 5.4 Asynchronous web service
Using a Coarsely Grained Approach
Much of the design of a web service interface involves designing the service's operations. After you determine the service's operations, you define the parameters for these operations, their return values, and any errors or exceptions that they can generate. That is, you define the method signatures of the service.
You should define the web service's interface for optimal granularity of its operations. Although finely grained service operations, such as an operation to browse a catalog by categories, products, or items, offer greater flexibility to the client, they also result in greater network overhead and reduced performance. More coarsely grained service operations, such as returning catalog entries in a set of categories, reduce network overhead and improve performance, although they are less flexible. Generally, you should consolidate finely grained operations into more coarsely grained ones to minimize expensive remote method calls. The key benefits of coarsely grained web services are that they provide a uniform interface, reduce coupling, increase manageability and reusability, centralize security management and transaction control, and improve performance.
With WebLogic Workshop, the XML documents that you exchange are business-level documents, such as entire invoices or purchase orders. The coarsely grained web services can access finely grained business logic through the control framework of WebLogic Workshop. You can have web services, such as purchase orders, that access finely grained controls for business logic such as EJB controls and database controls.
Exposing Business Logic Components
The Model-View-Controller (MVC) architecture is one of the well-known architecture frameworks used in many web-based applications. The MVC design is modular, separating the key components of the architecture:
ModelContains data required by the application
ViewManages the presentation of the data to the user
ControllerActs as an intermediary between the client and the data
The MVC approach (see Figure 5.5) can allow an organization to expose multiple interfaces to the same set of data. For example, consider a web service in which EJBs provide the data from a database (Model), JSPs are used to present the data (View), and servlets mange the interface between the client and the data (Controller). Now, if the client device changes from a browser to a PDA, the View can be changed from HTML to WML without affecting the EJBs and servlets. Also, if web services can be considered as just another View on the model, a web services presentation can easily be plugged into an existing MVC architecture. In this case, instead of HTML or WML being sent back to the client application, the web services View would construct XML or SOAP messages through interactions by interacting with the Controller.
Figure 5.5 MVC architecture
A Java class or an EJB can perform the business logic for fulfilling a web service request. The EJBs that support web services are session- and message-driven beans. Stateless session beans facilitate RPC-style web services that result in component operation invocations. Message-driven beans facilitate document-oriented web services. They do asynchronous messaging through a JMS consumer. Java classes can also be used for the business logic and are simpler to implement.
WebLogic Workshop has a Controls Framework with many built-in controls, such as database, EJB, and web service, that can wrap the back-end components and help expose them as web services. We talk more about the Controls Framework in Chapter 8, "Using Controls, Bindings, and Parsers."
The Web Flow Framework is a visual representation of presentation scenarios in WebLogic Workshop. The web flow framework is based on Struts, which is based on the MVC design paradigm. WebLogic Workshop facilitates the Web Flow Framework, which extends the Struts framework to provide a simplified development model with numerous additional features.
Companies such as HP are using frameworks such as SSA, which is described in the accompanying sidebar to build well-designed robust, scalable, and extensible web services. SSA complements standard J2EE web service toolkits such as WebLogic Workshop and helps HP IT in creating a consistent, repeatable approach to developing web services in J2EE.
Shared Services Architecture
The Shared Services Architecture (SSA) is a framework based on J2EE standards that was developed at HP to meet developers' needs for reusable services. The first version of the SSA was released in the year 2000, and support for creating web services was added in 2002. The SSA was developed by and is maintained by a small team within HP IT; it is the corporate standard framework for all internal Java-based web services development.
As we have discussed in this chapter, there is more to programming of web services, in production, you need modular, reusable, high-performance web services. This is where the SSA framework codifies the use of best practices, including design patterns, into a ready-to-use architecture and offers a robust, flexible framework for implementing enterprise-class web services.
The SSA offers developers a set of higher-level abstractions such as Request, Result, Feature, and Business Policy that developers can start with instead of having to start with a clean slate for every new service that they implement.
The SSA offers help in several areas:
-
Designing and developing a layered service implementation
-
Developing a modular, reliable, scalable, high-performance service
-
Designing and developing a modular, easily repurposable user experience implementation
-
Enforcing business rules in an easy-to-change fashion
-
Dealing with error handling and metrics gathering
-
Providing scalability and availability, ERP/legacy integration, authentication, and authorization
-
Specifying and controlling the overall flow and calling service components at predefined points in time using predefined interfaces. Conceptually, this is very similar to what other frameworks such as Struts offer for building web UIs in Java.
As complements of the core SSA framework itself, there are several plug-ins, utilities, and tools. The plug-ins expand the base functionality available in SSA and are analogous to web browser plug-ins. The list of available plug-ins includes the Apache Axis and the WebLogic SOAP plug-in for exposing SSA services as web services with different web services toolkits. The utilities include APIs for logging, metrics gathering, and lifecycle management. The tools include development tools such as code-generation wizards and deployment tools such as scripts and Ant build files.
Several key business benefits are associated with using SSA, including faster time to market, reduced total cost of ownership (TCO), reduced support costs, improved developer productivity, and improved capability to react to change. The SSA framework presently is being used in HP's identity-management solution for external users, HP Passport. It allows all external users to HP to be registered through web services built with the SSA framework in the BEA WebLogic plug-in. The SSA framework has helped make this solution robust and scaleable. It has high performance and is very flexible in adding operations to the existing web services.