今天做了一个Axis2 Module的例子(官网介绍),感觉很简单,但也很实用这里和大家分享一下
步骤:
1.首先要写一个Module的实现类
这里我写了一个和官网上的不太一样,但也差不多
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,我们也实现它
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
<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
<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文件夹下即可。
好了以上就是开发过程
有什么问题给我留言