Demo代码:https://github.com/earnext/test-webservice
需求:客户端调取服务端WebService接口插入用户数据。
目录:
- WebService生成客户端代码两种方式
- WebService常用注解
- 编写服务端(发布服务)
3.1. WebService服务端业务代码
3.2. WebService服务端配置(发布服务)- 编写客户端(调取接口)
4.1. 通过Apache CXF生成客户端代码调取WebService接口
4.2. 通过HttpURLConnection工具调取WebService接口
4.3. 通过HttpClient工具调取WebService接口
1.HttpURLConnection工具类
/**
* 发送webservice接口报文
* @author Dongxibao
* @date 2020-05-30
*/
@Slf4j
public class HttpURLConnectionXMLUtil {
public static InputStream send(String wsdlUrl, String xmlMessage) throws IOException {
if (StringUtils.isEmpty(wsdlUrl)) {
return null;
}
int timeout = 600000;
InputStream inputStream = null;
log.info("[HttpURLConnection]初始化 wsdlUrl:{}", wsdlUrl);
URL url = new URL(wsdlUrl);
log.info("[HttpURLConnection]开始设置 http 参数");
try {
HttpURLConnection httpURLConnection =