1.自定义Valve类
public class MyValve extends AbstractValve
{
public void invoke(PipelineContext context) throws Exception
{
System.out.println("this is my valve : stated");
context.invokeNext();
System.out.println("this is my valve : ended");
}
} (1)继承AbstractValve类也可以实现Valve接口,效果一样
public abstract class AbstractValve extends BeanSupport implements Valve {
} (2)实现invoke方法注意:和filter一样,需要调用下一个valve。使用invokeNext()方法
2.在pipeline.xml中配置
<services:pipeline xmlns="http://www.alibaba.com/schema/services/pipeline/valves">
<!-- 初始化turbine rundata,并在pipelineContext中设置可能会用到的对象(如rundata、utils),以便valve取得。 -->
<prepareForTurbine />
.......
<valve class="com.alibaba.webx.tutorial1.app1.value.MyValve"/>
.......
</services:pipeline>
本文介绍了如何通过继承AbstractValve类来自定义Tomcat的Valve组件,包括具体实现及在pipeline.xml中的配置方法。
4701

被折叠的 条评论
为什么被折叠?



