概述
2)设置axis2_home环境变量的值E:docWorkaxis2为:
3)将axis2下的bin加入到path路径下面(目的是可以在doc窗口中执行java2wsdl或者其他的一些axis2的命令):
4创建工程enviross,创建如图中所示的目录结构:
CooperationWS.java类的内容:
BaseResponseVo.java和BaseRequestVO.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);
}
}
}
CooperationResponse.java和CooperationRequest.java根据自己所需要的请求参数和返回响应的参数进行设置,
如CooperationResponse类的内容:
CooperationRequest类: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;
}
}
WSUtil.java是一个工具类: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;
}
}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实现类:
5)鉴于日志的篇幅有限,请继续观看本人的日志--- 用axis2制作webservice的过程(2)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");
}
}
最后
以上就是妩媚丝袜为你收集整理的用axis2制作webservice的过程(1)的全部内容,希望文章能够帮你解决用axis2制作webservice的过程(1)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复