This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new f2577cf76b bugfix: fix post method in HttpClientUtil (#6835)
f2577cf76b is described below

commit f2577cf76bbe2514a7d7fa7928e1bad748bab58a
Author: LegGasai <75920107+legga...@users.noreply.github.com>
AuthorDate: Tue Sep 10 09:37:57 2024 +0800

    bugfix: fix post method in HttpClientUtil (#6835)
---
 changes/en-us/2.x.md                                                | 2 ++
 changes/zh-cn/2.x.md                                                | 4 +++-
 .../src/main/java/org/apache/seata/common/util/HttpClientUtil.java  | 6 ++++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index bd2309a8da..26d0f5e101 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -37,6 +37,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#6817](https://github.com/apache/incubator-seata/pull/6817)] bugfix: fix 
namingserver changVgroup failed
 - [[#6820](https://github.com/apache/incubator-seata/pull/6820)] Fix file path 
error in the Dockerfile
 - [[#6825](https://github.com/apache/incubator-seata/pull/6825)] Fix the issue 
of XA mode transaction timeout and inability to roll back in Postgres
+- [[#6835](https://github.com/apache/incubator-seata/pull/6835)] Fix the issue 
of missing request body of post method in HttpClientUtil
 
 
 ### optimize:
@@ -135,5 +136,6 @@ Thanks to these contributors for their code commits. Please 
report an unintended
 - [laywin](https://github.com/laywin)
 - [xingfudeshi](https://github.com/xingfudeshi)
 - [xiaoxiangyeyu0](https://github.com/xiaoxiangyeyu0)
+- [LegGasai](https://github.com/LegGasai)
 
 Also, we receive many valuable issues, questions and advices from our 
community. Thanks for you all.
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index ee3343d2f9..4a3a7ec7e6 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -38,7 +38,8 @@
 - [[#6817](https://github.com/apache/incubator-seata/pull/6817)] 
修复namingserver切换事务分组失效的问题
 - [[#6820](https://github.com/apache/incubator-seata/pull/6820)] 
修复Dockerfile得文件结构错误
 - [[#6825](https://github.com/apache/incubator-seata/pull/6825)] 
修复Postgres的XA模式事务超时无法回滚问题
-- 
+- [[#6835](https://github.com/apache/incubator-seata/pull/6835)] 
修复HttpClientUtil中post方法请求体缺失的问题
+
 ### optimize:
 - [[#6499](https://github.com/apache/incubator-seata/pull/6499)] 拆分 committing 
和 rollbacking 状态的任务线程池
 - [[#6208](https://github.com/apache/incubator-seata/pull/6208)] 支持多版本的Seata序列化
@@ -136,6 +137,7 @@
 - [laywin](https://github.com/laywin)
 - [xingfudeshi](https://github.com/xingfudeshi)
 - [xiaoxiangyeyu0](https://github.com/xiaoxiangyeyu0)
+- [LegGasai](https://github.com/LegGasai)
 
 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
 
diff --git 
a/common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java 
b/common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java
index 63a5592acd..306c54b64a 100644
--- a/common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java
+++ b/common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java
@@ -17,6 +17,7 @@
 package org.apache.seata.common.util;
 
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.http.NameValuePair;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.config.RequestConfig;
@@ -52,6 +53,7 @@ public class HttpClientUtil {
 
     private static final PoolingHttpClientConnectionManager 
POOLING_HTTP_CLIENT_CONNECTION_MANAGER =
             new PoolingHttpClientConnectionManager();
+    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
     static {
         POOLING_HTTP_CLIENT_CONNECTION_MANAGER.setMaxTotal(10);
@@ -89,6 +91,10 @@ public class HttpClientUtil {
                     String requestBody = 
URLEncodedUtils.format(nameValuePairs, StandardCharsets.UTF_8);
                     StringEntity stringEntity = new StringEntity(requestBody, 
ContentType.APPLICATION_FORM_URLENCODED);
                     httpPost.setEntity(stringEntity);
+                } else if 
(ContentType.APPLICATION_JSON.getMimeType().equals(contentType)) {
+                    String requestBody = 
OBJECT_MAPPER.writeValueAsString(params);
+                    StringEntity stringEntity = new StringEntity(requestBody, 
ContentType.APPLICATION_JSON);
+                    httpPost.setEntity(stringEntity);
                 }
             }
             CloseableHttpClient client = 
HTTP_CLIENT_MAP.computeIfAbsent(timeout,


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to