This scenario explains how to add trivial client and server Handler classes to a sample application named WebServicesSamples.ear. The Handler classes display messages when given a request or response to handle.
The code for the client Handler class is:
package samples; public class ClientHandler implements javax.xml.rpc.handler.Handler { public ClientHandler() { } public boolean handleRequest(javax.xml.rpc.handler.MessageContext context) { System.out.println("ClientHandler: In handleRequest"); return true; } public boolean handleResponse(javax.xml.rpc.handler.MessageContext context) { System.out.println("ClientHandler: In handleResponse"); return true; } public boolean handleFault(javax.xml.rpc.handler.MessageContext context) { System.out.println("ClientHandler: In handleFault"); return true; } public void init(javax.xml.rpc.handler.HandlerInfo config) { } public void destroy() { } public javax.xml.namespace.QName[] getHeaders() { return null; } }
The code for the server Handler class is:
package sample; public class ServerHandler implements javax.xml.rpc.handler.Handler { public ServerHandler() { } public boolean handleRequest(javax.xml.rpc.handler.MessageContext context) { System.out.println("ServerHandler: In handleRequest"); return true; } public boolean handleResponse(javax.xml.rpc.handler.MessageContext context) { System.out.println("ServerHandler: In handleResponse"); return true; } public boolean handleFault(javax.xml.rpc.handler.MessageContext context) { System.out.println("ServerHandler: In handleFault"); return true; } public void init(javax.xml.rpc.handler.HandlerInfo config) { } public void destroy() { } public javax.xml.namespace.QName[] getHeaders() { return null; } }
%JAVA_HOME%\bin\java -extdirs %WAS_EXT_DIRS% ClientHandler.java ServerHandler.java (on Windows)
$JAVA_HOME/bin/java -extdirs $WAS_EXT_DIRS ClientHandler.java ServerHandler.java (on Unix)
launchClient ApplicationClients.ear -CCjar=AddressBookClient.jar
When the client executes, the console output is as shown below. The messages from the handlers are shown in bold.
IBM WebSphere Application Server J2EE Application Client Tool Copyright IBM Corp., 1997-2003 WSCL0012I: Processing command line arguments. WSCL0013I: Initializing the J2EE Application Client Environment. WSCL0035I: Initialization of the J2EE Application Client Environment has completed. WSCL0014I: Invoking the Application Client class com.ibm.websphere.samples.webservices.addr.AddressBookClient >> Querying address for 'Purdue Boilermaker' using port AddressBookW2JE ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 1 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900 >> Querying address for 'Purdue Boilermaker' using port AddressBookJ2WE ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 2 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900 >> Querying address for 'Purdue Boilermaker' using port AddressBookJ2WB ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 3 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900 >> Querying address for 'Purdue Boilermaker' using port AddressBookW2JB ClientHandler: In handleRequest ClientHandler: In handleResponse >> Response is: 4 University Drive West Lafayette, IN 47907 Phone: (765) 555-4900
For the client, the Handler class is configured for each service reference, not for each port. The AddressBook sample has four ports, but only one service reference, therefore the ClientHandler handles requests and responses on all ports.
When the server log file is examined, it contains:
[9/24/03 16:39:22:661 CDT] 4deec1c6 WebGroup I SRVE0180I: [HTTP router for AddressBookW2JE.jar] [/AddressBookW2JE] [Servlet.LOG]: AddressBook: init [9/24/03 16:39:23:161 CDT] 4deec1c6 SystemOut O ServerHandler: In handleRequest [9/24/03 16:39:23:211 CDT] 4deec1c6 SystemOut O ServerHandler: In handleResponse
What to do next
Install and test the application.