Example: Configure handler classes for Web services deployment descriptors

 

+

Search Tips   |   Advanced Search

 

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

  1. Compile these classes using

    Windows systems)

    %JAVA_HOME%\bin\java -extdirs %WAS_EXT_DIRS% ClientHandler.java ServerHandler.java

  2. Open an assembly tool and import the two sample enterprise archive (EAR) files:

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

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

  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 client deployment descriptor for handler classes.

    This topic explains how to configure the client deployment descriptor for user-provided handler classes.

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

  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 runs, the console output looks like the following example. 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 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

 

Results

The deployment descriptors for handler classes are configured. Deployment descriptors are required so that so that WAS can process the incoming Web services requests.

 

What to do next

Deploy the EAR file that has been configured and enabled for Web services. Then one can test the application to make sure it runs within the WAS environment.


 

Related Tasks

Configure the client deployment descriptor for handler classes with an assembly tool
Configure the webservices.xml deployment descriptor for handler classes