我是靠谱客的博主 妩媚丝袜,最近开发中收集的这篇文章主要介绍用axis2制作webservice的过程(1),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1)在  http://ws.apache.org/axis2/官网上面下载axis的war文件及axis2的zip包,将解压zip包后的目录放到E:docWork目录下,目录名称修改为axis2,如图:


 2)设置axis2_home环境变量的值E:docWorkaxis2为:


3)将axis2下的bin加入到path路径下面(目的是可以在doc窗口中执行java2wsdl或者其他的一些axis2的命令):


4创建工程enviross,创建如图中所示的目录结构:


CooperationWS.java类的内容:

package com.sw.sqr.webservice.cooperationWS;

import com.sw.sqr.webservice.cooperationWS.service.ICooperationService;
import com.sw.sqr.webservice.cooperationWS.service.imp.CooperationServiceImp;
import com.sw.sqr.webservice.util.WSUtil;

public class CooperationWS {
private ICooperationService CooperationService = new CooperationServiceImp();

public CooperationResponse queryStaticPage(CooperationRequest request) {
CooperationResponse response = new CooperationResponse();
try {
CooperationService.getCooperationById(request, response);
return WSUtil.responseSuccess(response, "查询成功");
} catch (Exception e) {
return WSUtil.responseError(response, e);
}
}
}

BaseResponseVo.java和BaseRequestVO.java是一个扩展类,现在可以没有任何属性和方法,可根据实际情况进行扩展。
CooperationResponse.java和CooperationRequest.java根据自己所需要的请求参数和返回响应的参数进行设置,
如CooperationResponse类的内容:

package com.sw.sqr.webservice.cooperationWS;
import com.sw.sqr.webservice.response.BaseResponseVO;
public class CooperationResponse extends BaseResponseVO{
private Integer cooperationId;
private String cooperationName;
private String chairManName;
private String chairManIdCard;
private String chairManSex ;
private String chairManEducationLevel;
public Integer getCooperationId() {
return cooperationId;
}
public void setCooperationId(Integer cooperationId) {
this.cooperationId = cooperationId;
}
public String getCooperationName() {
return cooperationName;
}
public void setCooperationName(String cooperationName) {
this.cooperationName = cooperationName;
}
public String getChairManName() {
return chairManName;
}
public void setChairManName(String chairManName) {
this.chairManName = chairManName;
}
public String getChairManIdCard() {
return chairManIdCard;
}
public void setChairManIdCard(String chairManIdCard) {
this.chairManIdCard = chairManIdCard;
}
public String getChairManSex() {
return chairManSex;
}
public void setChairManSex(String chairManSex) {
this.chairManSex = chairManSex;
}
public String getChairManEducationLevel() {
return chairManEducationLevel;
}
public void setChairManEducationLevel(String chairManEducationLevel) {
this.chairManEducationLevel = chairManEducationLevel;
}
}

CooperationRequest类:

package com.sw.sqr.webservice.cooperationWS;

public class CooperationRequest extends BaseRequestVO {
private String id;//静态页ID
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

WSUtil.java是一个工具类:

package com.sw.sqr.webservice.util;

import com.sw.sqr.webservice.response.BaseResponseVO;
import com.sw.sqr.webservice.util.exception.WSBaseException;

// import org.apache.log4j.Logger;
public class WSUtil {
// private static Logger log = Logger.getLogger(WSUtil.class);
public static <T extends BaseResponseVO> T responseSuccess(T response, String returnMsg) {
response.setRespCode(WSConstConfig.SUCCESS);
response.setRespDesc(returnMsg);
return response;
}

public static <T extends BaseResponseVO> T responseError(T response, Exception e) {
response.setRespCode(WSConstConfig.OTHER_ERROR);
response.setRespDesc(e.getMessage() == null ? "操作失败!" : e.getMessage());
// log.error(e.getMessage(), e);
return response;
}

public static <T extends BaseResponseVO> T responseError(T response, String returnCode, String returnMsg) {
response.setRespCode(returnCode);
response.setRespDesc(returnMsg);
// log.error(returnMsg);
return response;
}

public static <T extends BaseResponseVO> T responseError(T response, WSBaseException e) {
response.setRespCode(e.getResultCode());
response.setRespDesc(e.getMessage());
// log.error(e.getMessage(), e);
return response;
}
}


 ICooperationService.java接口和 CooperationServiceImp.java实现类:

package com.sw.sqr.webservice.cooperationWS.service.imp;
import com.sw.sqr.webservice.cooperationWS.CooperationRequest;
import com.sw.sqr.webservice.cooperationWS.CooperationResponse;
import com.sw.sqr.webservice.cooperationWS.service.ICooperationService;
public class CooperationServiceImp implements ICooperationService {
public void getCooperationById(CooperationRequest request, CooperationResponse response) throws Exception {
System.out.println(request.getId());//可以根据webservice传入的request的id属性,进行相应的业务操作,如根据这个id属性值从数据库中取得一条完整的记录,放入response中相应给webservice客户端

//此处因为是演示程序,没有做具体的业务处理。

response.setChairManEducationLevel("eee");
response.setChairManIdCard("kkkk");
response.setChairManName("lll");
response.setChairManSex("bbbb");
response.setCooperationId(255);
response.setCooperationName("cooperationName");
}
}

5)鉴于日志的篇幅有限,请继续观看本人的日志--- 用axis2制作webservice的过程(2)

最后

以上就是妩媚丝袜为你收集整理的用axis2制作webservice的过程(1)的全部内容,希望文章能够帮你解决用axis2制作webservice的过程(1)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部