Skip to content

Commit f2577cf

Browse files
authored
bugfix: fix post method in HttpClientUtil (#6835)
1 parent 8844ce9 commit f2577cf

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

changes/en-us/2.x.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Add changes here for all PR submitted to the 2.x branch.
3737
- [[#6817](https://github.com/apache/incubator-seata/pull/6817)] bugfix: fix namingserver changVgroup failed
3838
- [[#6820](https://github.com/apache/incubator-seata/pull/6820)] Fix file path error in the Dockerfile
3939
- [[#6825](https://github.com/apache/incubator-seata/pull/6825)] Fix the issue of XA mode transaction timeout and inability to roll back in Postgres
40+
- [[#6835](https://github.com/apache/incubator-seata/pull/6835)] Fix the issue of missing request body of post method in HttpClientUtil
4041

4142

4243
### optimize:
@@ -135,5 +136,6 @@ Thanks to these contributors for their code commits. Please report an unintended
135136
- [laywin](https://github.com/laywin)
136137
- [xingfudeshi](https://github.com/xingfudeshi)
137138
- [xiaoxiangyeyu0](https://github.com/xiaoxiangyeyu0)
139+
- [LegGasai](https://github.com/LegGasai)
138140

139141
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.

changes/zh-cn/2.x.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
- [[#6817](https://github.com/apache/incubator-seata/pull/6817)] 修复namingserver切换事务分组失效的问题
3939
- [[#6820](https://github.com/apache/incubator-seata/pull/6820)] 修复Dockerfile得文件结构错误
4040
- [[#6825](https://github.com/apache/incubator-seata/pull/6825)] 修复Postgres的XA模式事务超时无法回滚问题
41-
-
41+
- [[#6835](https://github.com/apache/incubator-seata/pull/6835)] 修复HttpClientUtil中post方法请求体缺失的问题
42+
4243
### optimize:
4344
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] 拆分 committing 和 rollbacking 状态的任务线程池
4445
- [[#6208](https://github.com/apache/incubator-seata/pull/6208)] 支持多版本的Seata序列化
@@ -136,6 +137,7 @@
136137
- [laywin](https://github.com/laywin)
137138
- [xingfudeshi](https://github.com/xingfudeshi)
138139
- [xiaoxiangyeyu0](https://github.com/xiaoxiangyeyu0)
140+
- [LegGasai](https://github.com/LegGasai)
139141

140142
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
141143

common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.seata.common.util;
1818

1919

20+
import com.fasterxml.jackson.databind.ObjectMapper;
2021
import org.apache.http.NameValuePair;
2122
import org.apache.http.client.ClientProtocolException;
2223
import org.apache.http.client.config.RequestConfig;
@@ -52,6 +53,7 @@ public class HttpClientUtil {
5253

5354
private static final PoolingHttpClientConnectionManager POOLING_HTTP_CLIENT_CONNECTION_MANAGER =
5455
new PoolingHttpClientConnectionManager();
56+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
5557

5658
static {
5759
POOLING_HTTP_CLIENT_CONNECTION_MANAGER.setMaxTotal(10);
@@ -89,6 +91,10 @@ public static CloseableHttpResponse doPost(String url, Map<String, String> param
8991
String requestBody = URLEncodedUtils.format(nameValuePairs, StandardCharsets.UTF_8);
9092
StringEntity stringEntity = new StringEntity(requestBody, ContentType.APPLICATION_FORM_URLENCODED);
9193
httpPost.setEntity(stringEntity);
94+
} else if (ContentType.APPLICATION_JSON.getMimeType().equals(contentType)) {
95+
String requestBody = OBJECT_MAPPER.writeValueAsString(params);
96+
StringEntity stringEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
97+
httpPost.setEntity(stringEntity);
9298
}
9399
}
94100
CloseableHttpClient client = HTTP_CLIENT_MAP.computeIfAbsent(timeout,

0 commit comments

Comments
 (0)