To better understand WebLogic Web services, you need to look at the basis of the 7.0 implementation: JAX-RPC 1.0. The JAX-RPC ModelJAX-RPC (Java APIs for XML-based RPC) is a finalized Java specification from Sun Microsystems for standardized Web service invocation, processing, and deployment. JAX-RPC is actually generalized to handle Remote Procedure Call mechanisms employing any protocol or transport, but in the context of this WebLogic Server discussion, we are binding JAX-RPC to the SOAP protocol and the HTTP transport of Web services. The WebLogic Platform Web services implementation is faithfully based on the JAX-RPC 1.0 specification. Therefore, understanding JAX-RPC is essential for the comprehension and effective use of the WebLogic Server Web services features. Tip General knowledge of XML and XML namespaces will aid in understanding portions of the JAX-RPC specifications. Refer to the XML specifications available at http://www.w3.org for more information. Some of the more important elements specified by JAX-RPC are
The specification also imposes rules on XML encodings for SOAP messages, protocol bindings, and transport. Note that JAX-RPC does not alter nor enhance the definition and semantics of WSDL or UDDI. Note None of the use cases described in this chapter utilize UDDI, implicitly or otherwise . WebLogic Platform 7.0 does offer extensive support and tools for UDDI, and this issue will be discussed in Chapter 31. WebLogic Server 7.0 offers all these JAX-RPC features and more, and has fully passed the JAX-RPC 1.0 Technology Compatibility Kit (TCK) test suite for both Servlet and J2EE Container requirements. Consequently, any client- or server-side Web services code you develop with WebLogic Server can be deployed and run on any JAX-RPCcompliant Web service container, thereby protecting your investment. Serializers and DeserializersWhen you invoke a Web service using a Java method call, its arguments, which are Java primitives or objects, must be translated into XML constructs for inclusion into a SOAP message. The process of converting a Java object to XML representation is called serialization . Conversely, before a Web service response can be returned to the caller, the SOAP return message containing results in XML format must be translated back to the appropriate Java primitives or objects. This conversion is known as deserialization . These conversions are implemented in the serializer and deserializer Java classes. Figure 29.12 shows where these conversions occur in a Web service use case. Figure 29.12. The place where Java to XML conversions, and vice versa, occur.
Client proxies provide a higher level abstraction layer that shields the client from underlying tasks such as building the SOAP message, parsing a SOAP response, and performing HTTP protocol activities. We will discuss client proxies in more depth later. As you can see, both the client proxy and the SOAP servlet use serializers and deserializers. The following statements explain Figure 29.12 (the numbers in parentheses correspond to those in the figure):
In essence, call data needs to be in XML (SOAP) format before transporting via HTTP (serialize), and call data needs to be in Java format before it can be used by a client or back-end service ( deserialize ). As mentioned earlier, JAX-RPC prescribes rules on Java-to-XML mapping and vice versa, on a definite set of data types, listed in the following section. The WebLogic Server has coded these rules into default serializer and deserializer classes that are automatically and appropriately invoked when any built-in type is used in a Web service method call. However, if your Web service methods use user -defined Java types (UDT or nonbuilt-in types) for parameters and return values, custom serializers and deserializers must be written or generated, and configured via type mappings into your Web service. This effectively extends the WebLogic/JAX-RPC built-in type mapping system. The next chapter explains how to define UDTs and mappings. Supported or Built-in TypesTable 29.1 lists the Java types that are supported by WebLogic Server and their mappings to XML. Table 29.1. Java Types Supported by WebLogic Server and Their Mappings to XML
Use of any of these types in your Web service methods requires no additional consideration or programming to ensure proper translation, interpretation, and delivery via SOAP and WSDL. They are translated between Java and XML automatically. SOAP HandlersBecause JAX-RPC and WebLogic Server provide such a convenient abstraction for performing all facets of Web services, you normally do not need to nor get to build the SOAP message yourself. Sometimes this feature could become a limitation. If you must influence the SOAP message in some way, JAX-RPC provides the concept of handlers for intercepting SOAP messages (both requests and responses) before they reach their destination. Handlers are Java classes that can be configured for invocation by the Web service container at appropriate junctures. You can do almost anything inside a handler, maybe even fulfill simple Web service requests without invoking a back-end component. Figure 29.13 clarifies where in a Web service call such handlers come into play. Figure 29.13. How handlers intercept SOAP messages.
Note To better illustrate handlers, Figure 29.13 is simplified in that it does not show the client invoking serializers and deserializers. Have you noticed that handlers always work with the SOAP message, that is, the XML representation of the request or response as opposed to the Java representation? You develop the Handler class code and then configure it as part of defining a Web service. Details are reserved for the next chapter. For now, you can scrutinize the make-up of a WebLogic Web service in the next section. Inside a Synchronous (RPC) Web ServiceFigure 29.14 shows the components that make up an End-to-End synchronous Web service call and fulfillment. Details on how to develop or generate these components will be discussed in the next chapter. Figure 29.14. The components that make up an End-to-End synchronous Web service call and fulfillment.
Each component plays the following role in the game:
To see what transpires in the WebLogic Web service container, you can expand the server components as shown in Figure 29.15. Figure 29.15. A look inside the Web service container.
Each of the numbered steps in Figure 29.15 is explained here:
WebLogic Web services even support building a Web service provider that is solely composed of handlers and no back-end component (class or EJB). In this case, the handler alone fulfills the service request. A more realistic scenario is for a handler to cache results of certain popular service requests, with a TTL (Time to Live) on the cache. If the cache is up to date, the handler can just return its contents without invoking the back-end component. When the cache expires or is empty, the back-end component is invoked first, and the results are cached and then returned. This could significantly increase performance and scalability of a Web service. The client internals are similar to what was described previously for the server. Handlers can be installed on outgoing SOAP requests as well as incoming SOAP results. Client-side handlers can also perform caching, which also will save network overhead. Inside an Asynchronous Web ServiceAs you recall from Figure 29.11, an asynchronous service utilizes JMS destinations and message-driven beans to deliver complex business logic to service clients . Such a service provides at least two operations:
Figure 29.16 depicts the component architecture for such a service. Figure 29.16. The component architecture for an asynchronous Web service.
Processing steps for an asynchronous Web service are as follows :
In practice, for reliability and for avoiding timing issues, another listener needs to be added, and JMS Destination 2 must subscribe to it. The new listener's sole function is to cache or persist the result. The requestData service can then check this persistent store for results. You might ask if the JMS destinations should be queues or topics. The rule of thumb is to use a JMS queue if there is only one kind of MDB that can process the request data because the WebLogic EJB container can instantiate as many MDB instances as necessary to handle the load. However, if there are multiple kinds of MDBs, a JMS topic would allow them all to subscribe to it and process data concurrently. You also might observe that this implementation, as is, does not scale to multiple users. Because the Web service may serve many clients, how does the requestData operation ensure that one client's result will not inadvertently be delivered to another client? One simple solution is to include with each submitData request some unique client ID, which is also to be included with each requestData call. A more elegant design would allow this asynchronous Web service to alert the client immediately when his result becomes available, thereby obviating the need for any polling. The WebLogic Workshop Web service IDE can do just that, and is discussed in Chapter 32. For this discussion, it behooves you to contemplate how the client might implement a callback mechanism. |