Creating and Using SOAP Message Handlers 9-19
9.8.2 Example of a Client-Side Handler Class
The following example shows a simple SOAP message handler class that you can configure for a client application that invokes a Web service.
package examples.webservices.client_handler.client; import javax.xml.namespace.QName;
import javax.xml.rpc.handler.HandlerInfo; import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.MessageContext;
public class ClientHandler1 extends GenericHandler { private QName[] headers;
public void initHandlerInfo hi { System.out.printlnin + this.getClass + init;
}
public boolean handleRequestMessageContext context { System.out.printlnin + this.getClass + handleRequest;
return true; }
public boolean handleResponseMessageContext context { System.out.printlnin + this.getClass + handleResponse;
return true; }
public boolean handleFaultMessageContext context { System.out.printlnin + this.getClass + handleFault;
return true; }
public QName[] getHeaders { return headers;
} }
9.8.3 Creating the Client-Side SOAP Handler Configuration File
The client-side SOAP handler configuration file specifies the list of handlers in the handler chain, the order in which they execute, the initialization parameters, and so
on. See Section 9.8.4, XML Schema for the Client-Side Handler Configuration File
for a full description of this file.
The configuration file uses XML to describe a single handler chain that contains one or more handlers, as shown in the following simple example:
weblogic-wsee-clientHandlerChain xmlns=http:www.bea.comnsweblogic90
xmlns:xsi=http:www.w3.org2001XMLSchema-instance
Note: You do not have to update your actual client application to
invoke the client-side SOAP message handlers; as long as you specify to the clientgen Ant task the handler configuration file, the
generated JAX-RPC stubs automatically take care of executing the handlers in the correct sequence.
9-20 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server
xmlns:j2ee=http:java.sun.comxmlnsj2ee handler
j2ee:handler-nameclienthandler1j2ee:handler-name j2ee:handler-classexamples.webservices.client_
handler.client.ClientHandler1j2ee:handler-class j2ee:init-param
j2ee:param-nameClientParam1j2ee:param-name j2ee:param-valuevalue1j2ee:param-value
j2ee:init-param handler
handler j2ee:handler-nameclienthandler2j2ee:handler-name
j2ee:handler-classexamples.webservices.client_ handler.client.ClientHandler2j2ee:handler-class
handler
weblogic-wsee-clientHandlerChain In the example, the handler chain contains two handlers: clienthandler1 and
clienthandler2 , implemented with the class names specified with the
j2ee:handler-class element. The two handlers execute in forward order
directly before the client application sends the SOAP request to the Web service, and then in reverse order directly after the client application receives the SOAP response
from the Web service.
The example also shows how to use the j2ee:init-param element to specify one or more initialization parameters to a handler.
Use the soap-role, soap-header, and port-name child elements of the handler
element to specify the SOAP roles implemented by the handler, the SOAP headers processed by the handler, and the port-name element in the WSDL with
which the handler is associated with, respectively.
9.8.4 XML Schema for the Client-Side Handler Configuration File