diff --git a/CHANGELOG.md b/CHANGELOG.md index 322aa28bd..7a5013547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * 【core 】 支持BeanUtil.toBean(object, Map.class)转换(issue#I1I4HC@Gitee) * 【core 】 MapUtil和CollUtil增加clear方法(issue#I1I4HC@Gitee) * 【core 】 增加FontUtil,可定义pressText是否从中间(issue#I1HSWU@Gitee) +* 【core 】 SoapClient支持自定义请求头(issue#I1I0AO@Gitee) ### Bug修复 * 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpBase.java b/hutool-http/src/main/java/cn/hutool/http/HttpBase.java index 083441d31..7e9aa63ca 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpBase.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpBase.java @@ -271,7 +271,7 @@ public abstract class HttpBase { */ public T charset(String charset) { if(StrUtil.isNotBlank(charset)){ - this.charset = Charset.forName(charset); + charset(Charset.forName(charset)); } return (T) this; } diff --git a/hutool-http/src/main/java/cn/hutool/http/webservice/SoapClient.java b/hutool-http/src/main/java/cn/hutool/http/webservice/SoapClient.java index 6c5794f49..d2dfc74b6 100644 --- a/hutool-http/src/main/java/cn/hutool/http/webservice/SoapClient.java +++ b/hutool-http/src/main/java/cn/hutool/http/webservice/SoapClient.java @@ -3,10 +3,10 @@ package cn.hutool.http.webservice; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.XmlUtil; +import cn.hutool.http.HttpBase; import cn.hutool.http.HttpGlobalConfig; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; @@ -51,7 +51,7 @@ import java.util.Map.Entry; * @author looly * @since 4.5.4 */ -public class SoapClient { +public class SoapClient extends HttpBase { /** * XML消息体的Content-Type @@ -62,10 +62,7 @@ public class SoapClient { * 请求的URL地址 */ private String url; - /** - * 编码 - */ - private Charset charset = CharsetUtil.CHARSET_UTF_8; + /** * 默认连接超时 */ @@ -203,11 +200,17 @@ public class SoapClient { * * @param charset 编码 * @return this + * @see #charset(Charset) */ public SoapClient setCharset(Charset charset) { - this.charset = charset; + return this.charset(charset); + } + + @Override + public SoapClient charset(Charset charset) { + super.charset(charset); try { - this.message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, this.charset.toString()); + this.message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, this.charset()); this.message.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true"); } catch (SOAPException e) { // ignore @@ -228,17 +231,45 @@ public class SoapClient { } /** - * 设置头信息 + * 设置SOAP头信息 + * + * @param name 头信息标签名 + * @return this + * @deprecated 为了和Http Hrader区分,请使用{@link #setSOAPHeader(QName)} + */ + @Deprecated + public SoapClient setHeader(QName name) { + return setSOAPHeader(name, null, null, null, null); + } + + /** + * 设置SOAP头信息 * * @param name 头信息标签名 * @return this */ - public SoapClient setHeader(QName name) { - return setHeader(name, null, null, null, null); + public SoapClient setSOAPHeader(QName name) { + return setSOAPHeader(name, null, null, null, null); } /** - * 设置头信息 + * 设置SOAP头信息 + * + * @param name 头信息标签名 + * @param actorURI 中间的消息接收者 + * @param roleUri Role的URI + * @param mustUnderstand 标题项对于要对其进行处理的接收者来说是强制的还是可选的 + * @param relay relay属性 + * @return this + * @deprecated 为了和Http Hrader区分,请使用{@link #setSOAPHeader(QName, String, String, Boolean, Boolean)} + */ + @Deprecated + public SoapClient setHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay) { + return setSOAPHeader(name, actorURI, roleUri, mustUnderstand, relay); + } + + /** + * 设置SOAP头信息 * * @param name 头信息标签名 * @param actorURI 中间的消息接收者 @@ -247,7 +278,7 @@ public class SoapClient { * @param relay relay属性 * @return this */ - public SoapClient setHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay) { + public SoapClient setSOAPHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay) { SOAPHeader header; SOAPHeaderElement ele; try { @@ -548,6 +579,7 @@ public class SoapClient { .setConnectionTimeout(this.connectionTimeout) .setReadTimeout(this.readTimeout) .contentType(getXmlContentType())// + .header(this.headers()) .body(getMsgStr(false))// .executeAsync(); }