`

利用axis2将SSH项目发布成Web Service

    博客分类:
  • SOA
阅读更多
1. 开发环境
eclipse,axis2 war,SSH项目
axis2 的eclipse插件:
axis2-eclipse-codegen-wizard.zip 用于生成stub本地代码
axis2-eclipse-service-archiver-wizard.zip 用于发布web service
2. 安装过程
1.下载完2个插件的压缩文件后,可以直接把解压后的文件拷贝到eclipse 的 plugins目录中
从axis2 bin 包里找到:backport-util-concurrent-3.1.jar 和 geronimo-stax-api_1.0_spec-1.0.1.jar
复制到 eclipse\plugins\Axis2_Codegen_Wizard_1.3.0\lib 文件夹下。
backport-util-concurrent-3.1.jar 需要在网上download site:http://www.findjar.com/jar/mule/dependencies/maven2/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar.html
2.修改eclipse\plugins\Axis2_Codegen_Wizard_1.3.0\plugin.xml 文件
  在 <runtime> 內加入下面的字串
    <library name="lib/geronimo-stax-api_1.0_spec-1.0.1.jar">
       <export name="*"/>
    </library>
    <library name="lib/backport-util-concurrent-3.1.jar">
        <export name="*"/>
    </library>
3.把Axis2_Codegen_wizard_1.3.0(eclipse/plugins/Axis2_Codegen_wizard_1.3.0)的名字改成Axis2_Codegen_wizard_1.4.0
  在plugin.xml中在<plugin>中 把Axis2_Codegen_wizard的version="1.3.0"改成version="1.4.0"
到plugin.xml文件中,保存后重新启动Eclipse即可
3. 开发过程
1.在spring的配置文件里加入:
<bean id= "applicationContext"class ="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"  />
2.在axis2容器里的web.xml加入如下代码,用于加载spring的配置文件,用于初始化bean
	<listener>
	<listener-class> 
org.springframework.web.context.ContextLoaderListener 
</listener-class>
	</listener>
	<context-param>
		<param-name> contextConfigLocation </param-name>
		<param-value> /WEB-INF/applicationContext.xml </param-value>
	</context-param>

3.目录结构:tomcat/axis2/WEB-INF

项目的配置文件都放在这里
修改配置文件里的一些内容:主要是加载路径相关,eg:
<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation">
			<value>/WEB-INF/hibernate.cfg.xml</value>
		</property>
	</bean>

4. 发布服务

aar包里在META-INF里面是

这个aar包里不需要放置类文件,只要一个services.xml用于标识将哪个类发布为服务
文件内容
<service name="student" >
<description>
Please Type your service description here
</description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name= "ServiceObjectSupplier" >
        org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
  </parameter>  //猜测是spring axis2 结合所需要的 类
  <parameter name= "SpringBeanName" >studentservice</parameter>
//发布的服对应的类,因为是利用spring来加载,所以这里必须是spring 配置文件里对应的bean id
//而不能是类的绝对路径,因为需要spring的注入功能所以要从spring窗口里去取得类的实例
</service>
5.向axis2容器里添加项目的Lib包:

注:
axis2可能不支持List<T>这种集合类型,所以要使用对象数组类型来返回多个数据,或者利用String返回,将其在client端进行解析。
  So the implementaion will be;   public String[] getRes(int a, int b) throws Exception { List list = new ArrayList(); list.add("ddd"); list.add("ddd"); list.add("ddd"); System.out.println(list); return (String[]) list.toArray(new String[list.size()]); }   If the method signature returns collections, there is no way for Axis2 to figure out types of the items included in the list, hence you will get an error.   


这两天忽然对axis2来了兴趣, 于是下载来摆弄.

我没有直接在下载的axis2的war包的基础上去做, 而是一步一步把axis2添加到我原有的工程里面去, 这样做确实挺累人的, 不过网上已经很多这样的文章, 因此我不去写它了

我感兴趣的是, 怎么让axis能传输java对象, 其实也有文章介绍, 见

因为我原来的应用是struts2+spring+hibernate的, 便很自然的想把axis2的service整合到spring去, 结果却发现一个axis2的bug, 在axis2的论坛已经有人提过, 好像还没有修复.

如果你做一个Bean, 并让Spring为这个bean生成事务代理的JDK动态代理类, 那么, 启动应用的时候, 就报类似
org.apache.axis2.deployment.DeploymentException: The following error occurred during schema generation: Unable to load bytecode for class $Proxy4
这样的出错信息, 很郁闷.

这意味着什么? 以为着我们公布的web service不能直接参与事务, 而是需要把事务"代理"给其他的类处理!!!
又多了一层不必要的封装!!!

我理想中的模型
Client ---------> ProxyTransactionalWebServiceBean
现在
Client----------> ProxyImpl ----------> ProxyTransactionalWebServiceBean
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics