自己配置Axis2 Module的方法

步骤:
1.首先要写一个Module的实现类
这里我写了一个和官网上的不太一样,但也差不多

Loggingmodule代码

package userguide.loggingmodule;  

import org.apache.axis2.AxisFault;  
import org.apache.axis2.context.ConfigurationContext;  
import org.apache.axis2.description.AxisDescription;  
import org.apache.axis2.description.AxisModule;  
import org.apache.axis2.modules.Module;  
import org.apache.neethi.Assertion;  

/**  
 *   
 * @author cnchenhl  
 * Jun 15, 2011  
 */  
public class LoggingModule implements Module {  
    /**  
     * Initialize the module  
     */  
    public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {  
    }  

    /**  
     * End of module processing  
     */  
    public void shutdown(ConfigurationContext configurationContext) throws AxisFault {  
    }  

    public void engageNotify(AxisDescription axisDescription) throws AxisFault {  
    }  

    public boolean canSupportAssertion(Assertion assertion) {  
        return false;  
    }  

    @Override  
    public void applyPolicy(org.apache.neethi.Policy arg0, AxisDescription arg1) throws AxisFault {  

    }  
} 

2.然后就是也Hander,我们也实现它
Loghandler代码

package userguide.loggingmodule;  

import org.apache.axis2.AxisFault;  
import org.apache.axis2.context.MessageContext;  
import org.apache.axis2.engine.Handler;  
import org.apache.axis2.handlers.AbstractHandler;  
import org.apache.commons.logging.Log;  
import org.apache.commons.logging.LogFactory;  

/**  
 *   
 * @author cnchenhl  
 * Jun 15, 2011  
 */  
public class LogHandler extends AbstractHandler implements Handler {  

    private static final Log log = LogFactory.getLog(LogHandler.class);  
    private String name;  

    public String getName() {  
        return name;  
    }  

    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {  
        log.info(msgContext.getEnvelope().toString());  
        return InvocationResponse.CONTINUE;  
    }  

    public void revoke(MessageContext msgContext) {  
        log.info(msgContext.getEnvelope().toString());  
    }  

    public void setName(String name) {  
        this.name = name;  
    }  

}  

3.下面做module.xml
Xml代码

<module name="logging" class="userguide.loggingmodule.LoggingModule">  
   <InFlow>  
        <handler name="InFlowLogHandler" class="userguide.loggingmodule.LogHandler">  
        <order phase="loggingPhase" />  
        </handler>  
   </InFlow>  

   <OutFlow>  
        <handler name="OutFlowLogHandler" class="userguide.loggingmodule.LogHandler">  
        <order phase="loggingPhase"/>  
        </handler>  
   </OutFlow>  

   <OutFaultFlow>  
        <handler name="FaultOutFlowLogHandler" class="userguide.loggingmodule.LogHandler">  
        <order phase="loggingPhase"/>  
        </handler>  
   </OutFaultFlow>  

   <InFaultFlow>  
        <handler name="FaultInFlowLogHandler" class="userguide.loggingmodule.LogHandler">  
        <order phase="loggingPhase"/>  
        </handler>  
   </InFaultFlow>  
</module> 

4.修改axis2.xml
Java代码 收藏代码

<phaseOrder type="InFlow">  
        <phase name="loggingPhase"/>  
<phaseOrder type="OutFlow">  
        <phase name="loggingPhase"/>  
........  

5.修改service.xml
加上<module ref="logging"/>
6.打包
基本的将上面的类编译成class,然后将module.xml放到META-INF下面 打包成jar,然后改后缀名为mar
7.发布
嘿嘿这个发布很简单,放到module文件夹下即可。

参照原文:http://chenhailong.iteye.com/blog/1090619

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值