liusheng
3 天以前 23f78d642951675437de226332621b1195a505c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cn.lihu.jh.module.ecg.webservice;
 
import cn.lihu.jh.module.ecg.webservice.ws.JHFWreq;
import cn.lihu.jh.module.ecg.webservice.ws._0020SAMPLEBS_0020;
import cn.lihu.jh.module.ecg.webservice.ws._0020SAMPLEBS_0020Soap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import javax.xml.ws.BindingProvider;
import java.net.URL;
 
/**
 * WebService客户端
 */
@Slf4j
@Component
public class WebServiceClient {
 
    private static final String WSDL_URL = "http://10.0.4.36/ZHIP/Service/ZHIP.JHFWTYRK.BS.JHFWTYRK.cls?wsdl";
    private static final String ENDPOINT_URL = "http://10.0.4.36/ZHIP/Service/ZHIP.JHFWTYRK.BS.JHFWTYRK.cls";
 
    /**
     * 调用JHFWTYRK服务
     *
     * @param action 操作类型
     * @param rdn 请求标识
     * @param message 消息内容
     * @return 响应结果
     */
    public String callJHFWTYRK(String action, String rdn, String message) {
        try {
            // 创建服务实例
            _0020SAMPLEBS_0020 service = new _0020SAMPLEBS_0020(new URL(WSDL_URL));
            _0020SAMPLEBS_0020Soap port = service.get_0020SAMPLEBS_0020Soap();
 
            // 设置端点地址
            BindingProvider bindingProvider = (BindingProvider) port;
            bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT_URL);
 
            // 设置超时时间(可选)
            bindingProvider.getRequestContext().put("javax.xml.ws.client.connectionTimeout", "30000");
            bindingProvider.getRequestContext().put("javax.xml.ws.client.receiveTimeout", "30000");
 
            // 构建请求参数
            JHFWreq req = new JHFWreq();
            req.setAction(action);
            req.setRdn(rdn);
            req.setMessage(message);
 
            // 调用服务
            String response = port.jhfwtyrk(req);
            log.info("JHFWTYRK调用成功,响应结果:{}", response);
            return response;
 
        } catch (Exception e) {
            log.error("JHFWTYRK调用失败", e);
            throw new RuntimeException("调用JHFWTYRK服务失败", e);
        }
    }
}