add SoapClinet.reset

This commit is contained in:
Looly 2019-09-21 07:52:47 +08:00
parent 8d51e2343d
commit c648c8c945
2 changed files with 142 additions and 85 deletions

View File

@ -14,6 +14,7 @@
* 【core】 FileUtil.normalize在win下支持samba路径issue#549@Github
* 【core】 修复Validator注释错误pr#70@Gitee
* 【cron】 添加获取任务表的方法issue#I12E5H@Gitee
* 【http】 SoapClient增加reset方法用于此对象的复用issue#I12CCC@Gitee
### Bug修复
* 【core】 修复DateUtil.offset导致的时区错误问题issue#I1294O@Gitee

View File

@ -33,31 +33,66 @@ import cn.hutool.http.HttpResponse;
/**
* SOAP客户端
*
* <p>
* 此对象用于构建一个SOAP消息并通过HTTP接口发出消息内容
* SOAP消息本质上是一个XML文本可以通过调用{@link #getMsgStr(boolean)} 方法获取消息体
* <p>
* 使用方法
*
* <pre>
* SoapClient client = SoapClient.create(url)
* .setMethod(methodName, namespaceURI)
* .setCharset(CharsetUtil.CHARSET_GBK)
* .setParam(param1, "XXX");
*
* String response = client.send(true);
*
* </pre>
*
* @author looly
* @since 4.5.4
*/
public class SoapClient {
/** XML消息体的Content-Type */
/**
* XML消息体的Content-Type
*/
private static final String TEXT_XML_CONTENT_TYPE = "text/xml;charset=";
/** 请求的URL地址 */
/**
* 请求的URL地址
*/
private String url;
/** 编码 */
/**
* 编码
*/
private Charset charset = CharsetUtil.CHARSET_UTF_8;
/** SOAP消息 */
private SOAPMessage message;
/** 消息方法节点 */
private SOAPBodyElement methodEle;
/** 应用于方法上的命名空间URI */
private String namespaceURI;
/** 消息工厂,用于创建消息 */
private MessageFactory factory;
/** 默认连接超时 */
/**
* 默认连接超时
*/
private int connectionTimeout = HttpGlobalConfig.getTimeout();
/** 默认读取超时 */
/**
* 默认读取超时
*/
private int readTimeout = HttpGlobalConfig.getTimeout();
/**
* 消息工厂用于创建消息
*/
private MessageFactory factory;
/**
* SOAP消息
*/
private SOAPMessage message;
/**
* 消息方法节点
*/
private SOAPBodyElement methodEle;
/**
* 应用于方法上的命名空间URI
*/
private String namespaceURI;
/**
* 创建SOAP客户端默认使用soap1.1版本协议
*
@ -144,6 +179,26 @@ public class SoapClient {
return this;
}
/**
* 重置SOAP客户端用于客户端复用
*
* <p>
* 重置后需调用serMethod方法重新指定请求方法并调用setParam方法重新定义参数
*
* @return this
* @since 4.6.7
*/
public SoapClient reset() {
try {
this.message = factory.createMessage();
} catch (SOAPException e) {
throw new SoapRuntimeException(e);
}
this.methodEle = null;
return this;
}
/**
* 设置编码
*
@ -482,6 +537,7 @@ public class SoapClient {
}
// -------------------------------------------------------------------------------------------------------- Private method start
/**
* 发送请求获取异步响应
*