问题的产生:
上班写了一个改接口的需求,其中涉及了一个WSDL这么一个概念
WSDL是个啥???? 翻了翻项目,里面就是个文件,以wsdl为后缀名
内容结构和XML相似,或者直接说是XML文件也可以
线索分析:
首先这个文件是放在Java包中的,这很神奇,一般Java包中只会存放Java文件
在这个项目中,wsdl文件也放在Java包中
所在的模块:wsdl所存在的位置是放在Interface模块中,也就是说,WSDL文件是和接口相关的
我们随意全文查找一个接口的信息来看看:
SD08本身:
package com.yonyou.dcs.intf.server.SD08; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** * <p>anonymous complex type的 Java 类。 * * <p>以下模式片段指定包含在此类中的预期内容。 * * <pre> * <complexType> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="in" type="{http://www.w3.org/2001/XMLSchema}string"/> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "in" }) @XmlRootElement(name = "SD08") public class SD08 { @XmlElement(required = true) protected String in; /** * 获取in属性的值。 * * @return * possible object is * {@link String } * */ public String getIn() { return in; } /** * 设置in属性的值。 * * @param value * allowed object is * {@link String } * */ public void setIn(String value) { this.in = value; } }
SD08Request:
package com.yonyou.dcs.intf.server.SD08; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; /** * <p>SD08_Request complex type?? Java ?? * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "SD08_Request", propOrder = { "vin", "engineNo", "modelCode", "productDate", "factoryDate", "saleDate", "maintainHandbookNo", "gearBoxManufactor", "gearBoxModel", "gearBoxNo", "frontAxleManufactor", "frontAxleModel", "frontAxleNo", "middleAxleManufactor", "middleAxleModel", "middleAxleNo", "rearAxleManufactor", "rearAxleModel", "rearAxleNo", "tbox", "engineTypeInfo" }) public class SD08Request { @XmlElement(required = true) protected String vin; @XmlElement(required = true) protected String engineNo; @XmlElement(required = true) protected String modelCode; @XmlElement(required = true) protected String productDate; @XmlElement(required = true) protected String factoryDate; @XmlElement(required = true) protected String saleDate; @XmlElement(required = true) protected String maintainHandbookNo; @XmlElement(required = true) protected String gearBoxManufactor; @XmlElement(required = true) protected String gearBoxModel; @XmlElement(required = true) protected String gearBoxNo; @XmlElement(required = true) protected String frontAxleManufactor; @XmlElement(required = true) protected String frontAxleModel; @XmlElement(required = true) protected String frontAxleNo; @XmlElement(required = true) protected String middleAxleManufactor; @XmlElement(required = true) protected String middleAxleModel; @XmlElement(required = true) protected String middleAxleNo; @XmlElement(required = true) protected String rearAxleManufactor; @XmlElement(required = true) protected String rearAxleModel; @XmlElement(required = true) protected String rearAxleNo; @XmlElement(required = true) protected String tbox; @XmlElement(required = true) protected String engineTypeInfo;
SD08Response:
package com.yonyou.dcs.intf.server.SD08; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "out" }) @XmlRootElement(name = "SD08Response") public class SD08Response { @XmlElement(required = true) protected String out; /** */ public String getOut() { return out; } /** */ public void setOut(String value) { this.out = value; } }
最核心的代码是这个 【SD08SOAPImpl】
在这个部分调用了这个方法:
/** * Please modify this class to meet your needs * This class is not complete */ package com.yonyou.dcs.intf.server.action; import java.sql.Timestamp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import com.yonyou.dcs.intf.dto.IntfOprtMsgDTO; import com.yonyou.dcs.intf.server.SD08.SAPDMS08Type; import com.yonyou.dcs.intf.server.SD08.SD08Request; import com.yonyou.dcs.intf.server.SD08.SD08Response; import com.yonyou.dcs.intf.server.service.SD08ServImpl; /** * This class was generated by Apache CXF 3.1.11 2017-06-07T10:50:58.568+08:00 * Generated source version: 3.1.11 * * 车辆库接口 * * 表 :tm_vehicle_base 所属微服vehCusView * * 新加字段表中未添加 * */ @javax.jws.WebService(serviceName = "SAP_DMS_08", portName = "SAP_DMS_08Port", targetNamespace = "http://wsServer.jmc.eai.infoservice.com/SAP_DMS_08/", wsdlLocation = "classpath:/com/yonyou/dcs/intf/server/wsdl/SD08.wsdl", endpointInterface = "com.yonyou.dcs.intf.server.SD08.SAPDMS08Type") public class SD08SOAPImpl implements SAPDMS08Type { private static final Logger logger = LoggerFactory .getLogger(SD08SOAPImpl.class); private Timestamp startTime; private Timestamp endTime; @Autowired private SD08ServImpl serv; public com.yonyou.dcs.intf.server.SD08.SD08Response sd08( SD08Request sd08Request) { com.yonyou.dcs.intf.server.SD08.SD08Response _return = new SD08Response(); logger.info("Executing operation sd08"); // 判断数据是否为空 if (sd08Request == null) { return _return; } logger.info("sd08 start"); // try { startTime = new Timestamp(System.currentTimeMillis()); IntfOprtMsgDTO oprtMsg = serv.processData(sd08Request); endTime = new Timestamp(System.currentTimeMillis()); serv.addSd08Record(sd08Request, oprtMsg, startTime, endTime);// 时间日志 logger.info("sd08 end"); return _return; // } catch (java.lang.Exception ex) { // ex.printStackTrace(); // throw new RuntimeException(ex); // } } }
在ServeImpl中:
package com.yonyou.dcs.intf.server.service; import java.sql.Timestamp; import java.util.List; import java.util.Map; import com.yonyou.dcs.intf.po.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.yonyou.dcs.common.Constant; import com.yonyou.dcs.common.bean.ElemBean; import com.yonyou.dcs.common.util.CommonUtils; import com.yonyou.dcs.common.util.POUtil; import com.yonyou.dcs.common.util.ThrowableUtil; import com.yonyou.dcs.intf.common.BaseTxn; import com.yonyou.dcs.intf.common.IntfConstans; import com.yonyou.dcs.intf.common.MsgSendServImpl; import com.yonyou.dcs.intf.dto.IntfOprtMsgDTO; import com.yonyou.dcs.intf.server.SD08.SD08Request; import com.yonyou.dcs.intf.server.dao.SD08DAO; @Service public class SD08ServImpl { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private BaseTxn bt; @Autowired private SD08DAO dao; @Autowired private POUtil poUtil; @Autowired private RecvServImpl recvServ; @Autowired private MsgSendServImpl msgSendServ; public IntfOprtMsgDTO processData(SD08Request sd08Request) { IntfOprtMsgDTO retMsg = null; Long baseId = null; try { // Long companyId = getFactoryCompanyOfModel(sd08Request.getModelCode()); ElemBean companyInfo = getFactoryCompanysOfModel(sd08Request.getModelCode()); bt.beginTxn(IntfConstans.TXN_VEHCUSVIEW, IntfConstans.JNDI_VEHCUSVIEW);// 开启事物 TmVehicleBasePO vehBaseInfo = dao.queryVehicleBaseByVin(sd08Request .getVin()); TmEngineInfoPO engineInfo = dao.queryEngineInfoByVin(sd08Request .getVin()); if (vehBaseInfo != null) { setCommonField(sd08Request, vehBaseInfo, companyInfo.getLong("realCompanyId")); dao.modifyVehicleBase(vehBaseInfo); retMsg = new IntfOprtMsgDTO(Constant.INTF_OPRT_STATUS_UPTSUC, "修改成功"); } else { vehBaseInfo = new TmVehicleBasePO(); setCommonField(sd08Request, vehBaseInfo, companyInfo.getLong("realCompanyId")); vehBaseInfo = dao.addVehicleBase(vehBaseInfo); retMsg = new IntfOprtMsgDTO(Constant.INTF_OPRT_STATUS_ADDSUC, "新增成功"); } if (null != engineInfo) { setCommonFieldForEngineInfo(sd08Request, engineInfo); dao.modifyEngineInfo(engineInfo); // retMsg = new IntfOprtMsgDTO(Constant.INTF_OPRT_STATUS_UPTSUC,"修改成功"); } else { engineInfo = new TmEngineInfoPO(); setCommonFieldForEngineInfo(sd08Request, engineInfo); dao.addEngineInfo(engineInfo); // engineInfo = // retMsg = new IntfOprtMsgDTO(Constant.INTF_OPRT_STATUS_ADDSUC,"新增成功"); } baseId = vehBaseInfo.getLongId(); // 判断是否是进出口、批售大客户,如果是要创建(如果没有)大客户信息,并将大客户与车表关联 // 增加其他公司 if(!companyInfo.isNull("otherCompanyIds")) { String[] otherCompanyIds = companyInfo.getStr("otherCompanyIds").split(","); for(String otherCompanyId : otherCompanyIds) { TrVehbaseCompanyPO trvcPO = TrVehbaseCompanyPO.findFirst("VEHICLE_BASE_ID=? AND COMPANY_ID=?", baseId, otherCompanyId); if(trvcPO != null) { trvcPO.set("VALID_STATUS", Constant.STATUS_ENABLE); trvcPO.saveIt(); } else { trvcPO = new TrVehbaseCompanyPO(); trvcPO.set("VEHICLE_BASE_ID", baseId); trvcPO.set("COMPANY_ID", otherCompanyId); trvcPO.set("VALID_STATUS", Constant.STATUS_ENABLE); trvcPO.saveIt(); } } } bt.endTxnTrue(); } catch (Exception ex) { retMsg = new IntfOprtMsgDTO(Constant.INTF_OPRT_STATUS_SYSFAL, ex.getMessage(), ThrowableUtil.getStackTraceToString(ex)); logger.error(ThrowableUtil.getStackTraceToString(ex)); bt.endTxnFalse(); } finally { bt.txnClean(); } if(baseId != null) { boolean suc = msgSendServ.sendVehicleBase(baseId); logger.info("the sd08 send vehicle_base({}) is {}", baseId, suc); } return retMsg; } @SuppressWarnings("rawtypes") private Long getFactoryCompanyOfModel(String modelCode) { Long factoryCompanyId = null; try { bt.beginTxn(IntfConstans.TXN_GMSPUBLICSERV, IntfConstans.JNDI_GMSPUBLICSERV); Map modelInfo = dao.queryModelInfo(modelCode); factoryCompanyId = modelInfo.get("COMPANY_ID") == null ? null : Long.parseLong(modelInfo.get("COMPANY_ID").toString()); bt.endTxnTrue(); } catch (Exception ex) { logger.error(ThrowableUtil.getStackTraceToString(ex)); bt.endTxnFalse(); } finally { bt.txnClean(); } return factoryCompanyId; } @SuppressWarnings("rawtypes") private ElemBean getFactoryCompanysOfModel(String modelCode) { ElemBean retBean = new ElemBean(); try { bt.beginTxn(IntfConstans.TXN_GMSPUBLICSERV, IntfConstans.JNDI_GMSPUBLICSERV); Map modelInfo = dao.queryModelInfo(modelCode); if(modelInfo != null) { retBean.put("realCompanyId", Long.parseLong(modelInfo.get("COMPANY_ID").toString())); List<TrBrandCompanyPO> trbcPOs = TrBrandCompanyPO.find("BRAND_ID=? AND VALID_STATUS=10011001", modelInfo.get("BRAND_ID")); String otherCompanyIds = ""; for(TrBrandCompanyPO trbcPO : trbcPOs) { otherCompanyIds = otherCompanyIds + ("".equals(otherCompanyIds)?"":",") + trbcPO.getString("COMPANY_ID"); } retBean.put("otherCompanyIds", otherCompanyIds); } else { retBean.put("realCompanyId", ""); retBean.put("otherCompanyIds", ""); } bt.endTxnTrue(); } catch (Exception ex) { logger.error(ThrowableUtil.getStackTraceToString(ex)); bt.endTxnFalse(); } finally { bt.txnClean(); } return retBean; } private void setCommonField(SD08Request req, TmVehicleBasePO po, Long companyId) { po.set("COMPANY_ID", companyId); po.setString("COLOR", req.getModelCode().substring(14, 16)); po.setString("VIN", req.getVin()); po.setString("ENGINE_NO", req.getEngineNo()); if (!CommonUtils.checkIsNullStr(req.getFactoryDate())) { po.set("FACTORY_DATE", req.getFactoryDate()); } po.setString("MODEL_CODE", req.getModelCode()); if (!CommonUtils.checkIsNullStr(req.getProductDate())&&!"00000000000000".equals(req.getProductDate())) { po.set("PRODUCT_DATE", req.getProductDate()); } po.setString("MAINTAIN_HANDBOOK_NO", req.getMaintainHandbookNo()); po.set("GEAR_BOX_MANUFACTOR", req.getGearBoxManufactor()); po.set("GEAR_BOX_MODEL", req.getGearBoxModel()); po.set("GEAR_BOX_NO", req.getGearBoxNo()); po.set("FRONT_AXLE_MANUFACTOR", req.getFrontAxleManufactor()); po.set("FRONT_AXLE_MODEL", req.getFrontAxleModel()); po.set("FRONT_AXLE_NO", req.getFrontAxleNo()); po.set("MIDDLE_AXLE_MANUFACTOR", req.getMiddleAxleManufactor()); po.set("MIDDLE_AXLE_MODEL", req.getMiddleAxleModel()); po.set("MIDDLE_AXLE_NO", req.getMiddleAxleNo()); po.set("REAR_AXLE_MANUFACTOR", req.getRearAxleManufactor()); po.set("REAR_AXLE_MODEL", req.getRearAxleModel()); po.set("REAR_AXLE_NO", req.getRearAxleNo()); po.set("IS_JMC", 1); po.set("IS_FACT_JMC", Constant.IF_TYPE_YES); if (!CommonUtils.checkIsNullStr(req.getTbox())&&!"Y".equals(req.getTbox())) { po.set("TBOX", Constant.IF_TYPE_YES); } } private void setCommonFieldForEngineInfo(SD08Request req, TmEngineInfoPO po) { po.setString("vin", req.getVin()); po.setString("engin_info", req.getEngineTypeInfo()); } public void addSd08Record(SD08Request sd08Request, IntfOprtMsgDTO oprtMsg, Timestamp startTime, Timestamp endTime) { try { bt.beginTxn(IntfConstans.TXN_INTF, IntfConstans.JNDI_INTF); // 日志表 TiSd08RecordPO po = new TiSd08RecordPO(); poUtil.copyToPO(sd08Request, po); po.set("HANDLE_STATUS", oprtMsg.getStatus()); po.setString("OPRT_MSG", oprtMsg.getMsg()); po.insert(); // 添加主记录 recvServ.addRecvRecord(oprtMsg, "SD08", po.getId(), startTime, endTime); bt.endTxnTrue(); } catch (Exception ex) { logger.error(ThrowableUtil.getStackTraceToString(ex)); bt.endTxnFalse(); } finally { bt.txnClean(); } } }
到了Dao中就是具体的一些表操作了【数据访问层用的是 ActiveJDBC】
package com.yonyou.dcs.intf.server.dao; import java.util.LinkedList; import java.util.List; import java.util.Map; import com.yonyou.dcs.intf.po.TmEngineInfoPO; import org.springframework.stereotype.Repository; import com.yonyou.dcs.common.util.DcsDaoUtil; import com.yonyou.dcs.intf.common.IntfConstans; import com.yonyou.dcs.intf.po.TmVehicleBasePO; @Repository public class SD08DAO { public TmVehicleBasePO queryVehicleBaseByVin(String vin) { List<TmVehicleBasePO> list = TmVehicleBasePO.find("VIN = ?", vin); return list == null || list.size() == 0 ? null : list.get(0); } public TmEngineInfoPO queryEngineInfoByVin(String vin) { List<TmEngineInfoPO> list = TmEngineInfoPO.find("VIN = ?", vin); return list == null || list.size() == 0 ? null : list.get(0); } public void modifyVehicleBase(TmVehicleBasePO po) { po.set("UPDATED_BY", IntfConstans.UPDATE_BY_OEM); po.set("QMS_IS_SCAN", 0); po.set("FORDPASS_SCAN", 0); po.saveIt(); } public void modifyEngineInfo(TmEngineInfoPO po) { po.set("UPDATED_BY", IntfConstans.UPDATE_BY_OEM); po.saveIt(); } public TmVehicleBasePO addVehicleBase(TmVehicleBasePO po) { po.setLong("IS_DELIEVE", 0); po.setString("MID_CONFIRM_FLAG", "0"); po.setLong("CREATED_BY", IntfConstans.CREATE_BY_OEM); po.insert(); return po; } public TmEngineInfoPO addEngineInfo(TmEngineInfoPO po) { po.setLong("CREATED_BY", IntfConstans.CREATE_BY_OEM); po.insert(); return po; } @SuppressWarnings("rawtypes") public Map queryModelInfo(String modelCode) { String sql = "SELECT * FROM VW_PRODUCT T WHERE T.MODEL_CODE_NEW = ?"; List<Object> params = new LinkedList<Object>(); params.add(modelCode); List<Map> list = DcsDaoUtil.findAll(IntfConstans.JNDI_GMSPUBLICSERV, sql, params); return list == null || list.size() == 0 ? null : list.get(0); } }
所以到这里可以基本得出一些结论:
WSDL用来描述,或者说定义了接口的信息
Request类描述的这个接口的数据模型是怎样的【封装数据模型】
然后SOAPI的这个类承接了Controller的功能,处理请求的数据
再往下Service层和Dao层就是实际对接数据库的实现
工作的要求:
这里有点问题就是,一般来说一个接口对应的数据库的一张表
但是需求有变动,BA让我新增一张表来存储一个新的字段,所以我要完整的看完这个流程才知道接口干了什么。
关于百度上提供的WSDL概念我真没懂
越看我是越晕,我理解就是一个接口规范描述,或者数据传输协议
关于WSDL本身的东西并不是很多:
https://www.runoob.com/wsdl/wsdl-tutorial.html
翻看W3C或者菜鸟教程就行了,工作上有可能自己自动生成还是怎样,反正怎么效率高怎么来,不纠结这个
WSDL文件案例:
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://wsServer.jmc.eai.infoservice.com/SAP_DMS_08/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SAP_DMS_08" targetNamespace="http://wsServer.jmc.eai.infoservice.com/SAP_DMS_08/"> <wsdl:types> <xsd:schema targetNamespace="http://wsServer.jmc.eai.infoservice.com/SAP_DMS_08/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="SD08"> <xsd:complexType> <xsd:sequence> <xsd:element name="in" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="SD08Response"> <xsd:complexType> <xsd:sequence> <xsd:element name="out" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="SD08_Request" type="tns:SD08_Request"></xsd:element> <xsd:complexType name="SD08_Request"> <xsd:sequence> <xsd:element name="vin" type="xsd:string"></xsd:element> <xsd:element name="engineNo" type="xsd:string"></xsd:element> <xsd:element name="modelCode" type="xsd:string"></xsd:element> <xsd:element name="productDate" type="xsd:string"></xsd:element> <xsd:element name="factoryDate" type="xsd:string"></xsd:element> <xsd:element name="saleDate" type="xsd:string"></xsd:element> <xsd:element name="maintainHandbookNo" type="xsd:string"> </xsd:element> <xsd:element name="gearBoxManufactor" type="xsd:string"></xsd:element> <xsd:element name="gearBoxModel" type="xsd:string"></xsd:element> <xsd:element name="gearBoxNo" type="xsd:string"></xsd:element> <xsd:element name="frontAxleManufactor" type="xsd:string"> </xsd:element> <xsd:element name="frontAxleModel" type="xsd:string"></xsd:element> <xsd:element name="frontAxleNo" type="xsd:string"></xsd:element> <xsd:element name="middleAxleManufactor" type="xsd:string"> </xsd:element> <xsd:element name="middleAxleModel" type="xsd:string"> </xsd:element> <xsd:element name="middleAxleNo" type="xsd:string"></xsd:element> <xsd:element name="rearAxleManufactor" type="xsd:string"> </xsd:element> <xsd:element name="rearAxleModel" type="xsd:string"></xsd:element> <xsd:element name="rearAxleNo" type="xsd:string"></xsd:element> <xsd:element name="tbox" type="xsd:string"></xsd:element> <xsd:element name="engineTypeInfo" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="SD08Request"> <wsdl:part element="tns:SD08_Request" name="SD08_Request"/> </wsdl:message> <wsdl:message name="SD08Response"> <wsdl:part element="tns:SD08Response" name="SD08_Response"/> </wsdl:message> <wsdl:portType name="SAP_DMS_08Type"> <wsdl:operation name="SD08"> <wsdl:input message="tns:SD08Request"/> <wsdl:output message="tns:SD08Response"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="SAP_DMS_08Binding" type="tns:SAP_DMS_08Type"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="SD08"> <soap:operation soapAction="http://wsServer.jmc.eai.infoservice.com/SAP_DMS_08/SD08"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="SAP_DMS_08"> <wsdl:port binding="tns:SAP_DMS_08Binding" name="SAP_DMS_08Port"> <soap:address location="http://wsServer.jmc.eai.infoservice.com/"/> </wsdl:port> </wsdl:service> </wsdl:definitions>