package com.emr.controller;

import com.emr.util.PropertiesUtils;
import org.apache.cxf.endpoint.Client;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @ProjectName:预加载一次webService
 * @Description:
 * @Param 传输参数
 * @Return
 * @Author: 曾文和
 * @CreateDate: 2020/7/7 16:34
 * @UpdateUser: 曾文和
 * @UpdateDate: 2020/7/7 16:34
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Component
public class WebServiceLoad {
    @PostConstruct
    public void contextInitialized() {
        new Thread(() -> {
            String token = "11";
            String POWER_URLHEAD = PropertiesUtils.getProperty("POWER_JSP");
            //创建连接工厂
            JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance();
            //创建客户端
            Client client = dcf.createClient(POWER_URLHEAD + "/WebService/PowerWebService?wsdl");
            try {
                //动态调用getInfosByUserId方法
                client.invoke("getInfosByUserId", token, "emr_record");
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                if(null != client) {
                    client.destroy();
                }
            }
        }).start();
    }
}
