Designing the SOAP Message Handlers and Handler Chains

9-4 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server

9.3 Designing the SOAP Message Handlers and Handler Chains

When designing your SOAP message handlers and handler chains, you must decide: ■ The number of handlers needed to perform all the work ■ The sequence of execution Each handler in a handler chain has one method for handling the request SOAP message and another method for handling the response SOAP message. An ordered group of handlers is referred to as a handler chain. You specify that a Web service has a handler chain attached to it with one of two JWS annotations: HandlerChain or SOAPMessageHandler . When to use which is discussed in a later section. When invoking a Web service, WebLogic Server executes handlers as follows: 1. The handleRequest methods of the handlers in the handler chain are all executed in the order specified by the JWS annotation. Any of these handleRequest methods might change the SOAP message request. 2. When the handleRequest method of the last handler in the handler chain executes, WebLogic Server invokes the back-end component that implements the Web service, passing it the final SOAP message request. 3. When the back-end component has finished executing, the handleResponse methods of the handlers in the handler chain are executed in the reverse order specified in by the JWS annotation. Any of these handleResponse methods might change the SOAP message response. 4. When the handleResponse method of the first handler in the handler chain executes, WebLogic Server returns the final SOAP message response to the client application that invoked the Web service. For example, assume that you are going to use the HandlerChain JWS annotation in your JWS file to specify an external configuration file, and the configuration file defines a handler chain called SimpleChain that contains three handlers, as shown in the following sample: jwshc:handler-config xmlns:jwshc=http:www.bea.comxmlnsjws xmlns:soap1=http:HandlerInfo.orgServer1 xmlns:soap2=http:HandlerInfo.orgServer2 xmlns=http:java.sun.comxmlnsj2ee jwshc:handler-chain jwshc:handler-chain-nameSimpleChainjwshc:handler-chain-name jwshc:handler handler-namehandlerOnehandler-name handler-classexamples.webservices.soap_handlers.global_ handler.ServerHandler1handler-class jwshc:handler jwshc:handler handler-namehandlerTwohandler-name handler-classexamples.webservices.soap_handlers.global_ handler.ServerHandler2handler-class jwshc:handler jwshc:handler handler-namehandlerThreehandler-name handler-classexamples.webservices.soap_handlers.global_ handler.ServerHandler3handler-class Creating and Using SOAP Message Handlers 9-5 jwshc:handler jwshc:handler-chain jwshc:handler-config The following graphic shows the order in which WebLogic Server executes the handleRequest and handleResponse methods of each handler. Figure 9–1 Order of Execution of Handler Methods Each SOAP message handler has a separate method to process the request and response SOAP message because the same type of processing typically must happen for the inbound and outbound message. For example, you might design an Encryption handler whose handleRequest method decrypts secure data in the SOAP request and handleResponse method encrypts the SOAP response. You can, however, design a handler that process only the SOAP request and does no equivalent processing of the response. You can also choose not to invoke the next handler in the handler chain and send an immediate response to the client application at any point.

9.4 Creating the GenericHandler Class