A Chain is a Chain of Handler. That is to say, multiple Handler may be executed in one request.
1. Let's write a Handler to execute it using the chain method.
Code
Package com. hoo. service. chain;
Import org. apache. axis. SimpleChain;
Import com. hoo. service. handler. RequestHandler;
Import com. hoo. service. handler. ResponseHandler;
/**
* <B> function: </B> use chain to call multiple handler
* @ Author hoojo
* @ CreateDate Dec 15,201 0 11:25:27
* @ File HandlerChain. java
* @ Package com. hoo. service. chain
* @ Project AxisWebService
* @ Blog http://blog.csdn.net/IBM_hoojo
* @ Email hoojo_@126.com
* @ Version 1.0
*/
Public class HandlerChain extends SimpleChain {
Private static final long serialVersionUID = 1226192132055911394l;
Public HandlerChain (){
RequestHandler request = new RequestHandler ();
ResponseHandler response = new ResponseHandler ();
This. addHandler (request );
This. addHandler (response );
}
}
The preceding HandlerChain inherits SimpleChain, creates RequestHandler and ResponseHandler In the constructor, and adds them to the chain handler with addHandler. In particular, the chain here is actually a handler. Why? The SimpleChain we inherit inherits the abstract class BsaicHandler, So chain is also a handler. Some people think that the configuration of handler should be similar to that of handler, but the configuration of chain can reference the configuration of handler.
2. Configure the wsdd file of the chain
First look at the configuration method 1:
Code
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<chain name="HandlerChain">
</chain>
<service name="HelloWorldWSDDHandlerChain" provider="java:RPC">
<requestFlow>
<chain type="HandlerChain"/>
</requestFlow>
<parameter name="className" value="com.hoo.service.HelloWorldWSDD" />
<parameter name="allowedMethods" value="*" />
<parameter name="scope" value="request" />
</service>
</deployment>
A handler label is configured in the chain element. The type of the label is the classpath class path. Then, configure the chain element label in the requestFlow label and reference the chain with the type.
Configuration method 2:
Code
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<chain name="handlerChain">
</chain>
<service name="HelloWorldWSDDHandlerChain2" provider="java:RPC">
<parameter name="className" value="com.hoo.service.HelloWorldWSDD" />
<parameter name="allowedMethods" value="*" />
<parameter name="scope" value="request" />
<responseFlow>
<chain type="handlerChain"/>
</responseFlow>
</service>
</deployment>
The handler is configured first. As mentioned earlier, chain is also a special handler. Therefore, use the handler label to configure the chain, and then use the type of handler to reference the hchain in the chain label. It is best to use the chain to reference the configured chain in the responseFlow label.
Note: Only the handler and chain elements can be configured in the chain tag, and the chain can be nested in the chain;
3. Publish the WebService with the wsdd configured chain
Java-Djava. ext. dirs = lib org. apache. axis. client. AdminClient-lhttp: // localhost: 8080/AxisWebService/services/AdminService deployChain. wsdd
Request in the browser: http: // localhost: 8080/AxisWebService/servlet/AxisServlet
You can see the published service.
4. Write the client code and request the WebService just released. The client code is almost referenced by the preceding HelloWorldWSDDClient, but the requested service can be changed to the service path we just released. After running, the console on the server has the following effects:
State: null, count: 1, requestCount: 1
State: null, count: 1, RESPONSE_COUNT: 1
State: null, count: 2, requestCount: 2
State: null, count: 2, RESPONSE_COUNT: 2