Skip to content

bugfix: fix post method in HttpClientUtil #6835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading