初次接触 axis2,发现用起来极端繁琐。网上搜了 N 多的资料,终于找到一种轻松实现的方法。
第一步:准备
下载 spring-framework-2.0.8.zip 和 axis2-1.5-war.zip 备用:
http://nchc.dl.sourceforge.net/project/springframework/springframework-2/2.0.8/spring-fra
mework-2.0.8.zip
http://apache.etoak.com/ws/axis2/1_5/axis2-1.5-war.zip
第二步:新建 web service 项目: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-c lass> <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>
部署至 tomcat,然后访问:
http://localhost:8080/ws-sample/services/listServices
如果不出差错的话,可以看到 Available services is Empty
第三步:部署 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 已成功部署
第四步:开发并部署基于 Spring ApplicationContex 的服务
创建接口:sample.weatherservice.service.IWeatherService和类:
sample.weatherservice.bean.Weather
sample.weatherservice.service.impl.WeatherService
代码如下:
package sample.weatherservice.service;
import sample.weatherservice.bean.Weather;
public interface IWeatherService {
void setWeather(Weather w);
Weather getWeather();
}
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;
}
}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;
}
}
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 {
// 使用 RPC 方式调用 WebService
// 指定调用 WebService 的 URL
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());
}
}
}
新建 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> 修改 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>
在 ws-sample/WebRoot/WEB-INF/services/ 目录下,新建文件夹:weatherservice
在目录 weatherservice 下,新建文件夹:META-INF
在目录 META-INF 下新建文件 services.xml
services.xml 的内容如下:
<?xml version="1.0" encoding="UTF-8"?> <serviceGroup> <service name="WeatherService"> <description>WeatherService:Spring POJO Axis2 Service Sample</description> <parameter name="ServiceClass">sample.weatherservice.service.IWeatherService</pa rameter> <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>
【下载地址】
百度网盘链接:https://pan.baidu.com/s/1qCL4suU6G-7-GliAbkk9GA
提取码:977f
相关文章
使用-JFreeChart来创建基于web的图表
XStream使用文档
WebService发布过程及常见问题
webpack实战入门进阶调优分享
weblogic调优参数及监控指标
weblogic节点管理
weblogic管理控制台概述
weblogic-部署和启动
WebLogic-Server-性能及调优-调优-Java-虚拟机
Java 虚拟机(Java virtual machine,简称 JVM)是一种虚拟“执行引擎”实例,可在微处理器上执行 Java 类文件中的字节码。调整 JVM 的方式会影响 Weblogic Server 和应用程序的性能。
Velocity是一个基于java的模板引擎(template engine)。它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象。
Velocity 用户手册是帮助页面设计者和内容提供者认识 Velocity 和其简单而功能强大的脚本语言――Velocity 模板语言(VTL)。在手册上的许多例子,都是用 Velocity 插入动态的内容到网页上,但是所有的 VLT 例子都能应用到其他的页面和模板中。
FlashFXP绿色版网盘下载,附激活教程 2667
FlashFxp百度网盘下载链接:https://pan.baidu.com/s/1MBQ5gkZY1TCFY8A7fnZCfQ。FlashFxp是功能强大的FTP工具
Adobe Fireworks CS6 Ansifa绿色精简版网盘下载 2513
firework可以制作精美或是可以闪瞎眼的gif,这在广告领域是需要常用的,还有firework制作下logo,一些原创的图片还是很便捷的,而且fireworks用法简单,配合dw在做网站这一块往往会发挥出很强大的效果。百度网盘下载链接:https://pan.baidu.com/s/1fzIZszfy8VX6VzQBM_bdZQ
navicat for mysql中文绿色版网盘下载 2289
Navicat for Mysql是用于Mysql数据库管理的一款图形化管理软件,非常的便捷和好用,可以方便的增删改查数据库、数据表、字段、支持mysql命令,视图等等。百度网盘下载链接:https://pan.baidu.com/s/1T_tlgxzdQLtDr9TzptoWQw 提取码:y2yq
火车头采集器(旗舰版)绿色版网盘下载 2488
火车头采集器是站长常用的工具,相比于八爪鱼,简洁好用,易于配置。火车头能够轻松的抓取网页内容,并通过自带的工具对内容进行处理。站长圈想要做网站,火车头采集器是必不可少的。百度网盘链接:https://pan.baidu.com/s/1u8wUqS901HgOmucMBBOvEA
Photoshop(CS-2015-2023)绿色中文版软件下载 2497
安装文件清单(共46G)包含Window和Mac OS各个版本的安装包,从cs到cc,从绿色版到破解版,从安装文件激活工具,应有尽有,一次性打包。 Photoshop CC绿色精简版 Photoshop CS6 Mac版 Photoshop CC 2015 32位 Photoshop CC 2015 64位 Photoshop CC 2015 MAC版 Photoshop CC 2017 64位 Adobe Photoshop CC 2018 Adobe_Photoshop_CC_2018 Photoshop CC 2018 Win32 Photoshop CC 2018 Win64