Skip to content

Commit

Permalink
bugfix: fix post method in HttpClientUtil (#6835)
Browse files Browse the repository at this point in the history
  • Loading branch information
LegGasai authored Sep 10, 2024
1 parent 8844ce9 commit f2577cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
4 changes: 3 additions & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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序列化
Expand Down Expand Up @@ -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和建议,非常感谢大家。

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -89,6 +91,10 @@ public static CloseableHttpResponse doPost(String url, Map<String, String> param
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,
Expand Down

0 comments on commit f2577cf

Please sign in to comment.