Axis2中使用模块2011-06-21zhangjunhd1.模块Axis2为模块提供一个延伸的支持。我们现在自定义一个模块并将其部署到我 们先前创建的MyService。为一个给定的Web Service部署一个自定义的模块,其 步骤如下:1)建立Module Implementation。2)创建Handlers。3)修改"axis2.xml"。4)修改"services.xml",使你的模块在部署期生效。5)将其打包为一个".mar"(Module Archive)。6)在Axis2上部署这个模块。2.为MyService增加一个日志模块现在我们在我们的例子程序中增加一个日志模块。这个模块包含一个handle ,用来记录所有传递给它的信息。Axis2使用". mar" (Module Archive)来部署 模块。下图给出了需要被打包为".mar"文档的文件结构。

步骤一:日志模块类日志模块是Axis2模块的实现类。Axis2模块应该实 现"org.apache.axis2.modules.Module"接口中的如下方法。
public void init(ConfigurationContext configContext, AxisModule module)
throws AxisFault;//Initialize the module
public void shutdown(AxisConfiguration axisSystem)
throws AxisFault;//End of module processing
public void engageNotify(AxisDescription axisDescription) throws AxisFault;这些方法可以用来控制模块的初始化和终止。通过参数AxisConfiguration, 可提供给用户完整的配置层次。模块设计者可以使用它来很好的控制模块的所有 可能的操作。就这个简单的日志服务的例子而言,我们可以空实现这些类。LoggingModule.java
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;
public class LoggingModule implements Module {
// initialize the module
public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {}
public void engageNotify(AxisDescription axisDescription) throws AxisFault {}
// shutdown the module
public void shutdown(ConfigurationContext configurationContext) throws AxisFault {}
public String[] getPolicyNamespaces() {
return null;
}
}