JavaEE--调用 WSDL -- httpclient 4.x.x
参考:http://aperise.iteye.com/blog/2223454
http://blog.csdn.net/chenleixing/article/details/43456987
package explore; import java.io.IOException;
import java.nio.charset.Charset; import org.apache.commons.lang.StringEscapeUtils;
import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import util.IOUtil; public class HttpClientWay1 { static int socketTimeout = 30000;// 请求超时时间
static int connectTimeout = 30000;// 传输超时时间 public static void main(String[] args) {
try {
// wsdl
// http://fw1test.shdzfp.com:7500/axis2/services/SajtIssueInvoiceService
String con; // 组织推送报文
// con = GenerateXml.shift_plus("pt_kpttxx.xml");
con = IOUtil.msgMachine("my.xml");
System.out.println(con); // 创建HttpClientBuilder
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
HttpPost httpPost = new HttpPost("http://fw1test.shdzfp.com:7500/axis2/services/SajtIssueInvoiceService"); // 设置请求和传输超时时间
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)
.setConnectTimeout(connectTimeout).build();
httpPost.setConfig(requestConfig); httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");
httpPost.setHeader("SOAPAction", "");
StringEntity data = new StringEntity(con, Charset.forName("UTF-8"));
httpPost.setEntity(data);
CloseableHttpResponse response = closeableHttpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
// 打印响应内容
String retStr = EntityUtils.toString(httpEntity, "UTF-8");
retStr = StringEscapeUtils.unescapeXml(retStr);// 反转义
System.out.println(retStr);
}
// 释放资源
closeableHttpClient.close();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
附 wsdl 内容:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://service.sl.shdzfp.sajt" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://service.sl.shdzfp.sajt">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.sl.shdzfp.sajt">
<xs:element name="eiInterface">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="in0" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="eiInterfaceResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="eiInterfaceRequest">
<wsdl:part name="parameters" element="ns:eiInterface"></wsdl:part>
</wsdl:message>
<wsdl:message name="eiInterfaceResponse">
<wsdl:part name="parameters" element="ns:eiInterfaceResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="SajtIssueInvoiceServicePortType">
<wsdl:operation name="eiInterface">
<wsdl:input message="ns:eiInterfaceRequest" wsaw:Action="urn:eiInterface"></wsdl:input>
<wsdl:output message="ns:eiInterfaceResponse" wsaw:Action="urn:eiInterfaceResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SajtIssueInvoiceServiceSoap11Binding" type="ns:SajtIssueInvoiceServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="eiInterface">
<soap:operation soapAction="urn:eiInterface" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="SajtIssueInvoiceServiceSoap12Binding" type="ns:SajtIssueInvoiceServicePortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="eiInterface">
<soap12:operation soapAction="urn:eiInterface" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="SajtIssueInvoiceServiceHttpBinding" type="ns:SajtIssueInvoiceServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="eiInterface">
<http:operation location="SajtIssueInvoiceService/eiInterface"/>
<wsdl:input>
<mime:content part="eiInterface" type="text/xml"/>
</wsdl:input>
<wsdl:output>
<mime:content part="eiInterface" type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SajtIssueInvoiceService">
<wsdl:port name="SajtIssueInvoiceServiceHttpSoap11Endpoint" binding="ns:SajtIssueInvoiceServiceSoap11Binding">
<soap:address location="http://fw1test.shdzfp.com:7500/axis2/services/SajtIssueInvoiceService.SajtIssueInvoiceServiceHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="SajtIssueInvoiceServiceHttpEndpoint" binding="ns:SajtIssueInvoiceServiceHttpBinding">
<http:address location="http://fw1test.shdzfp.com:7500/axis2/services/SajtIssueInvoiceService.SajtIssueInvoiceServiceHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
JavaEE--调用 WSDL -- httpclient 4.x.x的更多相关文章
- C# 不添加WEB引用调用WSDL接口
在项目中添加WEB引用耦合度较高,更新时要更新引用,所以我建议不添加WEB引用调用WSDL接口,废话不多说,直接上代码 例如WSDL地址为:http://XXX.XX.XXX.XXX:9115/WsP ...
- php7-soap调用wsdl接口报错:Could not connect to host
由php5.6升级到php7.1以上版本,在用soap调用wsdl接口是报错:Could not connect to host 后来经过排查是centos服务器上装有2个版本的openssl造成的. ...
- axis2调用WSDL接口
public static JSONObject sendWsdl(String url,String xmlStr){ JSONObject res=new JSONObject(); try { ...
- 采用WebService客户端调用WSDL/SOAP网络报错的解决办法
WebService接口是网络传输控制的重要途径,在Windows系统下运行客户端时,平时一直能正确运行,但某天可能突然会发生调用wsdl soap邮件标头无法识别等莫名其妙的错误提示,出现这种情况一 ...
- C#/Java 调用WSDL接口及方法
一.C#利用vs里面自带的“添加web引用”功能: 1.首先需要清楚WSDL的引用地址 如:http://www.webxml.com.cn/Webservices/WeatherWebServic ...
- java 调用wsdl的webservice接口 两种调用方式
关于wsdl接口对于我来说是比较头疼的 基本没搞过.一脸懵 就在网上搜 看着写的都很好到我这就不好使了,非常蓝瘦.谨以此随笔纪念我这半个月踩过的坑... 背景:短短两周除了普通开发外我就接到了两个we ...
- cxf动态调用wsdl的一个冲突以及解决
cxf发布服务,调用服务的博客很多,这里也就简单贴一下代代码. 环境如下:spring+cxf (maven环境) <cxf.version>2.7.11</cxf.version& ...
- http调用端HttpClient、DefaultHttpClient、CloseableHttpClient
1:说下httpClient接口和4.2.6版本后过时实例DefaultHttpClient,以及新的实例应用. 说到HTTP,脑子就冒出它的特性,基于TCP协议,简短点:说明是交互性的. 2:下面 ...
- java-webService(调用wsdl接口)
使用Axis或XFire实现WebService: Axis2是Apache下的一个重量级WebService框架,准确说它是一个Web Services / SOAP / WSDL 的引擎,是Web ...
- C#.NET调用WSDL接口及方法
1.首先需要清楚WSDL的引用地址 如:http://XX.XX.4.146:8089/axis/services/getfileno?wsdl 上述地址的构造为 类名getfileno. 2.在.N ...
随机推荐
- TRUNC()函数——oracle
使用trunc()函数获取不同的日期: select trunc(sysdate) from dual; --今天的日期 select trunc(sysdate,'dd') from dual; - ...
- hdu 2578 Dating with girls(1) 满足条件x+y=k的x,y有几组
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 利用标签导出Word文档
1 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; us ...
- HDU 5282:Senior's String
Senior's String Accepts: 30 Submissions: 286 Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- 大二暑假第七周总结--开始学习Hadoop基础(六)
复习关于Hadoop的操作语句以及重点 Shell版 跳转目录到Hadoop: cd /usr/local/hadoop 启动Hadoop: ./sbin/start-dfs.sh 注意:Hadoop ...
- MySQL 字符集和校验规则工作流程
MySQL 字符集和校验规则工作原理 字符编码相关参数 数据流中的转码过程 校验规则 Tips:字符集和校验规则总是相伴的 一 从简单的建库语句开始 CREATE DATABASE [IF NOT E ...
- 二十、CI框架数据库操作之查看生产的sql语句
一.代码如下: 二.我们访问一下: 三.我们对比一下数据库内容 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.
- Essay写作的灵魂:内容
在国内大家也许不觉得时常要写essay,但在国外留学,时不时就会有一篇essay写作任务下来.而时常写文的同学们应当就会知道一篇文章中的介绍和结论有多么重要,甚至于当导师拿到你的essay,如果摘要没 ...
- 进度3_家庭记账本App_Fragment使用SQLite实现简单存储及查询
AddFragment.java: package com.example.familybooks; import android.content.ContentValues; import andr ...
- 洛谷 P1020 导弹拦截
题目传送门 解题思路: 其实就是求一遍最长不上升子序列和最长上升子序列 AC代码: #include<iostream> #include<cstdio> #include&l ...