Processing Request/Response Messages of a Web Service Using Handler Chain
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.
BalanceEnquiryService.java
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:
- 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.
- 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.
- 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.
<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>
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-service.xml
<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".
0 Comments (click to add your comment)
Networking Solutions



Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.