Axis2可以通过模块(Module)进行扩展。Axis2模块至少需要有两个类,这两个类分别实现了Module和Handler接口。开发和使用一个Axis2模块的步骤如下:
1. 编写实现Module接口的类。Axis2模块在进行初始化、销毁等动作时会调用该类中相应的方法)。
2. 编写实现Handler接口的类。该类是Axis2模块的业务处理类。
3. 编写module.xml文件。该文件放在META-INF目录中,用于配置Axis2模块。
4. 在axis2.xml文件中配置Axis2模块。
5. 在services.xml文件中配置Axis2模块。每一个Axis2模块都需要使用<module>元素引用才能使用。
6. 发布Axis2模块。需要使用jar命令将Axis2模块压缩成.mar包(文件扩展名必须是.mar),然后将.mar文件放在
<Tomcat安装目录>\webapps\axis2\WEB-INF\modules目录中。
先来编写一个WebService类,代码如下:
package service;
public class MyService
{
public String getGreeting(String name)
{
return "您好 " + name;
}
}
package service;
public class MyService
{
public String getGreeting(String name)
{
return "您好 " + name;
}
}
下面我们来编写一个记录请求和响应SOAP消息的Axis2模块。当客户端调用WebService方法时,该Axis2模块会将请求和响应SOAP消息输出到Tomcat控制台上。
第1步:编写LoggingModule类
LoggingModule类实现了Module接口,代码如下:
package module;
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;
import org.apache.neethi.Policy;
public class LoggingModule implements Module
{
// initialize the module
public void init(ConfigurationContext configContext, AxisModule module)
throws AxisFault
{
System.out.println("init");
}
public void engageNotify(AxisDescription axisDescription) throws AxisFault
{
}
// shutdown the module
public void shutdown(ConfigurationContext configurationContext)
throws AxisFault
{
System.out.println("shutdown");
}
public String[] getPolicyNamespaces()
{
return null;
}
public void applyPolicy(Policy policy, AxisDescription axisDescription)
throws AxisFault
{
}
public boolean canSupportAssertion(Assertion assertion)
{
return true;
}
}
package module;
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;
import org.apache.neethi.Policy;
public class LoggingModule implements Module
{
// initialize the module
public void init(ConfigurationContext configContext, AxisModule module)
throws AxisFault
{
System.out.println("init");
}
public void engageNotify(AxisDescription axisDescription) throws AxisFault
{
}
// shutdown the module
public void shutdown(ConfigurationContext configurationContext)
throws AxisFault
{
System.out.println("shutdown");
}
public String[] getPolicyNamespaces()
{
return null;
}
public void applyPolicy(Policy policy, AxisDescription axisDescription)
throws AxisFault
{
}
public boolean canSupportAssertion(Assertion assertion)
{
return true;
}
}
在本例中LoggingModule类并没实现实际的功能,但该类必须存在。当Tomcat启动时会装载该Axis2模块,同时会调用LoggingModule类的init方法,并在Tomcat控制台中输出“init”。
第2步:编写LogHandler类
LogHandler类实现了Handler接口,代码如下:
package module;
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;
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
{
// 向Tomcat控制台输出请求和响应SOAP消息
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;
}
}
package module;
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;
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
{
// 向Tomcat控制台输出请求和响应SOAP消息
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;
}
}
LogHandler类的核心方法是invoke,当使用该Axis2模块的WebService的方法被调用时,LogHandler类的invoke方法被调用。
第3步:编写module.xml文件
在META-INF目录中建立一个module.xml文件,内容如下:
<module name="logging" class="module.LoggingModule">
<InFlow>
<handler name="InFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</InFlow>
<OutFlow>
<handler name="OutFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFlow>
<OutFaultFlow>
<handler name="FaultOutFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFaultFlow>
<InFaultFlow>
<handler name="FaultInFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</InFaultFlow>
</module>
<module name="logging" class="module.LoggingModule">
<InFlow>
<handler name="InFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</InFlow>
<OutFlow>
<handler name="OutFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFlow>
<OutFaultFlow>
<handler name="FaultOutFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFaultFlow>
<InFaultFlow>
<handler name="FaultInFlowLogHandler" class="module.LogHandler">
<order phase="loggingPhase"/>
</handler>
</InFaultFlow>
</module>
第4步:在axis2.xml文件中配置Axis2模块
打开axis2.xml文件,分别在如下四个<phaseOrder>元素中加入<phase name="loggingPhase"/>:
<phaseOrder type="InFlow">
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="OutFlow">
<phase name="Security"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="InFaultFlow">
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="OutFaultFlow">
<phase name="Security"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="InFlow">
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="OutFlow">
<phase name="Security"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="InFaultFlow">
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/>
</phaseOrder>
<phaseOrder type="OutFaultFlow">
<phase name="Security"/>
<phase name="loggingPhase"/>
</phaseOrder>
第5步:在services.xml文件中引用logging模块
services.xml文件的内容如下:
<service name="myService">
<description>
使用logging模块
</description>
<!-- 引用logging模块 -->
<module ref="logging"/>
<parameter name="ServiceClass">
service.MyService
</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
<service name="myService">
<description>
使用logging模块
</description>
<!-- 引用logging模块 -->
<module ref="logging"/>
<parameter name="ServiceClass">
service.MyService
</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
第6步:发布logging模块
到现在为止,我们应用可以建立两个发行包:logging.mar和service.aar。其中logging.mar文件是Axis2模块的发行包,该包的目录结构如下:
logging.mar
module\LoggingModule.class
module\LogHandler.class
META-INF\module.xml
service.aar文件是本例编写的WebService发行包,该包的目录结构如下:
service.aar
service\MyService.class
META-INF\services.xml
将logging.mar文件放在<Tomcat安装目录>\webapps\axis2\WEB-INF\modules目录中,将service.aar文件放在<Tomcat安装目录>\webapps\axis2\WEB-INF\services目录中。要注意的是,如果modules目录中包含了modules.list文件,Axis2会只装载在该文件中引用的Axis2模块,因此,必须在该文件中引用logging模块,该文件的内容如下:
addressing-1.4.1.mar
soapmonitor-1.4.1.mar
ping-1.4.1.mar
mex-1.4.1.mar
axis2-scripting-1.4.1.mar
logging.mar
如果modules目录中不包含modules.list文件,则Axis2会装载modules文件中的所有Axis2模块。
现在启动Tomcat,使用如下的C#代码调用MyService的getGreeting方法则会在Tomcat控制台中输出相应的请求和响应SOAP消息。
// async是引用MyService的服务名
async.myService my = new WSC.asyn.myService();
MessageBox.Show(my.getGreeting("中国"));
MessageBox.Show("完成调用");
在执行上面的代码后,在Tomcat控制台中输出的信息
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/crazystone4/archive/2009/06/20/4285761.aspx
分享到:
相关推荐
总结来说,"axis2-eclipse-codegen-plugin-1.6.2"和"axis2-eclipse-service-plugin-1.6.2"是针对Apache Axis2的Eclipse插件,旨在简化基于Axis2的Web服务开发。通过它们,开发者可以高效地生成和部署服务,同时享受...
plugin-1.7.9.zip_axis2_axis2-idea-plugin_idea导入axis2_"提到了几个关键元素,分别是"axis2"、"idea-plugin"和"idea导入axis2",这暗示了这个压缩包是用于在IntelliJ IDEA这款集成开发环境(IDE)中支持Axis2服务...
标题中的"axis2-eclipse-codegen-plugin-1.6.2.zip"和"axis2-eclipse-service-plugin-1.6.2.zip"是两个与Apache Axis2相关的Eclipse插件,用于简化Web服务的开发过程。Apache Axis2是Java平台上一个成熟的Web服务...
Apache Axis2是Apache软件基金会开发的一个SOAP(简单对象访问协议)引擎,它是一个完整的Web服务框架。该框架提供了一种高效、灵活的方式来创建和部署Web服务。Axis2的核心功能包括: 1. **SOAP处理**:Axis2能够...
基于AXIS2实现Web Service开发是一项常见的任务,尤其在企业级应用中,Web Service作为不同系统间通信的重要桥梁。AXIS2是Apache软件基金会提供的一个轻量级、高性能的Web Service框架,它提供了完整的Web Service...
共四个文件,都是最先版的,希望可以帮助大家。axis2-eclipse-service-archiver-wizard和axis2-eclipse-codegen-wizard和axis2-1.6.1-bin和axis2-1.6.1-war
目前axis2最高版本是2.0以上的版本,但是eclipse和myeclipse都不支持,无奈只能使用低版本的插件1.6.3;经实验,可以安装成功;...axis2-eclipse-service-plugin-1.6.3.zip axis2-eclipse-codegen-plugin-1.6.3.zip
Axis2是Apache软件基金会开发的一个开放源代码Web服务框架,它提供了一种高效、灵活的方式来创建和部署Web服务。该插件的版本号1.7.8表明这可能是其稳定且功能丰富的迭代之一。 首先,让我们详细了解一下Axis2。...
axis2-eclipse-service-archiver-wizard.zip
`axis2-1.5.1-bin.zip`是Axis2的二进制包,它包含了运行和开发Web服务所需的所有基本组件。这个包通常用于本地开发环境或者在服务器上进行手动安装。其中包含的主要文件和目录有: 1. `bin`目录:包含启动和管理...
Eclipse Codegen Plugin 和 Service Plugin 是Axis2为Eclipse集成开发环境提供的两个重要工具,它们极大地简化了基于Axis2的Web服务开发过程。 **Apache Axis2 Eclipse Codegen Plugin** 这个插件主要用于自动生成...
标题中的"axis2-eclipse-service-plugin-1.7.4.zip"指的是Axis2 Eclipse服务插件的1.7.4版本的归档文件,它是一个专门为Eclipse集成开发环境(IDE)设计的扩展。这个插件允许开发者在Eclipse中方便地创建、部署和...
【用Axis2开发Web Service】是本文的核心主题,轴心技术是Java开发Web服务的一种框架,相较于Axis1,其过程更为简洁。以下是关于使用Axis2开发Web Service的详细步骤和知识点: 1. **实验环境搭建**: - 首先确保...
"axis2"代表它与Apache Axis2紧密关联,“eclipse”表明它是为Eclipse IDE设计的,“service plugin”则意味着它的主要功能是关于Web服务的开发和管理。 在压缩包子文件的“plugins”目录下,通常会包含以下内容: ...
### Axis开发Web Service实例详解 #### 一、概述 在探讨如何使用Apache Axis来开发Web Service之前,我们首先需要了解一些基本概念。 **Web Service**是一种标准的技术框架,用于实现不同平台之间的应用通信。它...
Axis2是Apache软件基金会开发的一款Java Web服务框架,主要用于构建和部署Web服务。在Web服务领域,Axis2扮演着核心的角色,它提供了丰富的功能来支持服务导向架构(SOA)。标题中的"axis2-1.6.2.zip"指的是Axis2的...
【Axis2 Web Service 开发教程】是一份详细指导开发者如何使用Apache Axis2框架创建和部署Web服务的教学资料。Apache Axis2是Java世界中一个强大的Web服务引擎,它提供了高效的性能和灵活的架构,使得Web服务的开发...
标题“axis2-1.6.1”指的是Apache Axis2的1.6.1版本,这是一个流行的开源Web服务引擎,用于构建和部署Web服务。Apache Axis2是Axis1的下一代,设计为更灵活、可扩展且高效。在这个版本中,它提供了一系列改进和新...
Axis2 是一个强大的 Web Service 框架,它是由 Apache 软件基金会开发的,主要用于构建和部署 Web 服务。版本 1.5.6 是 Axis2 的一个稳定版本,提供了一系列增强的功能和修复了若干已知问题,使得在 SAP 中进行 Web ...
【标题】:Axis2与Eclipse整合开发的Web Service服务端详解 【描述】:本文将详细介绍如何在Eclipse环境中利用Axis2框架开发一个Web Service服务端,包括计算器服务CalculateService的实现步骤。 【标签】:Axis2,...