昨天做了使用axis2做客户端的示例,今天来做使用axis2发布自己的服务。首先到官方下载axis2-1.6.1-war.zip,解压后会得到能够在tomcat上部署的war文件,部署后可以在基于该工程的情况下进行我们的服务发布。我的附件中给的工程可以直接部署到tocmat下,由于上传限制,我删除了lib下的所有包,大家可以将下载的包中的jar拷贝到该工程里面,另外还需要拷贝spring.jar。
如果是做接口测试想快速做一个接口以供调用,可以在WEB-INF下创建一个pojo文件夹,然后将自己的类放到该文件夹下面即可完成发布。示例工程里面的MyAxis2Service.class源码是:
Java代码
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 这个是作为服务端的方法类,不能带有命名空间,方法必须为public
*/
public class MyAxis2Service {
/*
* 请求的方法,输出接收到的参数,返回时间戳字符串
*/
public String getServiceInit(String name){
System.out.println("you name is :" + name);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(new Date());
}
// 下载图像
public byte[] dowImageWithByte() {
byte[] imageByte = null;
try {
// 下面的代码调用uploadImageWithByte方法上传图像文件
// 打开图像文件,确定图像文件的大小
java.io.File file = new java.io.File("c:\\test.jpg");
java.io.FileInputStream fis = new java.io.FileInputStream("c:\\test.jpg");
// 创建保存要上传的图像文件内容的字节数组
imageByte = new byte[(int) file.length()];
fis.read(imageByte);
} catch (Exception e) {
return null;
} finally {
}
return imageByte;
}
// 上传图像,imageByte参数表示上传图像文件的字节,
// length参数表示图像文件的字节长度(该参数值可能小于imageByte的数组长度)
public boolean uploadImageWithByte(byte[] imageByte, int length) {
FileOutputStream fos = null;
try {
// 将上传的图像保存在D盘的test1.jpg文件中
fos = new FileOutputStream("d:\\test1.jpg");
// 开始写入图像文件的字节
fos.write(imageByte, 0, length);
fos.close();
} catch (Exception e) {
return false;
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
}
}
}
return true;
}
}
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 这个是作为服务端的方法类,不能带有命名空间,方法必须为public
*/
public class MyAxis2Service {
/*
* 请求的方法,输出接收到的参数,返回时间戳字符串
*/
public String getServiceInit(String name){
System.out.println("you name is :" + name);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(new Date());
}
// 下载图像
public byte[] dowImageWithByte() {
byte[] imageByte = null;
try {
// 下面的代码调用uploadImageWithByte方法上传图像文件
// 打开图像文件,确定图像文件的大小
java.io.File file = new java.io.File("c:\\test.jpg");
java.io.FileInputStream fis = new java.io.FileInputStream("c:\\test.jpg");
// 创建保存要上传的图像文件内容的字节数组
imageByte = new byte[(int) file.length()];
fis.read(imageByte);
} catch (Exception e) {
return null;
} finally {
}
return imageByte;
}
// 上传图像,imageByte参数表示上传图像文件的字节,
// length参数表示图像文件的字节长度(该参数值可能小于imageByte的数组长度)
public boolean uploadImageWithByte(byte[] imageByte, int length) {
FileOutputStream fos = null;
try {
// 将上传的图像保存在D盘的test1.jpg文件中
fos = new FileOutputStream("d:\\test1.jpg");
// 开始写入图像文件的字节
fos.write(imageByte, 0, length);
fos.close();
} catch (Exception e) {
return false;
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
}
}
}
return true;
}
}
其实就是昨天的那个类。访问http://localhost:8080/axis2/,可以看到axis2后台管理页面,点击services进入服务列表。其中version是默认的一个接口。
以上方法固然方便,不过不能定义自己的包路径。下面来做一下包含包路径的pojo发布。
首先定义类:
Java代码
package service;
public class MyService {
/**
* 接收参数,有返回值
*/
public String getGreeting(String name) {
return "您好 " + name;
}
/**
* 接收参数,无返回值
*/
public void update(String data) {
System.out.println("<" + data + ">已经更新");
}
}
package service;
public class MyService {
/**
* 接收参数,有返回值
*/
public String getGreeting(String name) {
return "您好 " + name;
}
/**
* 接收参数,无返回值
*/
public void update(String data) {
System.out.println("<" + data + ">已经更新");
}
}
再定义一个类,为了演示不同的配置方法:
Java代码
package service;
public class MyServiceForGroup {
/**
* 接收参数,有返回值
*/
public String getGreeting2(String name) {
return "你真好 " + name;
}
/**
* 接收参数,无返回值
*/
public void update2(String data) {
System.out.println("<" + data + ">真的已经更新");
}
}
package service;
public class MyServiceForGroup {
/**
* 接收参数,有返回值
*/
public String getGreeting2(String name) {
return "你真好 " + name;
}
/**
* 接收参数,无返回值
*/
public void update2(String data) {
System.out.println("<" + data + ">真的已经更新");
}
}
下面再定义一个XML配置文件,定义一个services.xml,在里面增加内容:
Xml代码
<serviceGroup>
<!-- name 属性就是发布 webservice 的访问名称,一个service代表一个服务,每个服务内可包含多个方法 -->
<service name="myService">
<!-- 描述 -->
<description>Web Service</description>
<!-- 指定服务类 -->
<parameter name="ServiceClass">service.MyService</parameter>
<!-- 用 operation 指定每一个方法的服务处理器 -->
<!-- 服务端使用什么样的方式发布WebService,对客户端并没有影响 -->
<operation name="getGreeting">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<operation name="update">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</operation>
</service>
<!-- 演示多个接口的配置方法 -->
<service name="MyServiceForGroup">
<description>Web Service2</description>
<parameter name="ServiceClass">
service.MyServiceForGroup
</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
<messageReceiver
mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</messageReceivers>
</service>
</serviceGroup>
<serviceGroup>
<!-- name 属性就是发布 webservice 的访问名称,一个service代表一个服务,每个服务内可包含多个方法 -->
<service name="myService">
<!-- 描述 -->
<description>Web Service</description>
<!-- 指定服务类 -->
<parameter name="ServiceClass">service.MyService</parameter>
<!-- 用 operation 指定每一个方法的服务处理器 -->
<!-- 服务端使用什么样的方式发布WebService,对客户端并没有影响 -->
<operation name="getGreeting">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageRe
没有合适的资源?快使用搜索试试~ 我知道了~
axis2发布webservice各种方式实例
共85个文件
jsp:39个
class:13个
mar:7个
5星 · 超过95%的资源 需积分: 33 48 下载量 91 浏览量
2011-12-29
23:53:36
上传
评论
收藏 273KB ZIP 举报
温馨提示
具体请查看文本文件,已经附带了示例工程,讲解了三种发布方式,包括spring发布方式
资源推荐
资源详情
资源评论
收起资源包目录
axis2.zip (85个子文件)
axis2
WEB-INF
conf
axis2.xml 26KB
pojo
MyAxis2Service.class 3KB
services
version-1.6.1.aar 8KB
ws.aar 2KB
wss.aar 728B
services.list 18B
applicationContext.xml 368B
modules
mex-1.6.1.mar 33KB
addressing-1.6.1.mar 30KB
axis2-jaxws-mar-1.6.1.mar 9KB
scripting-1.6.1.mar 28KB
modules.list 139B
ping-1.6.1.mar 13KB
soapmonitor-1.6.1.mar 11KB
mtompolicy-1.6.1.mar 14KB
classes
service
SpringService.class 654B
log4j.properties 2KB
META-INF
LICENSE 11KB
NOTICE 1KB
commons-logging.properties 1KB
org
apache
axis2
webapp
AdminAgent.class 18KB
AxisAdminServlet.class 2KB
transport
http
AxisAdminServlet.class 1KB
lib
web.xml 2KB
data
DataForm.class 767B
axis2-web
globalModules.jsp 2KB
ViewServiceHandlers.jsp 6KB
upload.jsp 3KB
ActivateService.jsp 3KB
admin.jsp 1KB
ListServiceGroup.jsp 3KB
viewphases.jsp 4KB
error.jsp 1KB
InActivateService.jsp 3KB
index.jsp 2KB
TopFrame.jsp 1KB
ServiceParaEdit.jsp 5KB
images
axis_l.jpg 12KB
asf-logo.gif 6KB
axis.jpg 3KB
axis.gif 2KB
listFaultyService.jsp 4KB
SelectService.jsp 4KB
EngageToServiceGroup.jsp 5KB
MainFrame.jsp 1KB
listSingleService.jsp 4KB
listGroupService.jsp 4KB
listServices.jsp 5KB
disengage.jsp 1KB
errorModule.jsp 1KB
listModules.jsp 3KB
engagingtoaservice.jsp 5KB
viewServiceGroupContext.jsp 2KB
engagingglobally.jsp 3KB
deleteService.jsp 1KB
engagingtoanoperation.jsp 5KB
ViewGlobalHandlers.jsp 5KB
css
axis-style.css 2KB
LeftFrame.jsp 5KB
HappyAxis.jsp 17KB
viewServiceContext.jsp 2KB
listService.jsp 6KB
Error
error404.jsp 2KB
GenError.html 1KB
AuthError.html 2KB
error500.jsp 2KB
Login.jsp 3KB
ViewContexts.jsp 3KB
include
adminheader.inc 1KB
adminfooter.inc 903B
footer.inc 1KB
link-footer.jsp 3KB
httpbase.jsp 3KB
adminheader.jsp 4KB
header.inc 1KB
link-footer.inc 927B
axis2发布webservice各种方式实例.txt 12KB
META-INF
MANIFEST.MF 126B
org
apache
axis2
soapmonitor
applet
SOAPMonitorApplet$ServiceFilterPanel.class 5KB
SOAPMonitorApplet$SOAPMonitorData.class 2KB
SOAPMonitorApplet$SOAPMonitorFilter.class 5KB
SOAPMonitorApplet$SOAPMonitorTextArea.class 3KB
SOAPMonitorApplet$SOAPMonitorPage.class 13KB
SOAPMonitorApplet.class 4KB
SOAPMonitorApplet$SOAPMonitorTableModel.class 6KB
共 85 条
- 1
java小强
- 粉丝: 49
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- #P0015. 全排列 超级简单
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页