Configure Handler classes for Web services deployment descriptors

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;  }
}

  1. Compile these classes using

    %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)

  2. Open the Assembly Toolkit and import the two sample EAR files:

    • %WAS_HOME%\samples\lib\WebServicesSamples\WebServicesSamples.ear on Windows or $WAS_HOME/samples/lib/WebServicesSamples/WebServicesSamples.ear on Unix.

    • %WAS_HOME%\samples\lib\WebServicesSamples\ApplicationClients.ear on Windows or $WAS_HOME/samples/lib/WebServicesSamples/ApplicationClients.ear on Unix..

  3. 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.

  4. Configure the webservicesclient.xml deployment descriptor for Handler classes.

  5. Configure the webservices.xml deployment descriptor for Handler classes.

  6. Save your changes and export the EAR files.

  7. Uninstall the WebServicesSamples.ear application from your server if it is already installed.

  8. Install the new WebServicesSamples.ear application.

  9. Start the server.

  10. Run the client:

    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 WAS, Release 5.1
        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.

 

See Also

Configuring the webservicesclient.xml deployment descriptor for Handler classes
Configuring the webservices.xml deployment descriptor for Handler classes