Axis1整合Spring比较简单,这种便利得益于Spring的ServletEndpointSupport类支持
1、导入jar包
1.1、axis1的jar包
activation.jar
axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
log4j-1.2.8.jar
mailapi_1_3_1.jar
wsdl4j-1.5.1.jar
1.2、spring相关jar包
2、创建服务端
2.1、创建接口
package com.axis.service; public interface HelloWorld { public String getMessage(String message); }
2.2、创建实现类
package com.axis.service.impl; import com.axis.service.HelloWorld; public class HelloWorldImpl implements HelloWorld { @Override public String getMessage(String message) { return "---------Axis Server-------" + message; } }
2.3、创建远程接口
package com.axis.service; import java.rmi.Remote; import java.rmi.RemoteException; public interface RemoteHelloWorld extends Remote { public String getMessage(String message) throws RemoteException; }
2.3、创建WEB服务(spring与axis1对接,需要做一个ServletEndpointSupport继承实现WebService)
package com.axis.service; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import org.springframework.remoting.jaxrpc.ServletEndpointSupport; public class JaxRpcHelloWorld extends ServletEndpointSupport implements RemoteHelloWorld { private HelloWorld helloWorld; protected void onInit() throws ServiceException { helloWorld = (HelloWorld) getApplicationContext().getBean("helloWorldService"); } public String getMessage(String message) throws RemoteException { return helloWorld.getMessage(message); } }
这个类有两个重要的方法getMessage()和onInit()方法的实现。在getMessage()中,你看到真实的处理和HelloWorld接口的一个实例相似,HelloWorld接口和RemoteHelloWorld几口根据同样的名称共享方法,但是HelloWorld没有继承Remote,方法也没抛出RemoteException,HelloWorld接口地实现可以在很多环境下通过servlet容器来进行简单的测试,因为他和java远程接口没有关系,我们可可以仅仅使用JaxRpcHelloWorld类代表RemoteHelloWorld,但是将消弱对于RemoteHelloWorld接口的可重用性实现,因为所有的方法必须抛出RemoteExceptio和继Remote,使用HelloWorld接口,我们能够使他在某些环境中更简单的使用
2.4、配置服务端
2.4.1、服务端的spring配置文件applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 接口的具体实现类 --> <bean id="helloWorldService" class="com.axis.service.impl.HelloWorldImpl" /> </beans>
2.4.2、部署axis的WebService服务,在web-inf下加入server-config.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" /> <service name="HelloWorld" provider="java:RPC"> <parameter name="className" value="com.axis.service.JaxRpcHelloWorld" /> <parameter name="allowedMethods" value="*" /> </service> <transport name="http"> <requestFlow> <handler type="URLMapper" /> </requestFlow> </transport> </deployment>
其中最重要的是service标签,他定义了WS的名字,有两个子标签,一个用来指定服务实现类的全名,一个用来定义服务中要被暴露的服务方法过滤器
指定java:RPC表明这是一个RPC风格的服务
2.4.3、配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- axis --> <servlet> <display-name>Apache-Axis Servlet</display-name> <servlet-name>axis</servlet-name> <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>axis</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app>
部署这个web服务,我们在浏览器中运行如下地址(根据你自己的webapp)
http://localhost:8080/services 可以看到你定义的web服务如下:
点击wsdl链接可以看到wdsl
3、客户端测试
package com.axis.client; import javax.xml.namespace.QName; import javax.xml.rpc.Call; import org.apache.axis.client.Service; import org.junit.Before; import org.junit.Test; public class AxisClientTest { private String nameSpaceUri = "http://localhost:8080/services/HelloWorld"; private String wsdlUrl = nameSpaceUri + "?wsdl"; private Service service; private Call call; @Before public final void init() throws Exception { // 创建调用对象 service = new Service(); call = (Call) service.createCall(); // 调用 远程方法 call.setOperationName(new QName(nameSpaceUri, "getMessage")); // 设置URL call.setTargetEndpointAddress(wsdlUrl); } @Test public final void testGetMessage() throws Exception { // 设置参数 String message = "HelloWorld"; // 执行远程调用,同时获得返回值 String str = (String) call.invoke(new Object[] { message }); System.out.println(str); } }
相关推荐
一个可能直接在tomcat运行的webservice例子(Axis+Spring+jpa)
简单例子:axis2整合spring发布webservice,以及session的管理
spring+axis2整合,项目下载之后就能使用,里面简单的编写的发布服务的代码,适合初学者使用
axis2+spring+ibatis整合的一个项目,含webservice文件传输
axis2+spring2.5整合(webservice)
axis2+Spring提供WebService服务,有调用方法类。
axis2和axis2+spring发布服务指南
lib包中包含所有axis2+spring所需要的jar包
AXIS2 + SPRING 文件上传 用MYECLIPSE直接导入文件运行即可.
axis2 和 spring3.2.0 的包。 这里http://blog.csdn.net/linlinv3/article/details/9017767详细讲解了 axis2 的用法
axis1.4+mybatis3+spring3集成实现webservice;websphere下Log4j记录日志解决方案;
首先,该工程实现了spring MVC、mybatis、axis webservice功能 其次,这个工程很简单,只做了最简单的功能实现 再次,数据库要自己准备 最后,该工程里的src目录下,有一个readme.txt,请下载者仔细阅读,里面有...
通过axis2与spring进行集成,发布webservice服务,
在hibernate spring项目基础上通过aixs2-1.4.1把程序发布成webService,包括aixs2以对象数组和AXIOM方式处理map,list的程序代码;和aixs2-1.4-1的jar包
公司项目需要,搭建了SSM框架,当初想更好的熟悉SSM框架的架构及其原理,所以未使用maven,资源中包括所有的jar包,能直接运行在tomcat服务器,框架中使用了Spring的自动扫描,注解注入,AOP异常日志记录,AOP事务,...
java开源,鄙视收分 by zero
cxf-2.4.1+axis-1.4,整合spring3.0所用jar包
4 支持Spring、Pico、Plexus、Loom等容器; 5 灵活的Binding机制,包括默认的Aegis,xmlbeans,jaxb2,castor; 6 高性能的SOAP 栈设计; 7 支持Spring、Pico、Plexus、Loom等容器。 8 XFire比Axis1.3快2-6倍; 9...
NULL 博文链接:https://lichaobao.iteye.com/blog/2142754
已经通过测试,运行稳定,需要注意的是axis版本为1