1.下载 spring-framework-2.0.8.zip 和 axis2-1.5-war.zip 备用:
http://nchc.dl.sourceforge.net/project/springframework/springframework-2/2.0.8/spring-framework-2.0.8.zip
http://apache.etoak.com/ws/axis2/1_5/axis2-1.5-war.zip
2.新建一个web工程:ws-sample
解压pring-framework-2.0.8.zip 和 axis2-1.5-war.zip
将 spring.jar 和 axis2/WEB-INF/lib 里的jar包拷贝到 ws-sample/WebRoot/WEB-INF/lib/
打开ws-sample/WebRoot/WEB-INF/web.xml,增加配置:
- < servlet >
- < servlet-name > AxisServlet </ servlet-name >
- < servlet-class > org.apache.axis2.transport.http.AxisServlet </ servlet-class >
- < load-on-startup > 1 </ load-on-startup >
- </ servlet >
- < servlet-mapping >
- < servlet-name > AxisServlet </ servlet-name >
- < url-pattern > /services/* </ url-pattern >
- </ servlet-mapping >
- <servlet>
- <servlet-name>AxisServlet</servlet-name>
- <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>AxisServlet</servlet-name>
- <url-pattern>/services/*</url-pattern>
- </servlet-mapping>
新建一个JSP:/ws-sample/WebRoot/axis2-web/listServices.jsp
- <%@
- page contentType="text/html;charset=UTF-8" language= "java"
- %><%@
- page import="org.apache.axis2.Constants,
- org.apache.axis2.description.AxisOperation,
- org.apache.axis2.description.AxisService,
- java.util.Collection,
- java.util.HashMap,
- java.util.Iterator"
- %><html>
- <head><title>List Services</title>
- <style>
- h2{margin:20 0 5 0 ;}
- ul{margin-top:5 ;}
- </style>
- </head>
- <body>
- <h1>Available services</h1>
- <%
- HashMap serviceMap = (HashMap) request.getSession().getAttribute(Constants.SERVICE_MAP);
- Collection servicecol = serviceMap.values();
- if(servicecol.size()==0 ){%>Available services is Empty.<%}
- for (Iterator iterator = servicecol.iterator(); iterator.hasNext();) {
- AxisService axisService = (AxisService) iterator.next();
- Iterator opItr = axisService.getOperations();
- String serviceName = axisService.getName();
- %>
- <h2><font color="blue" ><a href= "<%=serviceName %>?wsdl" target= "_blank" ><%=serviceName%></a></font></h2>
- <i>Available Operations</i>
- <ul>
- <%
- while (opItr.hasNext()) {
- AxisOperation axisOperation = (AxisOperation) opItr.next();
- %><li><%=axisOperation.getName().getLocalPart()%></li><%
- }
- %>
- </ul>
- <%
- }
- %>
- </body>
- </html>
- <%@
- page contentType="text/html;charset=UTF-8" language="java"
- %><%@
- page import="org.apache.axis2.Constants,
- org.apache.axis2.description.AxisOperation,
- org.apache.axis2.description.AxisService,
- java.util.Collection,
- java.util.HashMap,
- java.util.Iterator"
- %><html>
- <head><title>List Services</title>
- <style>
- h2{margin:20 0 5 0;}
- ul{margin-top:5;}
- </style>
- </head>
- <body>
- <h1>Available services</h1>
- <%
- HashMap serviceMap = (HashMap) request.getSession().getAttribute(Constants.SERVICE_MAP);
- Collection servicecol = serviceMap.values();
- if(servicecol.size()==0){%>Available services is Empty.<%}
- for (Iterator iterator = servicecol.iterator(); iterator.hasNext();) {
- AxisService axisService = (AxisService) iterator.next();
- Iterator opItr = axisService.getOperations();
- String serviceName = axisService.getName();
- %>
- <h2><font color="blue"><a href="<%=serviceName %>?wsdl" target="_blank"><%=serviceName%></a></font></h2>
- <i>Available Operations</i>
- <ul>
- <%
- while (opItr.hasNext()) {
- AxisOperation axisOperation = (AxisOperation) opItr.next();
- %><li><%=axisOperation.getName().getLocalPart()%></li><%
- }
- %>
- </ul>
- <%
- }
- %>
- </body>
- </html>
部署至tomcat,然后访问:
http://localhost:8080/ws-sample/services/listServices
如果不出差错的话,可以看到 Available services is Empty
3.部署pojo服务
新建目录:ws-sample/WebRoot/WEB-INF/services/
将 axis2/WEB-INF/services/version.aar 拷贝至 ws-sample/WebRoot/WEB-INF/services/
刷新 http://localhost:8080/ws-sample/services/listServices
见到一个叫Version的服务,说明 version.aar 已成功部署
4.开发并部署基于 Spring ApplicationContex 的服务
创建接口:sample.weatherservice.service.IWeatherService
和类:
sample.weatherservice.bean.Weather
sample.weatherservice.service.impl.WeatherService
代码如下:
- //Weather.java
- package sample.weatherservice.bean;
- public class Weather {
- float temperature;
- String forecast;
- boolean rain;
- float howMuchRain;
- public void setTemperature( float temp) {
- temperature = temp;
- }
- public float getTemperature() {
- return temperature;
- }
- public void setForecast(String fore) {
- forecast = fore;
- }
- public String getForecast() {
- return forecast;
- }
- public void setRain( boolean r) {
- rain = r;
- }
- public boolean getRain() {
- return rain;
- }
- public void setHowMuchRain( float howMuch) {
- howMuchRain = howMuch;
- }
- public float getHowMuchRain() {
- return howMuchRain;
- }
- }
- //Weather.java
- package sample.weatherservice.bean;
- public class Weather {
- float temperature;
- String forecast;
- boolean rain;
- float howMuchRain;
- public void setTemperature(float temp) {
- temperature = temp;
- }
- public float getTemperature() {
- return temperature;
- }
- public void setForecast(String fore) {
- forecast = fore;
- }
- public String getForecast() {
- return forecast;
- }
- public void setRain(boolean r) {
- rain = r;
- }
- public boolean getRain() {
- return rain;
- }
- public void setHowMuchRain(float howMuch) {
- howMuchRain = howMuch;
- }
- public float getHowMuchRain() {
- return howMuchRain;
- }
- }
- //IWeatherService.java
- package sample.weatherservice.service;
- import sample.weatherservice.bean.Weather;
- public interface IWeatherService {
- void setWeather(Weather w);
- Weather getWeather();
- }
- //IWeatherService.java
- package sample.weatherservice.service;
- import sample.weatherservice.bean.Weather;
- public interface IWeatherService {
- void setWeather(Weather w);
- Weather getWeather();
- }
- //WeatherService.java
- package sample.weatherservice.service.impl;
- import sample.weatherservice.bean.Weather;
- import sample.weatherservice.service.IWeatherService;
- public class WeatherService implements IWeatherService {
- Weather weather;
- public void setWeather(Weather w) {
- weather = w;
- }
- public Weather getWeather() {
- return weather;
- }
- }
- //WeatherService.java
- package sample.weatherservice.service.impl;
- import sample.weatherservice.bean.Weather;
- import sample.weatherservice.service.IWeatherService;
- public class WeatherService implements IWeatherService {
- Weather weather;
- public void setWeather(Weather w) {
- weather = w;
- }
- public Weather getWeather() {
- return weather;
- }
- }
新建spring配置文件:
ws-sample/WebRoot/WEB-INF/applicationContext.xml
- <? xml version = "1.0" encoding = "UTF-8" ?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- < beans >
- < bean id = "weatherService" class = "sample.weatherservice.service.impl.WeatherService" >
- < property name = "weather" >
- < bean class = "sample.weatherservice.bean.Weather" >
- < property name = "temperature" value = "89.9" />
- < property name = "forecast" value = "Sunny" />
- < property name = "rain" value = "false" />
- < property name = "howMuchRain" value = "0.2" />
- </ bean >
- </ property >
- </ bean >
- </ beans >
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="weatherService" class="sample.weatherservice.service.impl.WeatherService">
- <property name="weather">
- <bean class="sample.weatherservice.bean.Weather">
- <property name="temperature" value="89.9" />
- <property name="forecast" value="Sunny" />
- <property name="rain" value="false" />
- <property name="howMuchRain" value="0.2" />
- </bean>
- </property>
- </bean>
- </beans>
修改 ws-sample/WebRoot/WEB-INF/web.xml 增加:
- < context-param >
- < param-name > contextConfigLocation </ param-name >
- < param-value > /WEB-INF/applicationContext.xml </ param-value >
- </ context-param >
- < 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>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
在 ws-sample/WebRoot/WEB-INF/services/ 目录下,新建文件夹和文件 weatherservice/META-INF/services.xml
services.xml的内容如下:
- < serviceGroup >
- < service name = "WeatherService" >
- < description > WeatherService:Spring POJO Axis2 Service Sample </ description >
- < parameter name = "ServiceClass" > sample.weatherservice.service.IWeatherService </ parameter >
- < parameter name = "ServiceObjectSupplier" >
- org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
- </ parameter >
- < parameter name = "SpringBeanName" > weatherService </ parameter >
- < messageReceivers >
- < messageReceiver mep = "http://www.w3.org/2004/08/wsdl/in-out"
- class = "org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
- </ messageReceivers >
- </ service >
- </ serviceGroup >
- <serviceGroup>
- <service name="WeatherService">
- <description>WeatherService:Spring POJO Axis2 Service Sample</description>
- <parameter name="ServiceClass">sample.weatherservice.service.IWeatherService</parameter>
- <parameter name="ServiceObjectSupplier">
- org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
- </parameter>
- <parameter name="SpringBeanName">weatherService</parameter>
- <messageReceivers>
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
- class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
- </messageReceivers>
- </service>
- </serviceGroup>
刷新 http://localhost:8080/ws-sample/services/listServices
见到新增了一个叫WeatherService的服务,说明 WeatherService 已成功部署
5.开发客户端调用
创建类:client.WeatherRPCClient
- package client;
- import javax.xml.namespace.QName;
- import org.apache.axis2.AxisFault;
- import org.apache.axis2.addressing.EndpointReference;
- import org.apache.axis2.client.Options;
- import org.apache.axis2.rpc.client.RPCServiceClient;
- import sample.weatherservice.bean.Weather;
- public class WeatherRPCClient {
- public static void main(String[] args1) throws AxisFault {
- EndpointReference targetEPR = new EndpointReference( "http://localhost:8080/ws-sample/services/WeatherService" );
- RPCServiceClient serviceClient = new RPCServiceClient();
- Options options = serviceClient.getOptions();
- options.setTo(targetEPR);
- QName opGetWeather = new QName( "http://service.weatherservice.sample" , "getWeather" );
- Object[] opGetWeatherArgs = new Object[] { };
- Class[] returnTypes = new Class[] { Weather. class };
- Object[] response = serviceClient.invokeBlocking(opGetWeather,opGetWeatherArgs, returnTypes);
- Weather result = (Weather) response[0 ];
- if (result == null ) {
- System.out.println("Weather didn't initialize!" );
- }else {
- System.out.println();
- System.out.println("Temperature : " + result.getTemperature());
- System.out.println("Forecast : " + result.getForecast());
- System.out.println("Rain : " + result.getRain());
- System.out.println("How much rain (in inches) : " + result.getHowMuchRain());
- }
- }
- }
- package client;
- import javax.xml.namespace.QName;
- import org.apache.axis2.AxisFault;
- import org.apache.axis2.addressing.EndpointReference;
- import org.apache.axis2.client.Options;
- import org.apache.axis2.rpc.client.RPCServiceClient;
- import sample.weatherservice.bean.Weather;
- public class WeatherRPCClient {
- public static void main(String[] args1) throws AxisFault {
- EndpointReference targetEPR = new EndpointReference("http://localhost:8080/ws-sample/services/WeatherService");
- RPCServiceClient serviceClient = new RPCServiceClient();
- Options options = serviceClient.getOptions();
- options.setTo(targetEPR);
- QName opGetWeather = new QName("http://service.weatherservice.sample", "getWeather");
- Object[] opGetWeatherArgs = new Object[] { };
- Class[] returnTypes = new Class[] { Weather.class };
- Object[] response = serviceClient.invokeBlocking(opGetWeather,opGetWeatherArgs, returnTypes);
- Weather result = (Weather) response[0];
- if (result == null) {
- System.out.println("Weather didn't initialize!");
- }else{
- System.out.println();
- System.out.println("Temperature : " + result.getTemperature());
- System.out.println("Forecast : " + result.getForecast());
- System.out.println("Rain : " + result.getRain());
- System.out.println("How much rain (in inches) : " + result.getHowMuchRain());
- }
- }
- }
运行 WeatherRPCClient,输出如下,说明调用成功:
Temperature : 89.9
Forecast : Sunny
Rain : false
How much rain (in inches) : 0.2
相关推荐
当我们谈论“Spring + Axis2 开发 WebService”时,这通常指的是使用Spring框架与Apache Axis2工具来创建、部署和消费基于SOAP(Simple Object Access Protocol)的Web服务。以下是关于这个主题的详细知识点: 1. *...
本教程将介绍如何利用Spring框架与Apache Axis2来开发和部署SOAP Web服务,这是一种高效且灵活的方式。 首先,我们需要了解Spring框架。Spring是一个开源的应用程序框架,它为Java开发提供了全面的基础设施支持。...
2. **创建WebService**:在Spring中,可以通过定义一个实现了特定接口的类来创建Web服务。这个接口通常对应于服务的WSDL契约,而实现类则包含了实际的服务逻辑。 Axis2提供了`ServiceStub`类,可以帮助我们与服务...
标题中的“axis2+spring webservice”指的是使用Apache Axis2框架与Spring框架集成来开发Web服务。Apache Axis2是Java环境中广泛使用的Web服务引擎,它提供了高性能、灵活且可扩展的架构。Spring框架则是一个全面的...
本文将深入探讨如何使用Spring与Axis进行集成,以便开发和消费Web服务。 首先,让我们了解Spring和Axis的基本概念。Spring是一个开源Java框架,它为构建灵活、模块化且可测试的应用程序提供了强大的支持。它包含多...
在这个"spring+axis编写webservice"的例子中,我们将深入探讨如何结合这两者来创建高效、灵活的Web服务,并利用JDOM解析XML数据。 首先,Spring框架是Java企业级应用开发的重要工具,提供了依赖注入(DI)和面向切面...
标题 "axis2+spring+hibernate Webservice" 指出的是一个基于Java的开源项目,它结合了三个关键的技术框架:Axis2、Spring和Hibernate。这些技术都是企业级应用开发中的重要组件,用于构建高效、灵活且可扩展的服务...
3. **配置Spring**:在Spring的XML配置文件中,创建一个Bean,使用`<bean>`标签定义服务实现,并使用`<axis2:service>`或`<axis2:client>`标签来声明这是一个Axis2服务或客户端。 4. **配置Axis2**:在Axis2的配置...
Axis2和Spring框架的结合提供了一种高效且灵活的方式来创建和管理WebService。让我们深入了解一下这两个技术以及它们如何协同工作。 首先,Apache Axis2是Java平台上一个成熟的Web服务引擎,专门用于处理SOAP消息。...
软件架构说明 服务端:WebService+axis+mybatis 服务端开发环境:jdk8,mysql8.0,tomcat9.0,IDEA2021 客户端:基于Springboot来整合axis客户端 客户端用springboot实现,服务端用webService+axis+mybatis实现 ...
【Spring + Axis2 + XFire 整合的Web Service】是一种在Java环境下构建Web服务的解决方案,它结合了Spring框架的灵活性和Axis2、XFire的Web服务处理能力。Web服务是一个基于开放标准的分布式计算模型,允许不同系统...
主流的spring4mvc+Mybatis,并整合了axis2实现webservice接口开发。利用quartz注解实现任务作业功能源码。利用spring RoutingDataSource实现动态数据源切换
本案例"jsf+spring+hibernate+Axis2开发案例"旨在演示如何整合这四个核心技术来创建一个完整的Web应用程序。 首先,`JSF (JavaServer Faces)`是一种用于构建用户界面的MVC(Model-View-Controller)框架,它简化了...
首先,该工程实现了spring MVC、mybatis、axis webservice功能 其次,这个工程很简单,只做了最简单的功能实现 再次,数据库要自己准备 最后,该工程里的src目录下,有一个readme.txt,请下载者仔细阅读,里面有...
综合来看,"Xfire+Spring+Hibernate WebService"项目利用了这些工具和技术的协同工作,实现了高效、灵活的Web服务开发。Xfire提供Web服务的基础框架,Spring为业务逻辑提供了容器和管理,而Hibernate则处理了数据...
通过以上步骤,我们可以将Axis2 Web服务完全融入Spring的应用程序中,实现更高效的开发、测试和部署流程。这样的整合不仅简化了代码管理,还充分利用了Spring的高级特性,提高了整体系统的灵活性和可靠性。在实际...
在IT行业中,Axis2是Apache软件基金会开发的一个用于构建Web服务和Web服务客户端的框架,主要基于Java语言。本文将详细讲解如何使用Axis2来发布Web服务以及如何生成客户端代码来调用这些服务。 首先,让我们了解...
### WebService技术应用:Spring 3 + CXF 3.4与Axis 1.4的交互 在现代软件开发中,Web服务作为一种重要的技术手段,被广泛应用于不同系统之间的通信。其中,Spring框架与Apache CXF是实现RESTful或SOAP风格的Web...
这些库共同构成了一个完整的开发环境,使得开发者能够利用Axis2和Spring的强大力量创建和部署高质量的Web服务。在实际开发中,根据项目需求,可能还需要添加其他特定的库或依赖,但这些基础库已经覆盖了大部分基本...
3. **创建WebService**:在Spring Boot应用中,你可以通过Axis1.4创建一个WebService。首先,定义一个Java类,包含你想要公开的方法。然后,使用Axis的工具生成服务端点接口和服务类。 4. **配置Spring Boot**:...