• webService接口提供给别的系统调用


    我们项目与其他系统集成的目录结构,这里的都是提供给对外系统调用的webService接口。

    下面,把关于这些内容de文件一一贴出来:

    module-ws.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://cxf.apache.org/jaxws
      http://cxf.apache.org/schemas/jaxws.xsd">
      <import resource="classpath*:META-INF/cxf/cxf.xml"/>
      <import resource="classpath*:META-INF/cxf/cxf-servlet.xml"/>
      <import resource="classpath*:META-INF/cxf/cxf-extension-xml.xml"/>
      <bean id="mdsBaseLineImportWsServiceImpl" class="avicit.mms.pdm.mdsbaselineimportws.ws.impl.MdsBaseLineImportWsServiceImpl"></bean>
      <jaxws:endpoint id="mdsBaseLineImportWsService" implementor="#mdsBaseLineImportWsServiceImpl" address="/mdsBaseLineImportWsService">
      </jaxws:endpoint>
      <!--测试访问地址 http://localhost:9080/mms/ws/mdsBaseLineImportWsService?wsdl-->//这里是别的系统调用的地址
    </beans>

    MdsBaseLineImportWsService.java

    package avicit.mms.pdm.mdsbaselineimportws.ws;

    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;

    @WebService(targetNamespace = "http://ws.mdsbaselineimportws.pdm")     //webService接口的命名空间,不过不一定需要,本次接口集成的过程中,没用到
    public interface MdsBaseLineImportWsService {
      @WebMethod(operationName = "addBaseLine")
      @WebResult(name = "result")
      public String addBaseLine(@WebParam(name = "baseLineInfoXml") String baseLineInfoXml) throws Exception;
    }

    MdsBaseLineImportWsServiceImpl.java

    import avicit.mms.mds.mdsbaselineimport.dto.MdsBaselineImportDTO;
    import avicit.mms.mds.mdsbaselineimport.service.MdsBaselineImportService;
    import avicit.mms.pdm.mdsbaselineimportws.ws.MdsBaseLineImportWsService;
    import avicit.platform6.commons.utils.JsonHelper;
    import com.alibaba.druid.support.json.JSONUtils;
    import com.alibaba.fastjson.JSONArray;
    import com.alibaba.fastjson.JSONObject;
    import com.fasterxml.jackson.core.type.TypeReference;
    import org.json.XML;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;

    import javax.jws.WebService;
    import java.text.SimpleDateFormat;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    @WebService(endpointInterface = "avicit.mms.pdm.mdsbaselineimportws.ws.MdsBaseLineImportWsService", targetNamespace = "http://ws.mdsbaselineimportws.pdm")
    public class MdsBaseLineImportWsServiceImpl implements MdsBaseLineImportWsService {
      private static final Logger logger = LoggerFactory.getLogger(MdsBaseLineImportWsServiceImpl.class);
      @Autowired
      private MdsBaselineImportService mdsBaselineImportService;

      @Override
      public String addBaseLine(String baseLineInfoXml) throws Exception {
        Map<String, Object> returnInfo = new HashMap<String, Object>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Map<String, Object> jsonData = new HashMap<String, Object>();
        try {
          jsonData = (Map<String, Object>) JSONObject.parse(XML.toJSONObject(baseLineInfoXml).get("BaseLine").toString());
        } catch (Exception e) {
          logger.info("xml格式错误***************");
          e.printStackTrace();
          returnInfo.put("flag", "0");
          returnInfo.put("ErrorMessage", "xml格式错误:" + e.getMessage());
          return JSONUtils.toJSONString(returnInfo);
        }

        if (null == XML.toJSONObject(baseLineInfoXml).get("BaseLine")) {
          logger.info("xml中不包含BaseLine节点");
          returnInfo.put("flag", "0");
          returnInfo.put("ErrorMessage", "xml中不包含BaseLine节点");
          return JSONUtils.toJSONString(returnInfo);
        }

        // 转换成List之前需判断字符串中是否已包含[],如果没有,转换时会发生异常
        String jsonStr = JSONArray.toJSONString(jsonData);
        if (!jsonStr.startsWith("[")) {
          jsonStr = "[" + jsonStr + "]";
        }

        List<Map<String, Object>> data = JsonHelper.getInstance().readValue(jsonStr, sdf, new TypeReference<List<Map<String, Object>>>() {
        });
        if (null != data && data.size() > 0) {
          try {
            for (Map<String, Object> map : data) {
              MdsBaselineImportDTO dto = new MdsBaselineImportDTO();
              dto.setPdmBaselineCode((String) map.get("Number"));
              dto.setPdmBaselineName((String) map.get("Name"));
              dto.setPdmBaselineType((String) map.get("Type"));
              dto.setPdmBaselineStatus((String) map.get("State"));
              dto.setPdmLastModified(sdf.parse((String) map.get("LastModified")));
              dto.setProductName((String) map.get("Product"));
              dto.setIsImportedMes("N");
              mdsBaselineImportService.insertMdsBaselineImport(dto);
            }
          } catch (Exception e) {
            logger.info("插入基线表MDS_BASELINE_IMPORT出错");
            e.printStackTrace();
            returnInfo.put("flag", "0");
            returnInfo.put("ErrorMessage", "插入基线表MDS_BASELINE_IMPORT出错:" + e.getMessage());
            return JSONUtils.toJSONString(returnInfo);
          }

          return JSONUtils.toJSONString(returnInfo);
        } else {
          returnInfo.put("flag", "0");
          returnInfo.put("msg", "接口数据格式中PBOM值为空,请核实");
          return JSONUtils.toJSONString(returnInfo);
        }
      }
    }

  • 相关阅读:
    微信小程序-开发入门(一)
    Vue入门
    美化input type=range标签滑动样式(带渐变效果)
    全新的css网站布局--Grid布局
    移动端布局与样式上的坑
    swiper 下拉刷新混乱
    子元素scroll父元素容器不跟随滚动JS实现
    解决前端页面闪烁问题(转载)
    VUE 与其他常见前端框架对比
    移动端表层div滑动,导致底层body滑动(touchmove的阻止)
  • 原文地址:https://www.cnblogs.com/1012hq/p/11170961.html
Copyright © 2020-2023  润新知