web.xml 里配置使用cxf发布的
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
访问时使用http://localhost:8082/2BMPM/rdmuWS?wsdl<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/rdmuWS/*</url-pattern>
</servlet-mapping>
maven
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf</artifactId> <version>2.7.15</version> </dependency>
接口代码
package com.rdmu.product.webservice.pdmserver;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface IntPdmbackWeb {
@WebMethod
public String getPdmBackStatus(@WebParam(name = "bizData", targetNamespace = "http://pdmserver.webservice.product.rdmu.com/") String bizData);
@WebMethod
public String reviewInformationFeedback(@WebParam(name = "bizData", targetNamespace = "http://pdmserver.webservice.product.rdmu.com/") String bizData);
@WebMethod
public String reviewUpcomingTasks(@WebParam(name = "bizData", targetNamespace = "http://pdmserver.webservice.product.rdmu.com/") String bizData);
}
实现类
package com.rdmu.product.webservice.pdmserver;
import com.rdmu.ecubeframework.core.utils.StringUtil;
import com.rdmu.framework.common.utils.PropertyUtil;
import com.rdmu.framework.entity.Sysuser;
import com.rdmu.framework.web.system.service.SysuserService;
import com.rdmu.framework.web.system.service.WebServiceLogService;
import com.rdmu.product.entity.*;
import com.rdmu.product.web.PlanwebClient.services.JavaToXmlPlanService;
import com.rdmu.product.web.mywork.services.TaskApproveInfoService;
import com.rdmu.product.web.pm.services.PlanService;
import com.rdmu.product.web.pm.services.ProjectDocService;
import com.rdmu.product.web.pm.services.SummaryService;
import com.rdmu.product.web.revenueBudget.services.ProjectRevenueInfoService;
import com.rdmu.product.web.revenueBudget.services.RevenuePortService;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@Component
@Transactional
public class IntPdmbackWebImpl implements IntPdmbackWeb {
@Autowired
private PlanService planService;
@Autowired
private JavaToXmlPlanService javaToXmlPlanService;
@Autowired
private ProjectDocService projectDocService;
@Autowired
private RevenuePortService revenuePortService;
@Autowired
private ProjectRevenueInfoService projectRevenueInfoService;
@Autowired
private TaskApproveInfoService taskApproveInfoService;
@Autowired
private SummaryService summaryService;
@Autowired
private WebServiceLogService webServiceLogService;
@Autowired
private SysuserService sysuserService;
@Override
public String getPdmBackStatus(String bizData) {
webServiceLogService.genWebServiceLog("","",bizData,"","Pdm修改任务状态","");
String num = null;
String result=null;
String newbizData = bizData.trim();
try {
Document personDoc = DocumentHelper.parseText(newbizData);
Element rootElt = personDoc.getRootElement(); // 获取根节点
System.out.println("根节点:" + rootElt.getName()); // 拿到根节点的名称
Iterator body = rootElt.elementIterator("list");
while (body.hasNext()) {
Element task = (Element) body.next();
Iterator tasks = task.elementIterator("task");
while (tasks.hasNext()){
Element Datas = (Element) tasks.next();
Iterator delivrylist = Datas.elementIterator("delivrylist");
List<ProjectTasks>projectTasksList=this.planService.find("from ProjectTasks ps where ps.id = ? ",Datas.elementTextTrim("taskID"));
if(projectTasksList.size()>0&&projectTasksList!=null){
for(ProjectTasks projectTask :projectTasksList){
if(Datas.elementTextTrim("taskStatus").equals("6005")){
projectTask.setStatus(ProjectTasks.STARTING);
}
if(Datas.elementTextTrim("taskStatus").equals("6007")){
projectTask.setStatus("6007");
projectTask.setCustomItem2("0");
projectTask.setProgress(100);
}
//进度
if(stringUtil(Datas.elementTextTrim("taskProgress"))!=null){
projectTask.setProgress(Integer.valueOf(Datas.elementTextTrim("taskProgress")));
}
//开始时间
if(stringUtil(getDate(Datas.elementTextTrim("realBeginTime")))!=null){
projectTask.setRealBeginDate(getDate(Datas.elementTextTrim("realBeginTime")));
}
//结束时间
if(stringUtil(getDate(Datas.elementTextTrim("realEndTime")))!=null){
projectTask.setRealEndDate(getDate(Datas.elementTextTrim("realEndTime")));
}
//交付物路径
while (delivrylist.hasNext()) {
Element delivery = (Element) delivrylist.next();
Iterator deliverys = delivery.elementIterator("delivery");
while (deliverys.hasNext()){
Element data = (Element) deliverys.next();
if(StringUtil.validateString(data.elementTextTrim("docName"))){
ActivityOResult activityOResult=new ActivityOResult();
activityOResult.setProjectTasks(projectTask);
activityOResult.setName(data.elementTextTrim("docName"));
activityOResult.setCreateUser(this.planService.getTaskSysuserById(data.elementTextTrim("taskID")));
activityOResult.setCustomItem2(data.elementTextTrim("docUrl").replaceAll("喆","&"));
this.planService.save(activityOResult);
ProjectDoc projectDoc = new ProjectDoc();
projectDoc.setProjectTasks(projectTask);
projectDoc.setDocName(data.elementTextTrim("docName"));
projectDoc.setDocSubmitTime(new Date());
projectDoc.setDocType("5011");
projectDoc.setActivityOResult(activityOResult);
projectDoc.setSysuser(this.planService.getTaskSysuserById(data.elementTextTrim("taskID")));
this.projectDocService.save(projectDoc);
}
}
}
this.planService.save(projectTask);
planService.calculateParentProgress(projectTask);//计算百分比
Properties p = PropertyUtil.initPropertiesFile("system.properties");
String http = p.getProperty("systemName");
this.summaryService.setPlanProcessApprove(projectTask, http);
}
}
}
}
result=javaToXmlPlanService.buildResult("0");
} catch (DocumentException e) {
e.printStackTrace();
result=javaToXmlPlanService.buildResult("1");
}
return result;
}
public Date getDate(String stringdate){
Date date = null;
try {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
date =sf.parse(stringdate);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
public String stringUtil (Object obj){
String str= null;
if(obj!=null){
str=obj.toString();
}
return str;
}
//Pdm反馈评审信息
@Override
public String reviewInformationFeedback(String bizData) {
webServiceLogService.genWebServiceLog("","",bizData,"","PDM反馈评审信息","");
String num = null;
String result=null;
String newbizData = bizData.trim();//去掉字符串两端的多余的空格
try {
Document personDoc = DocumentHelper.parseText(newbizData);
Element Datas = personDoc.getRootElement(); // 获取根节点
// Iterator body = rootElt.elementIterator("isLeftProblem");
Iterator body = Datas.elementIterator("taskId");
// Element Datas = (Element) body.next();
//评审信息反馈表
// ReviewInformation reviewInformationNew = new ReviewInformation();
//任务id不能为空
if(StringUtil.validateString(Datas.elementTextTrim("taskId"))){
List<ProjectTasks> projectTasksList=this.planService.find("from ProjectTasks ps where ps.id = ? ",Datas.elementTextTrim("taskId"));
List<ReviewInformation> reviewInformations =this.planService.find("from ReviewInformation rf where rf.reviewNumber = ? ",Datas.elementTextTrim("reviewNumber"));
ReviewInformation reviewInformation;
if (reviewInformations.size()>0){
reviewInformation = reviewInformations.get(0);
}else {
reviewInformation = new ReviewInformation();
}
if(projectTasksList.size()>0){
try {
reviewInformation.setProjectTasks(projectTasksList.get(0));
//型号类别
reviewInformation.setModelType(Datas.elementTextTrim("modelType"));
//阶段标识
reviewInformation.setPhase(Datas.elementTextTrim("phase"));
//评审名称
reviewInformation.setReviewName(Datas.elementTextTrim("reviewName"));
//评审时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (StringUtil.validateString(Datas.elementTextTrim("reviewTime"))) {
try {
reviewInformation.setReviewTime(sdf.parse(timeStrToDateStr(Datas.elementTextTrim("reviewTime"))));
} catch (ParseException e) {
result = javaToXmlPlanService.buildResult("4");
e.printStackTrace();
return result;
}
}
//评审级别
reviewInformation.setReviewLev(Datas.elementTextTrim("reviewLev"));
//评审类别
reviewInformation.setReviewClasses(Datas.elementTextTrim("reviewClasses"));
//评审类型
reviewInformation.setReviewType(Datas.elementTextTrim("reviewType"));
//评审形式
reviewInformation.setReviewForm(Datas.elementTextTrim("reviewForm"));
//评审单号
reviewInformation.setReviewNumber(Datas.elementTextTrim("reviewNumber"));
//组织单位
reviewInformation.setOrgDepart(Datas.elementTextTrim("orgDepart"));
//评审组长
if (StringUtil.validateString(Datas.elementTextTrim("reviewGroup"))) {
// Sysuser reviewGroup = this.sysuserService.get(Datas.elementTextTrim("reviewGroup"));
Sysuser reviewGroup = this.sysuserService.findUnique("select p from Sysuser p where p.pid=?", Datas.elementTextTrim("reviewGroup"));
if (reviewGroup != null) {
reviewInformation.setReviewGroup(reviewGroup);
} else {
// reviewInformation.setReviewGroup(new Sysuser());
}
}
//有无专家意见
if (StringUtil.validateString(Datas.elementTextTrim("isLeftProblem"))) {
reviewInformation.setIsLeftProblem(Integer.parseInt(Datas.elementTextTrim("isLeftProblem")));
}
//评审结果
reviewInformation.setReviewResult(Datas.elementTextTrim("reviewResult"));
//项目主管
if (StringUtil.validateString(Datas.elementTextTrim("reviewLeader"))) {
// Sysuser reviewLeader = this.sysuserService.get(Datas.elementTextTrim("reviewLeader"));
Sysuser reviewLeader = this.sysuserService.findUnique("select p from Sysuser p where p.pid=?", Datas.elementTextTrim("reviewLeader"));
if (reviewLeader != null) {
reviewInformation.setReviewLeader(reviewLeader);
} else {
// reviewInformation.setReviewLeader(new Sysuser());
}
}
//实际评审费用
if (StringUtil.validateString(Datas.elementTextTrim("reviewCharge"))) {
reviewInformation.setReviewCharge(Double.parseDouble(Datas.elementTextTrim("reviewCharge")));
}
//成本类别
reviewInformation.setCostType(Datas.elementTextTrim("costType"));
//是否一次通过
if (StringUtil.validateString(Datas.elementTextTrim("isFirstPass"))) {
reviewInformation.setIsFirstPass(Integer.parseInt(Datas.elementTextTrim("isFirstPass")));
}
this.planService.save(reviewInformation);
result = javaToXmlPlanService.buildResult("0");
} catch (Exception e) {
result=javaToXmlPlanService.buildResult("5");
e.printStackTrace();
}
}else{
result=javaToXmlPlanService.buildResult("3");
}
}else{
result=javaToXmlPlanService.buildResult("2");
}
} catch (DocumentException e) {
e.printStackTrace();
result=javaToXmlPlanService.buildResult("1");
}
return result;
}
//PDM反馈评审中的待办任务回MPM系统
@Override
public String reviewUpcomingTasks(String bizData) {
webServiceLogService.genWebServiceLog("","",bizData,"","PDM反馈评审中的待办任务回MPM系统","");
String num = null;
String result=null;
String newbizData = bizData.trim();//去掉字符串两端的多余的空格
try {
Document personDoc = DocumentHelper.parseText(newbizData);
Element rootElt = personDoc.getRootElement(); // 获取根节点
Iterator<Element> body = rootElt.elementIterator("question");
while (body.hasNext()){
Element Datas = (Element) body.next();
//评审中的待办任务反馈表
//评审单号不能为空
if(StringUtil.validateString(Datas.elementTextTrim("reviewNumber"))){
ReviewUpcomingTasks reviewUpcomingTasks;
List<ReviewInformation> reviewInformationList=this.planService.find("from ReviewInformation R where R.reviewNumber = ? ",Datas.elementTextTrim("reviewNumber"));
if(reviewInformationList.size()>0){
try {
reviewUpcomingTasks =this.planService.findUnique("from ReviewUpcomingTasks ru where ru.customItem1 = ? ",Datas.elementTextTrim("ID"));
if (reviewUpcomingTasks==null){
reviewUpcomingTasks = new ReviewUpcomingTasks();
}
reviewUpcomingTasks.setCustomItem1(Datas.elementTextTrim("ID"));
reviewUpcomingTasks.setReviewInformation(reviewInformationList.get(0));
//专家意见
reviewUpcomingTasks.setExpertIdea(Datas.elementTextTrim("expertIdea"));
//提出人
if(StringUtil.validateString(Datas.elementTextTrim("introducer"))){
// Sysuser dutyPer = this.sysuserService.get(Datas.elementTextTrim("dutyPer"));
Sysuser introducer = this.sysuserService.findUnique("select p from Sysuser p where p.pid=?",Datas.elementTextTrim("introducer"));
if(introducer != null){
reviewUpcomingTasks.setIntroducer(introducer);
}else{
// reviewUpcomingTasks.setIntroducer(new Sysuser());
}
}
//提出时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if(StringUtil.validateString(Datas.elementTextTrim("applyTime"))){
try {
reviewUpcomingTasks.setApplyTime(sdf.parse(timeStrToDateStr(Datas.elementTextTrim("applyTime"))));
} catch (ParseException e) {
result=javaToXmlPlanService.buildResult("4");
e.printStackTrace();
return result;
}
}
//责任部门
reviewUpcomingTasks.setResDepart(Datas.elementTextTrim("resDepart"));
//责任人
if(StringUtil.validateString(Datas.elementTextTrim("dutyPer"))){
// Sysuser dutyPer = this.sysuserService.get(Datas.elementTextTrim("dutyPer"));
Sysuser dutyPer = this.sysuserService.findUnique("select p from Sysuser p where p.pid=?",Datas.elementTextTrim("dutyPer"));
if(dutyPer != null){
reviewUpcomingTasks.setDutyPer(dutyPer);
}else{
// reviewUpcomingTasks.setDutyPer(new Sysuser());
}
}
//是否采纳
if(StringUtil.validateString(Datas.elementTextTrim("isPass"))){
reviewUpcomingTasks.setIsPass(Integer.parseInt(Datas.elementTextTrim("isPass")));
}
//不采纳情况说明
reviewUpcomingTasks.setAdoptExplain(Datas.elementTextTrim("adoptExplain"));
//问题落实情况说明
reviewUpcomingTasks.setProExplain(Datas.elementTextTrim("proExplain"));
//遗留到下阶段解决的事项
reviewUpcomingTasks.setLeftoverExplain(Datas.elementTextTrim("leftoverExplain"));
//问题落实时间
if(StringUtil.validateString(Datas.elementTextTrim("proTime"))){
try {
reviewUpcomingTasks.setProTime(sdf.parse(timeStrToDateStr(Datas.elementTextTrim("proTime"))));
} catch (ParseException e) {
result=javaToXmlPlanService.buildResult("4");
e.printStackTrace();
return result;
}
}
//验证情况
reviewUpcomingTasks.setVerifyState(Datas.elementTextTrim("verifyState"));
//验证时间
if(StringUtil.validateString(Datas.elementTextTrim("verifyTime"))){
try {
reviewUpcomingTasks.setVerifyTime(sdf.parse(timeStrToDateStr(Datas.elementTextTrim("verifyTime"))));
} catch (ParseException e) {
result=javaToXmlPlanService.buildResult("4");
e.printStackTrace();
return result;
}
}
//组织单位
reviewUpcomingTasks.setStatus(Datas.elementTextTrim("status"));
this.planService.save(reviewUpcomingTasks);
result=javaToXmlPlanService.buildResult("0");
} catch (Exception e) {
//字段类型不匹配
result=javaToXmlPlanService.buildResult("5");
e.printStackTrace();
}
}else{
//评审单号查不到数据
result=javaToXmlPlanService.buildResult("3");
}
}else{
//评审单号不能为空
result=javaToXmlPlanService.buildResult("2");
}
}
} catch (DocumentException e) {
e.printStackTrace();
result=javaToXmlPlanService.buildResult("1");
}
return result;
}
public static String timeStrToDateStr(String timeStr){
if (null == timeStr) {
return null;
}
String dateStr = null;
SimpleDateFormat sdf_input = new SimpleDateFormat("yyyyMMdd");//输入格式
SimpleDateFormat sdf_target =new SimpleDateFormat("yyyy-MM-dd"); //转化成为的目标格式
try {
//将20160325160000转化为Fri Mar 25 16:00:00 CST 2016,再转化为2016-03-25 16:00:00
dateStr = sdf_target.format(sdf_input.parse(timeStr));
} catch (Exception e) {
}
return dateStr;
}
}
Spring核心配置文件里的代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
default-lazy-init="true">
接口发布需要代码
id随便起名,class为实现类
<bean id="pdmPorts" class="com.rdmu.product.webservice.pdmserver.IntPdmbackWebImpl" />
address也是随便起名,bean用上面的id
<jaxws:server address="/PdmToMpmPorts">
<jaxws:serviceBean>
<ref bean="pdmPorts" />
</jaxws:serviceBean>
</jaxws:server>
以上就是发布WebService的所有代码。