博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaEE--调用 WSDL -- httpclient 4.x.x
阅读量:5096 次
发布时间:2019-06-13

本文共 4204 字,大约阅读时间需要 14 分钟。

参考:

     

1 package explore; 2  3 import java.io.IOException; 4 import java.nio.charset.Charset; 5  6 import org.apache.commons.lang.StringEscapeUtils; 7 import org.apache.http.HttpEntity; 8 import org.apache.http.ParseException; 9 import org.apache.http.client.ClientProtocolException;10 import org.apache.http.client.config.RequestConfig;11 import org.apache.http.client.methods.CloseableHttpResponse;12 import org.apache.http.client.methods.HttpPost;13 import org.apache.http.entity.StringEntity;14 import org.apache.http.impl.client.CloseableHttpClient;15 import org.apache.http.impl.client.HttpClientBuilder;16 import org.apache.http.util.EntityUtils;17 18 import util.IOUtil;19 20 public class HttpClientWay1 {21 22     static int socketTimeout = 30000;// 请求超时时间23     static int connectTimeout = 30000;// 传输超时时间24 25     public static void main(String[] args) {26         try {27             // wsdl28             // http://fw1test.shdzfp.com:7500/axis2/services/SajtIssueInvoiceService29             String con;30 31             // 组织推送报文32             // con = GenerateXml.shift_plus("pt_kpttxx.xml");33             con = IOUtil.msgMachine("my.xml");34             System.out.println(con);35 36             // 创建HttpClientBuilder37             HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();38             // HttpClient39             CloseableHttpClient closeableHttpClient = httpClientBuilder.build();40             HttpPost httpPost = new HttpPost("http://fw1test.shdzfp.com:7500/axis2/services/SajtIssueInvoiceService");41 42             // 设置请求和传输超时时间43             RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)44                     .setConnectTimeout(connectTimeout).build();45             httpPost.setConfig(requestConfig);46 47             httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");48             httpPost.setHeader("SOAPAction", "");49             StringEntity data = new StringEntity(con, Charset.forName("UTF-8"));50             httpPost.setEntity(data);51             CloseableHttpResponse response = closeableHttpClient.execute(httpPost);52             HttpEntity httpEntity = response.getEntity();53             if (httpEntity != null) {54                 // 打印响应内容55                 String retStr = EntityUtils.toString(httpEntity, "UTF-8");56                 retStr = StringEscapeUtils.unescapeXml(retStr);// 反转义57                 System.out.println(retStr);58             }59             // 释放资源60             closeableHttpClient.close();61         } catch (ClientProtocolException e) {62             // TODO Auto-generated catch block63             e.printStackTrace();64         } catch (ParseException e) {65             // TODO Auto-generated catch block66             e.printStackTrace();67         } catch (IOException e) {68             // TODO Auto-generated catch block69             e.printStackTrace();70         } catch (Exception e) {71             // TODO Auto-generated catch block72             e.printStackTrace();73         }74     }75 76 }

 

附 wsdl 内容:

1 This XML file does not appear to have any style information associated with it. The document tree is shown below. 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

 

转载于:https://www.cnblogs.com/microcat/p/6993362.html

你可能感兴趣的文章
elasticsearch插件
查看>>
如约而至:微信自用的移动端IM网络层跨平台组件库Mars已正式开源
查看>>
C#winform在textbox插入内容换行
查看>>
luogu P1220 关路灯
查看>>
后台往前台写弹窗代码不显示
查看>>
Altium Designer 电源部分
查看>>
Hive读取外表数据时跳过文件行首和行尾
查看>>
C#入门
查看>>
spring-mybatis项目练习 - 通讯录系统,ssm配置文件部分
查看>>
Java判断数据库表是否存在的方法
查看>>
将博客搬至CSDN
查看>>
模型驱动设计的构造块
查看>>
screen窗口管理器
查看>>
Oracle总结之plsql编程(基础九)
查看>>
转:Java Annotation入门(二)(中英文结合)
查看>>
Python从入门到入土-Pycharm如何使用python3
查看>>
java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter
查看>>
TensorFlow+Keras 01 人工智能、机器学习、深度学习简介
查看>>
js控制页面显示
查看>>
Linux 学习手记(6): 磁盘、分区、MBR与GPT
查看>>