Example: Configuring handler classes for web services deployment descriptors
This scenario explains how to add a client and server handler class to a sample application, WebServicesSamples.ear. The handler classes display messages when given a request or response to handle.
The code for the client handler class is illustrated in the following example:
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 illustrated in the following example:
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; } }
- Compile these classes using:
(Windows) %JAVA_HOME%\bin\java -extdirs %WAS_EXT_DIRS% ClientHandler.java ServerHandler.java
(Linux) (AIX) (HPUX) (Solaris) $JAVA_HOME/bin/java -extdirs $WAS_EXT_DIRS ClientHandler.java ServerHandler.java
- Open an assembly tool and import the two sample EAR files:
- (Windows) ...\installableApps\WebServicesSamples.ear
(Linux) (AIX) (HPUX) (Solaris) .../installableApps/WebServicesSamples.ear
- (Windows) ...\installableApps\ApplicationClients.ear
(Linux) (AIX) (HPUX) (Solaris) .../installableApps/ApplicationClients.ear
- Import the compiled handler classes into the projects for the sample modules:
- Import sample.ClientHandler into the appClientModule directory of the AddressBookClient project.
- Import sample.ServerHandler into the ejbModule directory of the AddressBookW2JE project.
- Configure the client deployment descriptor for handler classes.
This topic explains how to configure the client deployment descriptor for user-provided handler classes.
- Configure the webservices.xml deployment descriptor for handler classes.
This topic explains how to configure the webservices.xml deployment descriptor for user-provided handler classes.
- Save changes and export the EAR files.
- Uninstall the WebServicesSamples.ear application from the server if it is already installed.
- Install the new WebServicesSamples.ear application.
- Start the server.
- Run the client:
launchClient ApplicationClients.ear -CCjar=AddressBookClient.jar
When the client runs, the console output looks like the following example. The messages from the handlers are shown in bold.
IBM WAS 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 >>Query 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 >>Query 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 >>Query 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 >>Query 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-4900For 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 the following data:
[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
The deployment descriptors for handler classes are configured. Deployment descriptors are required so that so that WebSphere Application Server can process the incoming web services requests.
What to do next
Deploy the EAR file configured and enabled for web services. Then we can test the application to make sure it runs within the WAS environment.
Configure the JAX-RPC client deployment descriptor for handler classes Configure the webservices.xml deployment descriptor for handler classes Samples, v8.5