一、环境配置
:在
eclipse
中配置引入相应的
Spring
框架(
core/Remoting/Web
)、
axis
包。
<!---->
<o:p>
</o:p>
<!---->
<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600">
<v:stroke joinstyle="miter">
</v:stroke>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
</v:f>
<v:f eqn="sum @0 1 0">
</v:f>
<v:f eqn="sum 0 0 @1">
</v:f>
<v:f eqn="prod @2 1 2">
</v:f>
<v:f eqn="prod @3 21600 pixelWidth">
</v:f>
<v:f eqn="prod @3 21600 pixelHeight">
</v:f>
<v:f eqn="sum @0 0 1">
</v:f>
<v:f eqn="prod @6 1 2">
</v:f>
<v:f eqn="prod @7 21600 pixelWidth">
</v:f>
<v:f eqn="sum @8 21600 0">
</v:f>
<v:f eqn="prod @7 21600 pixelHeight">
</v:f>
<v:f eqn="sum @10 21600 0">
</v:f>
</v:formulas>
<v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f">
</v:path>
<o:lock aspectratio="t" v:ext="edit">
</o:lock>
</v:shapetype>
<v:shape id="_x0000_i1025" style="WIDTH: 414.75pt; HEIGHT: 273pt" type="#_x0000_t75">
<v:imagedata o:title="" src="file:///D:\Winbak\Temp\msohtml1\01\clip_image001.png">
</v:imagedata>
</v:shape>
<o:p>
</o:p>
<o:p> </o:p>
二、代码开发
<o:p>
</o:p>
1、
在
MyEclipse
中建立一个新的
J2EE
的
Web Project,
新建
java
包
test
。
<o:p>
</o:p>
2、
接口文件
HelloWorldRemote.java<o:p></o:p>
package test;<o:p></o:p>
//Spring
工程中要使用的接口文件
<o:p>
</o:p>
public interface HelloWorldRemote <o:p></o:p>
{<o:p></o:p>
public String getMessage(String name);<o:p></o:p>
}<o:p></o:p>
3、
接口实现文件
HelloWorldBean.java<o:p></o:p>
package test;<o:p></o:p>
//Spring
工程中要使用的接口实现文件
<o:p>
</o:p>
public class HelloWorldBean implements HelloWorldRemote <o:p></o:p>
{ <o:p></o:p>
private String helloStr; // Spring
中需要注入的字符串
<o:p>
</o:p>
public String getHelloStr() <o:p></o:p>
{<o:p></o:p>
return helloStr;<o:p></o:p>
}<o:p></o:p>
public void setHelloStr(String helloStr) <o:p></o:p>
{<o:p></o:p>
this.helloStr = helloStr;<o:p></o:p>
}<o:p></o:p>
//
实现接口中的方法
<o:p>
</o:p>
public String getMessage(String name) <o:p></o:p>
{<o:p></o:p>
return helloStr + ":" + name;<o:p></o:p>
} <o:p></o:p>
}<o:p></o:p>
4、
在
Spring
中对
Web Service
进行封装很简单,仅仅需要继承
<o:p>
</o:p>
org.springframework.remoting.jaxrpc.ServletEndpointSupport
类,实现里面的一些方法,包装一次,将其发布出来就可以。
HelloWorldWebService.java<o:p></o:p>
package test;<o:p></o:p>
import javax.xml.rpc.ServiceException;<o:p></o:p>
import org.springframework.remoting.jaxrpc.ServletEndpointSupport;<o:p></o:p>
public class HelloWorldWebService <o:p></o:p>
extends ServletEndpointSupport <o:p></o:p>
implements HelloWorldRemote <o:p></o:p>
{<o:p></o:p>
private HelloWorldRemote helloWorld;<o:p></o:p>
protected void onInit() throws ServiceException <o:p></o:p>
{<o:p></o:p>
//
在
Spring
容器中获取
Bean
的实例
<o:p>
</o:p>
helloWorld = (HelloWorldRemote) getApplicationContext()<o:p></o:p>
.getBean("myHelloWorldBean");<o:p></o:p>
}<o:p></o:p>
public String getMessage(String name) <o:p></o:p>
{<o:p></o:p>
//
执行
Bean
中的相同的方法
<o:p>
</o:p>
return helloWorld.getMessage(name);<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
<o:p> </o:p>
三、配置文件
(全部放在
/WEB-INF/
目录下
)
<o:p>
</o:p>
1、
web.xml
为
web
加载
spring
和
axis
配置
<o:p>
</o:p>
<!--Spring
框架需要引入的配置文件及相关类
--><o:p></o:p>
<context-param><o:p></o:p>
<param-name>contextConfigLocation</param-name><o:p></o:p>
<param-value>/WEB-INF/applicationContext.xml</param-value><o:p></o:p>
</context-param><o:p></o:p>
<servlet><o:p></o:p>
<servlet-name>context</servlet-name><o:p></o:p>
<servlet-class><o:p></o:p>
org.springframework.web.context.ContextLoaderServlet<o:p></o:p>
</servlet-class><o:p></o:p>
<load-on-startup>1</load-on-startup><o:p></o:p>
</servlet><o:p></o:p>
<!--axis
需要引入的
Servlet --><o:p></o:p>
<servlet><o:p></o:p>
<servlet-name>axis</servlet-name><o:p></o:p>
<servlet-class><o:p></o:p>
org.apache.axis.transport.http.AxisServlet<o:p></o:p>
</servlet-class><o:p></o:p>
<load-on-startup>2</load-on-startup><o:p></o:p>
</servlet><o:p></o:p>
<servlet-mapping><o:p></o:p>
<servlet-name>axis</servlet-name><o:p></o:p>
<url-pattern>/services/*</url-pattern><o:p></o:p>
</servlet-mapping><o:p></o:p>
<!--axis
的
Web Service
的
Web
发布路径
--><o:p></o:p>
2、
applicationContext.xml
为
spring
的配置
<o:p>
</o:p>
<?xml version="1.0" encoding="UTF-8"?> <o:p></o:p>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" <o:p></o:p>
"http://www.springframework.org/dtd/spring-beans.dtd"> <o:p></o:p>
<beans><o:p></o:p>
<bean id="myHelloWorldBean" class="test.HelloWorldBean"><o:p></o:p>
<property name="helloStr"><o:p></o:p>
<value>Say Hello to :</value><o:p></o:p>
</property><o:p></o:p>
</bean><o:p></o:p>
</beans><o:p></o:p>
3、
server-config.wsdd
为
axis
服务配置
<o:p>
</o:p>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"<o:p></o:p>
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"><o:p></o:p>
<handler name="URLMapper"<o:p></o:p>
type="java:org.apache.axis.handlers.http.URLMapper" /> <o:p></o:p>
<!--
系统服务
--><o:p></o:p>
<service name="AdminService" provider="java:MSG"><o:p></o:p>
<parameter name="allowedMethods" value="AdminService" /><o:p></o:p>
<parameter name="enableRemoteAdmin" value="false" /><o:p></o:p>
<parameter name="className" value="org.apache.axis.utils.Admin" /><o:p></o:p>
<namespace>http://xml.apache.org/axis/wsdd/</namespace><o:p></o:p>
</service><o:p></o:p>
<service name="Version" provider="java:RPC"><o:p></o:p>
<parameter name="allowedMethods" value="getVersion" /><o:p></o:p>
<parameter name="className" value="org.apache.axis.Version" /><o:p></o:p>
</service> <o:p></o:p>
<!--
自定义服务
--><o:p></o:p>
<service name="myWebService" provider="java:RPC"><o:p></o:p>
<parameter name="className"<o:p></o:p>
value="test.HelloWorldWebService" /><o:p></o:p>
<parameter name="allowedMethods" value="*" /><o:p></o:p>
</service><o:p></o:p>
<transport name="http"><o:p></o:p>
<requestFlow><o:p></o:p>
<handler type="URLMapper" /><o:p></o:p>
</requestFlow><o:p></o:p>
</transport><o:p></o:p>
</deployment><o:p></o:p>
<o:p> </o:p>
四、测试
客户端
TestWebServiceClient.java<o:p></o:p>
package test;<o:p></o:p>
import javax.xml.namespace.QName;<o:p></o:p>
import org.apache.axis.client.Call;<o:p></o:p>
import org.apache.axis.client.Service;<o:p></o:p>
public class TestWebServiceClient <o:p></o:p>
{ <o:p></o:p>
public static void main(String[] args)<o:p></o:p>
{ <o:p></o:p>
try <o:p></o:p>
{<o:p></o:p>
String wsdlUrl <o:p></o:p>
= "http://localhost:8080/spring-axis/services/myWebService?wsdl";<o:p></o:p>
String nameSpaceUri <o:p></o:p>
= "http://localhost:8080/spring-axis/services/myWebService";<o:p></o:p>
//
创建调用对象
<o:p>
</o:p>
Service service = new Service();<o:p></o:p>
Call call = null;<o:p></o:p>
call = (Call) service.createCall();<o:p></o:p>
//
调用
getMessage<o:p></o:p>
System.out.println(">>>getMessage");<o:p></o:p>
call.setOperationName(new QName(nameSpaceUri, "getMessage"));<o:p></o:p>
call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));<o:p></o:p>
String ret = (String) call.invoke(new Object[] { "ABC" });<o:p></o:p>
System.out.println("return value is " + ret);<o:p></o:p>
} <o:p></o:p>
catch (Exception e) <o:p></o:p>
{<o:p></o:p>
e.printStackTrace();<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
<o:p> </o:p>
分享到:
相关推荐
简单例子:axis2整合spring发布webservice,以及session的管理
一个可能直接在tomcat运行的webservice例子(Axis+Spring+jpa)
axis2+Spring提供WebService服务,有调用方法类。
借鉴网上的资源,弄了一个SpringBoot开发WebService之Axis示例。
axis2+spring2.5整合(webservice)
lib包中包含所有axis2+spring所需要的jar包
首先,该工程实现了spring MVC、mybatis、axis webservice功能 其次,这个工程很简单,只做了最简单的功能实现 再次,数据库要自己准备 最后,该工程里的src目录下,有一个readme.txt,请下载者仔细阅读,里面有...
axis1.4+mybatis3+spring3集成实现webservice;websphere下Log4j记录日志解决方案;
通过axis2与spring进行集成,发布webservice服务,
spring+axis集成webservice
axis2 webservice 服务端jar包: -->axis2-kernel-1.6.1.jar -->axis2-spring-1.6.1.jar -->axis2-transport-http-1.6.1.jar -->XmlSchema-1.4.7.jar -->wsdl4j-1.6.2.jar -->axiom-api-1.2.12.jar -->axiom...
axis2+spring+ibatis整合的一个项目,含webservice文件传输
spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码
java开源,鄙视收分 by zero
NULL 博文链接:https://lichaobao.iteye.com/blog/2142754
Axis2是目前比较流行的WebService引擎。WebService被应用在很多不同的场景。OSGi 框架为基于 Java 的组件开发提供了一套通用的和标准的解决方案,通过 OSGi 框架可以轻松实现组件信息的隐藏和共享。
该文档详细的讲述了通过axis与spring开发webservice的流程,内附实例与图解,使您能详细的了解开发流程~~
一个spring+axis开发webservice的完整例子,还配有jdom解析xml
在hibernate spring项目基础上通过aixs2-1.4.1把程序发布成webService,包括aixs2以对象数组和AXIOM方式处理map,list的程序代码;和aixs2-1.4-1的jar包
Axis的简单准备 Axis的入门实例 Axis复杂对象类型的WebService Axis的辅助工具发布、调用WebService Axis WebService会话Session的管理 Axis用控制台Dos命令发布...Axis使用SoapMonitar监视WebService的请求和响应信息