October 26, 2016
Hot Topics:

Processing Request/Response Messages of a Web Service Using Handler Chain

  • May 10, 2005
  • By Nandhini Arumugam & Jeyarani Venkatasamy
  • Send Email »
  • More Articles »

The following is the code for the Balance Enquiry service. It is a very simple service that returns the balance amount of the given account number.


public class BalanceEnquiryService{   public float getBalance(String accountNo)   {      if(accountNo.equals("12345"))         return 5000f;      else         return 100f;   }}

The web-service.xml of the Web Service is to be modified to include the handler chain details. The following are the changes to be done in web-services.xml:

  1. Create a <handler-chains> child element of the <web-services> root element that will contain a list of all handler chains defined for the Web service.
  2. Create a <handler-chain> child element of the <handler-chains> element; within this element, list all the handlers in the handler chain. For each handler, use the class-name attribute to specify the fully qualified name of the Java class that implements the handler. Use the <init-params> element to specify any initialization parameters of the handler.
  3. <handler-chains>   <handler-chain name="myChain">      <handler class-name="myHandlers.handlerOne" />      <handler class-name="myHandlers.handlerTwo" />      <handler class-name="myHandlers.handlerThree" />   </handler-chain></handler-chains>
  4. Use the <operation> child element of the <operations> element (which itself is a child of the <web-service> element) to specify that the handler chain is an operation of the Web Service.
Note: The handler chain executes on its own, without a backend component. In this case, use only the handler-chain attribute of the <operation> element and explicitly do not specify the component or method attributes, as shown in the following excerpt:

<web-service>   <operations>      <operation name="chainService"                 handler-chain="myChain" />   </operations></web-service>

Here is the web-service.xml for the example.


<web-services xmlns:xsd="http://www.w3.org/2001/XMLSchema">   <handler-chains>      <handler-chain name="AuthenticationHandlerChain">         <handler class-name="AuthenticationHandler" />      </handler-chain>   </handler-chains>   <web-service name="BalanceEnquiryService"                uri="/BalanceEnquiryService"                targetNamespace="http://www.bea.com">      <components>         <java-class name="jccomp0"                     class-name="BalanceEnquiryService">         </java-class>      </components>      <operations>         <operation method="getBalance"                    handler-chain="AuthenticationHandlerChain"                    component="jccomp0">            <params>               <param name="param0" class-name="java.lang.String"                                    style="in" type="xsd:string" />               <return-param name="result"                             class-name="java.lang.Float"                                           type="xsd:float" />            </params>         </operation>      </operations>   </web-service></web-services>

Here, the handler-chain is named AuthenticationHandlerChain, which contains a handler AuthenticationHandler. Note that the operation includes the attribute handler-chain="AuthenticationHandlerChain".

Page 2 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel