cmd解析webservice接口的方法:wsimport -s C: -p com.zrt.portal.replay https://stg-sengine.gehcwebsvc.cn/IBTool/webService/SdtWebServiceInterface?Wsdl
-s 存放地址;-p:接口地址
测试数据:
{"data":"<SOE>
<TYPE>SDT_STASUS_LOG</TYPE>
<SDT>
<UserName>jin</UserName>
<Operating>qqq</Operating>
<AddressStatus>沈阳</AddressStatus>
<UpdateTime>2020-12-20 09:03:53</UpdateTime>
</SDT>
<SDT>
<UserName>jin1</UserName>
<Operating>qqq</Operating>
<AddressStatus>大连</AddressStatus>
<UpdateTime>2020-12-20 09:03:53</UpdateTime>
</SDT>
</SOE>"}
JAVA:
接口:
WebServiceInterface
package com.fh.controller.sdt.webservice; import javax.jws.WebParam; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; @WebService @SOAPBinding(style = SOAPBinding.Style.RPC) public interface SdtWebServiceInterface { String sdtData(@WebParam(name = "param") String param); }
WebServiceInterfaceServiceImpl
package com.fh.controller.sdt.webservice.impl; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.annotation.Resource; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import org.apache.log4j.Logger; import org.jdom2.JDOMException; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fh.controller.sdt.webservice.SdtWebServiceInterface; import com.fh.controller.sdt.webservice.SdtWebServiceUtil; import com.fh.entity.XmlException; import com.fh.service.sdtData.SdtDataLogService; import com.fh.service.sdtData.SdtDataService; import com.fh.util.PageData; import com.fh.util.UuidUtil; @WebService( endpointInterface = "com.fh.controller.sdt.webservice.SdtWebServiceInterface", targetNamespace = "http://webservice.sdt.controller.fh.com/", serviceName = "SdtWebServiceInterface") @SOAPBinding(style = SOAPBinding.Style.RPC) public class SdtWebServiceInterfaceServiceImpl implements SdtWebServiceInterface { @Resource(name = "SdtDataLogService") private SdtDataLogService sdtDataLogService; @Resource(name = "sdtDataService") private SdtDataService sdtDataService; Logger logger = Logger.getLogger("Logger"); @Override /** * 入库接收接口 * * @param param * @return */ public String sdtData(String param) { Date d = new Date(); SimpleDateFormat nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateNowStr = nowTime.format(d); PageData starlogPd = new PageData(); starlogPd.put("LOG_ID", UuidUtil.get32UUID()); starlogPd.put("TYPE", "接口");//类型为批量上传 starlogPd.put("MOUDLE", "SDT Data");//接收fmv starlogPd.put("OPERATION", "调用sdtData接口");// starlogPd.put("OPERATION_TIME", dateNowStr);//时间 PageData logPd = new PageData(); logPd.put("LOG_ID", UuidUtil.get32UUID()); logPd.put("TYPE", "接收");//类型为批量上传 logPd.put("MOUDLE", "SDT Data Receive");//接收fmv logPd.put("OPERATION", "接收SDT Data数据");// logPd.put("OPERATION_TIME", dateNowStr);//时间 boolean success = false; try { // return "param:"+param; sdtDataLogService.insertLogs(starlogPd); System.out.println("------------------------------------------------------------"); JSONObject json = JSON.parseObject(param); String xmlDoc = (String) json.get("data"); System.out.println(xmlDoc); String type = null; List<PageData> list = SdtWebServiceUtil.poeXmlElements(xmlDoc); PageData delOld = new PageData(); for (PageData pageData : list) { type = pageData.get("TYPE").toString(); if (type.equals("SDT_STASUS_LOG")) { if (delOld.size()==0) { delOld.put("startTime", pageData.get("UpdateTime")); delOld.put("endTime", pageData.get("UpdateTime")); } if (nowTime.parse(pageData.get("UpdateTime").toString()).getTime()<nowTime.parse(delOld.getbigString("startTime")).getTime()) { delOld.put("startTime", pageData.get("UpdateTime")); }else { delOld.put("endTime", pageData.get("UpdateTime")); } } } if (type.equals("SDT_STASUS_LOG")) { logPd.put("MOUDLE", "SDT Word Status Log Receive");//接收 logPd.put("OPERATION", "接收SDT工作状态日志数据");// } sdtDataService.insertSdtData(list,delOld); PageData timePd = new PageData(); timePd.put("UPDATE_DATE", list.get(0).getString("UPDATE_DATE")); timePd.put("UPDATE_PERSON", "SDT"); success = true; logPd.put("REMARK", "接收入库信息成功!"); logPd.put("STATUS", "S"); logger.debug("接收入库信息成功!"); sdtDataLogService.insertLogs(logPd); return "{\"success\":" + success + ",\"data\":\"\"}"; } catch (JDOMException e) { logPd.put("REMARK", "构造SDT XML Document失败"); logger.debug("构造SDT XML Document失败"); logPd.put("STATUS", "F"); try { sdtDataLogService.insertLogs(logPd); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //保存错误数据信息 try { logPd.put("REMARK", e.getMessage()); logger.debug("保存SDT错误数据信息成功"); logPd.put("STATUS", "F"); sdtDataLogService.insertLogs(logPd); } catch (Exception ex) { logPd.put("REMARK", e.getMessage()); logger.debug("保存SDT错误数据信息失败"); logPd.put("STATUS", "F"); ex.printStackTrace(); try { sdtDataLogService.insertLogs(logPd); } catch (Exception e1) { e1.printStackTrace(); } } return "{\"success\":" + success + ",\"data\":\"" + e.getMessage() + "\"}"; } catch (IOException e) { logPd.put("REMARK", "构造SDT XML Document IO异常"); logger.debug("构造SDT XML Document IO异常"); logPd.put("STATUS", "F"); try { sdtDataLogService.insertLogs(logPd); } catch (Exception e1) { e1.printStackTrace(); } //保存错误数据信息 try { logPd.put("REMARK", e.getMessage()); logger.debug("保存SDT错误数据信息成功"); logPd.put("STATUS", "S"); sdtDataLogService.insertLogs(logPd); } catch (Exception ex) { logPd.put("REMARK", "保存EPOP错误数据信息失败"); logger.debug("保存SDT错误数据信息失败"); logPd.put("STATUS", "F"); ex.printStackTrace(); try { sdtDataLogService.insertLogs(logPd); } catch (Exception e1) { e1.printStackTrace(); } } return "{\"success\":" + success + ",\"data\":\"构造SDT XML Document失败\"}"; } catch (XmlException e) { logPd.put("REMARK", e.getMessage()); //保存错误数据信息 try { logPd.put("REMARK", e.getMessage()); logger.debug("保存SDT错误数据信息成功"); logPd.put("STATUS", "F"); sdtDataLogService.insertLogs(logPd); } catch (Exception ex) { logPd.put("REMARK", "保存SDT错误数据信息失败"); logger.debug("保存SDT错误数据信息失败"); logPd.put("STATUS", "F"); try { sdtDataLogService.insertLogs(logPd); } catch (Exception e1) { e1.printStackTrace(); } ex.printStackTrace(); } return "{\"success\":" + success + ",\"data\":\"" + e.getMessage() + "\"}"; } catch (Exception e) { logPd.put("REMARK", "入库接收数据处理失败"); logger.error(e.toString(), e); //保存错误数据信息 try { logPd.put("REMARK", e.getMessage()); logger.debug("保存SDT错误数据信息成功"); logPd.put("STATUS", "F"); sdtDataLogService.insertLogs(logPd); } catch (Exception ex) { logPd.put("REMARK", "保存SDT错误数据信息失败"); logger.debug("保存SDT错误数据信息失败"); logPd.put("STATUS", "F"); try { sdtDataLogService.insertLogs(logPd); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ex.printStackTrace(); } return "{\"success\":" + success + ",\"data\":\"入库接收数据处理失败,请联系管理员\"}"; } } }
xml接收的数据处理工具
package com.fh.controller.sdt.webservice; import com.fh.util.DateUtil; import com.fh.util.PageData; import com.fh.util.UuidUtil; import com.fh.entity.*; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; import org.jdom2.Namespace; import org.jdom2.input.SAXBuilder; import org.xml.sax.InputSource; import java.io.IOException; import java.io.StringReader; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; public class SdtWebServiceUtil { /** * 解析入库出库接收xml * @param xmlDoc xml字符串 * @param name * @throws Exception */ public static List<PageData> poeXmlElements(String xmlDoc) throws JDOMException, IOException, XmlException { //创建一个新的字符串 StringReader read = new StringReader(xmlDoc); //创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入 InputSource source = new InputSource(read); //创建一个新的SAXBuilder SAXBuilder sb = new SAXBuilder(); //通过输入源构造一个Document Document doc = sb.build(source); //取的根元素 Element root = doc.getRootElement(); System.out.println(root.getName());//输出根元素的名称(测试) //得到根元素所有子元素的集合 List jiedian = root.getChildren(); //获得XML中的命名空间(XML中未定义可不写) Namespace ns = root.getNamespace(); List<PageData> listPd = new ArrayList<>(); PageData headPd = new PageData(); Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = df.format(date); String type = null; for(int i=0;i<jiedian.size();i++){ Element et = (Element) jiedian.get(i);//循环依次得到子元素 if ("TYPE".equalsIgnoreCase(et.getName())) { type = et.getText(); } if ("SDT".equalsIgnoreCase(et.getName())){ PageData detailPd = new PageData(); detailPd.putAll(headPd); detailPd.put("UPDATE_DATE",time); detailPd.put("CREATE_DATE",time); detailPd.put("UPDATE_PERSON",""); detailPd.put("CREATE_PERSON",""); detailPd.put("STATUS","U"); detailPd.put("ID", UuidUtil.get32UUID()); detailPd.put("TYPE", type); detailPd = poeDetailXmlToPd(detailPd,et); listPd.add(detailPd); } } return listPd; } /** * 解析入库接收xml <POE_HEADER> * @param headPd * @param et * @return PageData * @throws XmlException */ private static PageData poeDetailXmlToPd(PageData headPd, Element et) throws XmlException { Element sdtData = null; if (headPd.get("TYPE").equals("SDT_STASUS_LOG")) { sdtData = et.getChild("UserName"); if (sdtData != null ){ if(!sdtData.getText().equals("")){ headPd.put("UserName",sdtData.getText()); }else{ headPd.put("UserName",""); // throw new XmlException("FMVSplitNo不能为空"); } }else { throw new XmlException("XML中缺少UserName节点,请检查是否存在以及大小写"); } sdtData = et.getChild("Operating"); if (sdtData != null){ if(!sdtData.getText().equals("")){ headPd.put("Operating",sdtData.getText()); }else{ headPd.put("Operating",""); } }else { throw new XmlException("XML中缺少Operating节点,请检查是否存在以及大小写"); } sdtData = et.getChild("AddressStatus"); if (sdtData != null){ if(!sdtData.getText().equals("")){ headPd.put("AddressStatus",sdtData.getText()); }else{ headPd.put("AddressStatus",""); } }else { throw new XmlException("XML中缺少AddressStatus节点,请检查是否存在以及大小写"); } sdtData = et.getChild("UpdateTime"); if (sdtData != null){ if(!sdtData.getText().equals("")){ headPd.put("UpdateTime",sdtData.getText()); }else{ headPd.put("UpdateTime",""); } }else { throw new XmlException("XML中缺少UpdateTime节点,请检查是否存在以及大小写"); } } return portCusdefXmlToPd(headPd,et,"HEADER"); } /** * 解析xml 自定义列 * @param Pd * @param et * @param hOrd (header or detail) * @return PageData * @throws XmlException */ public static PageData portCusdefXmlToPd(PageData Pd, Element et,String hOrd) { Element cusdef = null; for (int i = 1; i <= 10; i++) { cusdef = et.getChild("cusdef"+i); if (cusdef != null){ Pd.put(hOrd+"CUSDEF"+i, cusdef.getText()); }else { Pd.put(hOrd+"CUSDEF"+i, ""); } } return Pd; } }
调用接口的账号密码:
package com.fh.controller.sdt.webservice; import com.fh.util.MD5; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPMessage; public class AuthInterceptor extends AbstractPhaseInterceptor<SoapMessage> { private SAAJInInterceptor saa = new SAAJInInterceptor(); public AuthInterceptor() { super(Phase.PRE_PROTOCOL); getAfter().add(SAAJInInterceptor.class.getName()); } public void handleMessage(SoapMessage message) throws Fault { SOAPMessage soapMsg = message.getContent(SOAPMessage.class); if (soapMsg == null){ saa.handleMessage(message); soapMsg = message.getContent(SOAPMessage.class); } SOAPHeader header = null; try { header = soapMsg.getSOAPHeader(); System.out.println(header.toString()); NodeList userNodes = header.getElementsByTagName("username"); NodeList passNodes = header.getElementsByTagName("password"); if(userNodes!=null && passNodes!=null){ Node userNode = userNodes.item(0); Node passNode = passNodes.item(0); if (userNode !=null && passNode != null){ if(userNode.getFirstChild() != null && passNode.getFirstChild() != null && userNode.getFirstChild().getNodeValue() != null && passNode.getFirstChild().getNodeValue() != null && userNode.getFirstChild().getNodeValue().equals("GESDT")){ String pwd = passNode.getFirstChild().getNodeValue(); if(pwd.equals(MD5.md5("GE"))){ return ; } } } } else { throw new Fault(new Exception("auth error")); } } catch (SOAPException e) { e.printStackTrace(); } throw new Fault(new Exception("auth error")); } public static void main(String[] args) { System.out.println(MD5.md5("f803729628adf4199f224c2a225038e9")); } }
日志service
package com.fh.service.sdtData; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.fh.dao.DaoSupport; import com.fh.util.PageData; @Service("SdtDataLogService") public class SdtDataLogService { @Resource(name = "daoSupport") private DaoSupport dao; /** * 添加日志 * @param pd * @throws Exception */ public void insertLogs(PageData pd) throws Exception{ dao.save("SdtDataLogMapper.insertLogs", pd); } /** * 查询上传的最后时间 * @param pd * @throws Exception */ public PageData selectMaxUpdateTime(PageData pd) throws Exception{ return (PageData)dao.findForObject("SdtDataLogMapper.selectMaxUpdateTime", pd); } }
数据存入数据库service
package com.fh.service.sdtData; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.fh.dao.DaoSupport; import com.fh.service.fmv.approvalProcess.FmvApprovalProcessService; import com.fh.util.Logger; import com.fh.util.PageData; @Service("sdtDataService") public class SdtDataService { @Resource(name = "daoSupport") private DaoSupport dao; protected Logger logger = Logger.getLogger(this.getClass()); @Resource(name="FmvApprovalProcessService") private FmvApprovalProcessService fmvApprovalProcessService; /** * 插入入库接收数据 * * @param list * @param identify 表标识 * @throws Exception */ public void insertSdtData(List<PageData> list,PageData delOld) throws Exception { //SDT工作状态日志表 if ("SDT_STASUS_LOG".equals(list.get(0).get("TYPE").toString())) { dao.delete("SdtDataMapper.deleteBySdtStateLog", delOld); dao.batchSave("SdtDataMapper.batchSaveSdtStateLog",list); } } }
日志mapper
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="SdtDataLogMapper"> <!-- 添加日志 --> <insert id="insertLogs" parameterType="pd"> insert into tb_sdt_data_logs ( LOG_ID, USER_NAME, LOGIN_IP, TYPE, OPERATION, OPERATION_TIME, REMARK, STATUS, USER_CODE, <if test="OPERATION_END != null and OPERATION_END != ''"> OPERATION_END, </if> MOUDLE ) values( #{LOG_ID,jdbcType=VARCHAR}, #{USER_NAME,jdbcType=VARCHAR}, #{LOGIN_IP,jdbcType=VARCHAR}, #{TYPE,jdbcType=VARCHAR}, #{OPERATION,jdbcType=VARCHAR}, #{OPERATION_TIME}, #{REMARK,jdbcType=VARCHAR}, #{STATUS,jdbcType=VARCHAR}, #{USER_CODE,jdbcType=VARCHAR}, <if test="OPERATION_END != null and OPERATION_END != ''"> #{OPERATION_END}, </if> #{MOUDLE,jdbcType=VARCHAR} ) </insert> </mapper>
存数据mapper
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="SdtDataMapper"> <!-- 批量导入 --> <insert id="batchSaveSdtStateLog" parameterType="java.util.List" useGeneratedKeys="false"> INSERT INTO tb_sdt_work_status_log ( ID, USERNAME, OPERATING, ADDRESS_STATUS, UPDATE_TIME, CREATE_DATE, CREATE_PERSON, UPDATE_DATE, UPDATE_PERSON ) <foreach collection="list" item="list" index="index" separator="union all"> ( SELECT #{list.ID,jdbcType=VARCHAR}, #{list.UserName,jdbcType=VARCHAR}, #{list.Operating,jdbcType=VARCHAR}, #{list.AddressStatus,jdbcType=VARCHAR}, #{list.UpdateTime,jdbcType=VARCHAR}, #{list.CREATE_DATE,jdbcType=VARCHAR}, #{list.CREATE_PERSON,jdbcType=VARCHAR}, #{list.UPDATE_DATE,jdbcType=VARCHAR}, #{list.UPDATE_PERSON,jdbcType=VARCHAR} FROM DUAL ) </foreach> </insert> <!-- 删除上一版数据 --> <delete id="deleteBySdtStateLog" parameterType="pd"> DELETE FROM tb_sdt_work_status_log WHERE 1=1 <if test="startTime != null and startTime !=''"> and UPDATE_TIME >= #{startTime} </if> <if test="endTime != null and endTime !=''"> <![CDATA[and UPDATE_TIME <= #{endTime}]]> </if> </delete> </mapper>
调用接口
package com.fh.controller.sdt.webservice; import java.util.List; import javax.xml.namespace.QName; import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; import org.apache.cxf.headers.Header; import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.apache.cxf.phase.Phase; public class aaa { /** * webservice客户端测试 */ public static class TestWS { /** * @param args */ public static void main(String[] args) { JaxWsProxyFactoryBean soapFactoryBean = new JaxWsProxyFactoryBean(); soapFactoryBean.setAddress("https://localhost:8805/IBTool/webService/SdtWebServiceInterface?Wsdl"); soapFactoryBean.getInInterceptors().add(new LoggingInInterceptor()); soapFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor()); // 添加拦截器 soapFactoryBean.getOutInterceptors().add(new ClientAuthInterceptor()); soapFactoryBean.setServiceClass(SdtWebServiceInterface.class); Object o = soapFactoryBean.create(); SdtWebServiceInterface testService = (SdtWebServiceInterface)o; String result = null; try { String data = "{\"data\":\"" + "<SOE>\n" + "\t<TYPE>SDT_STASUS_LOG</TYPE>\n" + "\t<SDT>\n" + "\t\t<UserName>jin</UserName>\n" + "\t\t<Operating>qqq</Operating>\n" + "\t\t<AddressStatus>沈阳</AddressStatus>\n" + "\t\t<UpdateTime>2020-12-20 09:03:53</UpdateTime>\n" + "\t</SDT>\n" + "\t<SDT>\n" + "\t\t<UserName>jin1</UserName>\n" + "\t\t<Operating>qqq</Operating>\n" + "\t\t<AddressStatus>大连</AddressStatus>\n" + "\t\t<UpdateTime>2020-12-20 09:03:53</UpdateTime>\n" + "\t</SDT>\n" + "</SOE>" + "\"}"; result = testService.sdtData(data); } catch (Exception e) { e.printStackTrace(); } System.out.println(result); } } public static class ClientAuthInterceptor extends AbstractSoapInterceptor { public ClientAuthInterceptor(){ super(Phase.WRITE); } public void handleMessage(SoapMessage soapMessage) throws Fault { org.w3c.dom.Document doc= DOMUtils.createDocument(); // 根节点 org.w3c.dom.Element rootEle=doc.createElementNS("", "AuthToken"); // 用户ID org.w3c.dom.Element userEle = doc.createElement("username"); userEle.setTextContent("GESDT"); rootEle.appendChild(userEle); // 密码 org.w3c.dom.Element passEle = doc.createElement("password"); passEle.setTextContent(MD5.md5("GE")); rootEle.appendChild(passEle); // 添加到头 List<Header> headers = soapMessage.getHeaders(); QName qname=new QName("AuthToken"); SoapHeader head=new SoapHeader(qname, rootEle); headers.add(head); } } }
调用接口的第二种方法:
1.先解析wdsl文件:通过接口地址解析,例如:https://stg-sengine.gehcwebsvc.cn/IBTool/webService/SdtWebServiceInterface?Wsdl
代码:
测试客户端
package client; import webservice.SdtWebServiceInterface_PortType; import webservice.SdtWebServiceInterface_Service; import webservice.SdtWebServiceInterface_ServiceLocator; import javax.xml.namespace.QName; import javax.xml.rpc.ServiceException; import java.rmi.RemoteException; import java.util.List; import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; import org.apache.cxf.headers.Header; import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.apache.cxf.phase.Phase; /** * @version V1.0 * @FileName: * @Description: * @author: SunLiZhi * @Date: 2021/3/4 11:30 */ public class test { public static void main(String[] args) throws ServiceException { SdtWebServiceInterface_Service test = new SdtWebServiceInterface_ServiceLocator();//web引用(改成您自己的) SdtWebServiceInterface_PortType webCXFService = test.getSdtWebServiceInterfaceServiceImplPort(); try { String data = "{\"data\":\"" + "<SOE>\n" + "\t<TYPE>SDT_STASUS_LOG</TYPE>\n" + "\t<SDT>\n" + "\t\t<UserName>jin</UserName>\n" + "\t\t<Operating>qqq</Operating>\n" + "\t\t<AddressStatus>沈阳</AddressStatus>\n" + "\t\t<UpdateTime>2020-12-20 09:03:53</UpdateTime>\n" + "\t</SDT>\n" + "\t<SDT>\n" + "\t\t<UserName>jin1</UserName>\n" + "\t\t<Operating>qqq</Operating>\n" + "\t\t<AddressStatus>大连</AddressStatus>\n" + "\t\t<UpdateTime>2020-12-20 09:03:53</UpdateTime>\n" + "\t</SDT>\n" + "</SOE>" + "\"}"; String s = webCXFService.sdtData(data); System.out.println(s); } catch (Exception e) { e.printStackTrace(); } } public static class ClientAuthInterceptor extends AbstractSoapInterceptor { public ClientAuthInterceptor(){ super(Phase.WRITE); } public void handleMessage(SoapMessage soapMessage) throws Fault { org.w3c.dom.Document doc= DOMUtils.createDocument(); // 根节点 org.w3c.dom.Element rootEle=doc.createElementNS("", "AuthToken"); // 用户ID org.w3c.dom.Element userEle = doc.createElement("username"); userEle.setTextContent("GESDT"); rootEle.appendChild(userEle); // 密码 org.w3c.dom.Element passEle = doc.createElement("password"); passEle.setTextContent(MD5.md5("GE")); rootEle.appendChild(passEle); // 添加到头 List<Header> headers = soapMessage.getHeaders(); QName qname=new QName("AuthToken"); SoapHeader head=new SoapHeader(qname, rootEle); headers.add(head); } } }
解析出来的代码:
SdtWebServiceInterface_PortType:
/** * SdtWebServiceInterface_PortType.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package webservice; public interface SdtWebServiceInterface_PortType extends java.rmi.Remote { public java.lang.String sdtData(java.lang.String param) throws java.rmi.RemoteException; }
SdtWebServiceInterface_Service:
/** * SdtWebServiceInterface_Service.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package webservice; public interface SdtWebServiceInterface_Service extends javax.xml.rpc.Service { public java.lang.String getSdtWebServiceInterfaceServiceImplPortAddress(); public webservice.SdtWebServiceInterface_PortType getSdtWebServiceInterfaceServiceImplPort() throws javax.xml.rpc.ServiceException; public webservice.SdtWebServiceInterface_PortType getSdtWebServiceInterfaceServiceImplPort(java.net.URL portAddress) throws javax.xml.rpc.ServiceException; }
SdtWebServiceInterface_ServiceLocator:
/** * SdtWebServiceInterface_ServiceLocator.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package webservice; import client.MD5; import org.apache.axis.message.SOAPHeaderElement; import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.helpers.DOMUtils; import org.apache.xmlbeans.impl.soap.Name; import javax.xml.namespace.QName; public class SdtWebServiceInterface_ServiceLocator extends org.apache.axis.client.Service implements webservice.SdtWebServiceInterface_Service { public SdtWebServiceInterface_ServiceLocator() { } public SdtWebServiceInterface_ServiceLocator(org.apache.axis.EngineConfiguration config) { super(config); } public SdtWebServiceInterface_ServiceLocator(java.lang.String wsdlLoc, javax.xml.namespace.QName sName) throws javax.xml.rpc.ServiceException { super(wsdlLoc, sName); } // Use to get a proxy class for SdtWebServiceInterfaceServiceImplPort private java.lang.String SdtWebServiceInterfaceServiceImplPort_address = "https://stg-sengine.gehcwebsvc.cn/IBTool/webService/SdtWebServiceInterface"; public java.lang.String getSdtWebServiceInterfaceServiceImplPortAddress() { return SdtWebServiceInterfaceServiceImplPort_address; } // The WSDD service name defaults to the port name. private java.lang.String SdtWebServiceInterfaceServiceImplPortWSDDServiceName = "SdtWebServiceInterfaceServiceImplPort"; public java.lang.String getSdtWebServiceInterfaceServiceImplPortWSDDServiceName() { return SdtWebServiceInterfaceServiceImplPortWSDDServiceName; } public void setSdtWebServiceInterfaceServiceImplPortWSDDServiceName(java.lang.String name) { SdtWebServiceInterfaceServiceImplPortWSDDServiceName = name; } public webservice.SdtWebServiceInterface_PortType getSdtWebServiceInterfaceServiceImplPort() throws javax.xml.rpc.ServiceException { java.net.URL endpoint; try { endpoint = new java.net.URL(SdtWebServiceInterfaceServiceImplPort_address); } catch (java.net.MalformedURLException e) { throw new javax.xml.rpc.ServiceException(e); } return getSdtWebServiceInterfaceServiceImplPort(endpoint); } public webservice.SdtWebServiceInterface_PortType getSdtWebServiceInterfaceServiceImplPort(java.net.URL portAddress) throws javax.xml.rpc.ServiceException { try { org.w3c.dom.Document doc= DOMUtils.createDocument(); // 根节点 org.w3c.dom.Element rootEle=doc.createElementNS("", "AuthToken"); // 用户ID org.w3c.dom.Element userEle = doc.createElement("username"); userEle.setTextContent("GESDT"); rootEle.appendChild(userEle); // 密码 org.w3c.dom.Element passEle = doc.createElement("password"); passEle.setTextContent(MD5.md5("GE")); rootEle.appendChild(passEle); QName qname=new QName("AuthToken"); SOAPHeaderElement element = new SOAPHeaderElement(qname,rootEle); // SoapHeader head=new SoapHeader(qname, rootEle); webservice.SdtWebServiceInterfaceSoapBindingStub _stub = new webservice.SdtWebServiceInterfaceSoapBindingStub(portAddress, this); _stub.setPortName(getSdtWebServiceInterfaceServiceImplPortWSDDServiceName()); _stub.setHeader(element); return _stub; } catch (org.apache.axis.AxisFault e) { return null; } } public void setSdtWebServiceInterfaceServiceImplPortEndpointAddress(java.lang.String address) { SdtWebServiceInterfaceServiceImplPort_address = address; } /** * For the given interface, get the stub implementation. * If this service has no port for the given interface, * then ServiceException is thrown. */ public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException { try { if (webservice.SdtWebServiceInterface_PortType.class.isAssignableFrom(serviceEndpointInterface)) { webservice.SdtWebServiceInterfaceSoapBindingStub _stub = new webservice.SdtWebServiceInterfaceSoapBindingStub(new java.net.URL(SdtWebServiceInterfaceServiceImplPort_address), this); _stub.setPortName(getSdtWebServiceInterfaceServiceImplPortWSDDServiceName()); return _stub; } } catch (java.lang.Throwable t) { throw new javax.xml.rpc.ServiceException(t); } throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface: " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName())); } /** * For the given interface, get the stub implementation. * If this service has no port for the given interface, * then ServiceException is thrown. */ public java.rmi.Remote getPort(javax.xml.namespace.QName portName, Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException { if (portName == null) { return getPort(serviceEndpointInterface); } java.lang.String inputPortName = portName.getLocalPart(); if ("SdtWebServiceInterfaceServiceImplPort".equals(inputPortName)) { return getSdtWebServiceInterfaceServiceImplPort(); } else { java.rmi.Remote _stub = getPort(serviceEndpointInterface); ((org.apache.axis.client.Stub) _stub).setPortName(portName); return _stub; } } public javax.xml.namespace.QName getServiceName() { return new javax.xml.namespace.QName("http://webservice.sdt.controller.fh.com/", "SdtWebServiceInterface"); } private java.util.HashSet ports = null; public java.util.Iterator getPorts() { if (ports == null) { ports = new java.util.HashSet(); ports.add(new javax.xml.namespace.QName("http://webservice.sdt.controller.fh.com/", "SdtWebServiceInterfaceServiceImplPort")); } return ports.iterator(); } /** * Set the endpoint address for the specified port name. */ public void setEndpointAddress(java.lang.String portName, java.lang.String address) throws javax.xml.rpc.ServiceException { if ("SdtWebServiceInterfaceServiceImplPort".equals(portName)) { setSdtWebServiceInterfaceServiceImplPortEndpointAddress(address); } else { // Unknown Port Name throw new javax.xml.rpc.ServiceException(" Cannot set Endpoint Address for Unknown Port" + portName); } } /** * Set the endpoint address for the specified port name. */ public void setEndpointAddress(javax.xml.namespace.QName portName, java.lang.String address) throws javax.xml.rpc.ServiceException { setEndpointAddress(portName.getLocalPart(), address); } }
SdtWebServiceInterfaceSoapBindingStub:
/** * SdtWebServiceInterfaceSoapBindingStub.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package webservice; public class SdtWebServiceInterfaceSoapBindingStub extends org.apache.axis.client.Stub implements webservice.SdtWebServiceInterface_PortType { private java.util.Vector cachedSerClasses = new java.util.Vector(); private java.util.Vector cachedSerQNames = new java.util.Vector(); private java.util.Vector cachedSerFactories = new java.util.Vector(); private java.util.Vector cachedDeserFactories = new java.util.Vector(); static org.apache.axis.description.OperationDesc [] _operations; static { _operations = new org.apache.axis.description.OperationDesc[1]; _initOperationDesc1(); } private static void _initOperationDesc1(){ org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc(); oper.setName("sdtData"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "param"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); oper.setReturnClass(java.lang.String.class); oper.setReturnQName(new javax.xml.namespace.QName("", "return")); oper.setStyle(org.apache.axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.LITERAL); _operations[0] = oper; } public SdtWebServiceInterfaceSoapBindingStub() throws org.apache.axis.AxisFault { this(null); } public SdtWebServiceInterfaceSoapBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { this(service); super.cachedEndpoint = endpointURL; } public SdtWebServiceInterfaceSoapBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { if (service == null) { super.service = new org.apache.axis.client.Service(); } else { super.service = service; } ((org.apache.axis.client.Service)super.service).setTypeMappingVersion("1.1"); } protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException { try { org.apache.axis.client.Call _call = super._createCall(); if (super.maintainSessionSet) { _call.setMaintainSession(super.maintainSession); } if (super.cachedUsername != null) { _call.setUsername(super.cachedUsername); } if (super.cachedPassword != null) { _call.setPassword(super.cachedPassword); } if (super.cachedEndpoint != null) { _call.setTargetEndpointAddress(super.cachedEndpoint); } if (super.cachedTimeout != null) { _call.setTimeout(super.cachedTimeout); } if (super.cachedPortName != null) { _call.setPortName(super.cachedPortName); } java.util.Enumeration keys = super.cachedProperties.keys(); while (keys.hasMoreElements()) { java.lang.String key = (java.lang.String) keys.nextElement(); _call.setProperty(key, super.cachedProperties.get(key)); } return _call; } catch (java.lang.Throwable _t) { throw new org.apache.axis.AxisFault("Failure trying to get the Call object", _t); } } public java.lang.String sdtData(java.lang.String param) throws java.rmi.RemoteException { if (super.cachedEndpoint == null) { throw new org.apache.axis.NoEndPointException(); } org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[0]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setEncodingStyle(null); _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE); _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new javax.xml.namespace.QName("http://webservice.sdt.controller.fh.com/", "sdtData")); setRequestHeaders(_call); setAttachments(_call); try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {param}); if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } else { extractAttachments(_call); try { return (java.lang.String) _resp; } catch (java.lang.Exception _exception) { return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class); } } } catch (org.apache.axis.AxisFault axisFaultException) { throw axisFaultException; } } }
工具类:
MD5
package com.fh.controller.sdt.webservice; import java.security.MessageDigest; public class MD5 { public static String md5(String str) { try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } str = buf.toString(); } catch (Exception e) { e.printStackTrace(); } return str; } public static void main(String[] args) { System.out.println(md5("31119@qq.com"+"123456")); System.out.println(md5("mj1")); } }
数据库
日志表
CREATE TABLE `cengine`.`tb_sdt_data_logs` ( `LOG_ID` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主键ID', `USER_NAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作者名称', `LOGIN_IP` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '登录IP地址', `TYPE` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型:(Upload:上传,Down:下载)', `OPERATION` varchar(3000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作', `OPERATION_TIME` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作时间', `REMARK` varchar(3000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注', `STATUS` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态(成功:S,失败:F)', `USER_CODE` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作者SSO', `MOUDLE` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '模块', `OPERATION_END` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '结束时间(选填)', PRIMARY KEY (`LOG_ID`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
数据表
CREATE TABLE `cengine`.`tb_sdt_work_status_log` ( `ID` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '32UUID主键', `USERNAME` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名', `OPERATING` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '操作', `ADDRESS_STATUS` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '地址/状态', `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '更新时间', `CREATE_DATE` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建时间', `CREATE_PERSON` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人', `UPDATE_DATE` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新时间', `UPDATE_PERSON` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人', PRIMARY KEY (`ID`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;