-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.x' into feature_support_spring_acturator_2.x
- Loading branch information
Showing
41 changed files
with
620 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Add changes here for all PR submitted to the 2.x branch. | ||
|
||
<!-- Please add the `changes` to the following location(feature/bugfix/optimize/test) based on the type of PR --> | ||
|
||
### feature: | ||
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] A brief and accurate description of PR | ||
|
||
### bugfix: | ||
- [[#6075](https://github.com/seata/seata/pull/6075)] fix missing table alias for on update column of image SQL | ||
|
||
### optimize: | ||
- [[#6031](https://github.com/seata/seata/pull/6031)] add a check for the existence of the undolog table | ||
|
||
### security: | ||
- [[#6069](https://github.com/seata/seata/pull/6069)] Upgrade Guava dependencies to fix security vulnerabilities | ||
|
||
### test: | ||
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] A brief and accurate description of PR | ||
|
||
Thanks to these contributors for their code commits. Please report an unintended omission. | ||
|
||
<!-- Please make sure your Github ID is in the list below --> | ||
- [slievrly](https://github.com/slievrly) | ||
- [ptyin](https://github.com/ptyin) | ||
- [laywin](https://github.com/laywin) | ||
- [imcmai](https://github.com/imcmai) | ||
|
||
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
所有提交到 2.x 分支的 PR 请在此处登记。 | ||
|
||
<!-- 请根据PR的类型添加 `变更记录` 到以下对应位置(feature/bugfix/optimize/test) 下 --> | ||
|
||
### feature: | ||
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] 准确简要的PR描述 | ||
|
||
### bugfix: | ||
- [[#6075](https://github.com/seata/seata/pull/6075)] 修复镜像SQL对于on update列没有添加表别名的问题 | ||
|
||
### optimize: | ||
- [[#6031](https://github.com/seata/seata/pull/6031)] 添加undo_log表的存在性校验 | ||
|
||
### security: | ||
- [[#6069](https://github.com/seata/seata/pull/6069)] 升级Guava依赖版本,修复安全漏洞 | ||
|
||
### test: | ||
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] 准确简要的PR描述 | ||
|
||
非常感谢以下 contributors 的代码贡献。若有无意遗漏,请报告。 | ||
|
||
<!-- 请确保您的 GitHub ID 在以下列表中 --> | ||
- [slievrly](https://github.com/slievrly) | ||
- [ptyin](https://github.com/ptyin) | ||
- [laywin](https://github.com/laywin) | ||
- [imcmai](https://github.com/imcmai) | ||
|
||
|
||
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
common/src/main/java/io/seata/common/util/HttpClientUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.seata.common.util; | ||
|
||
|
||
import org.apache.http.NameValuePair; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.apache.http.client.utils.URLEncodedUtils; | ||
import org.apache.http.entity.ContentType; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.apache.http.message.BasicNameValuePair; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author funkye | ||
*/ | ||
public class HttpClientUtil { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientUtil.class); | ||
|
||
private static final Map<Integer/*timeout*/, CloseableHttpClient> HTTP_CLIENT_MAP = new ConcurrentHashMap<>(); | ||
|
||
private static final PoolingHttpClientConnectionManager POOLING_HTTP_CLIENT_CONNECTION_MANAGER = | ||
new PoolingHttpClientConnectionManager(); | ||
|
||
static { | ||
POOLING_HTTP_CLIENT_CONNECTION_MANAGER.setMaxTotal(10); | ||
POOLING_HTTP_CLIENT_CONNECTION_MANAGER.setDefaultMaxPerRoute(10); | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> HTTP_CLIENT_MAP.values().parallelStream().forEach(client -> { | ||
try { | ||
client.close(); | ||
} catch (IOException e) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
}))); | ||
} | ||
|
||
// post request | ||
public static CloseableHttpResponse doPost(String url, Map<String, String> params, Map<String, String> header, | ||
int timeout) throws IOException { | ||
try { | ||
URIBuilder builder = new URIBuilder(url); | ||
URI uri = builder.build(); | ||
HttpPost httpPost = new HttpPost(uri); | ||
if (header != null) { | ||
header.forEach(httpPost::addHeader); | ||
} | ||
List<NameValuePair> nameValuePairs = new ArrayList<>(); | ||
params.forEach((k, v) -> { | ||
nameValuePairs.add(new BasicNameValuePair(k, v)); | ||
}); | ||
String requestBody = URLEncodedUtils.format(nameValuePairs, StandardCharsets.UTF_8); | ||
|
||
StringEntity stringEntity = new StringEntity(requestBody, ContentType.APPLICATION_FORM_URLENCODED); | ||
httpPost.setEntity(stringEntity); | ||
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); | ||
CloseableHttpClient client = HTTP_CLIENT_MAP.computeIfAbsent(timeout, | ||
k -> HttpClients.custom().setConnectionManager(POOLING_HTTP_CLIENT_CONNECTION_MANAGER) | ||
.setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(timeout) | ||
.setSocketTimeout(timeout).setConnectTimeout(timeout).build()) | ||
.build()); | ||
return client.execute(httpPost); | ||
} catch (URISyntaxException | ClientProtocolException e) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
return null; | ||
} | ||
|
||
// get request | ||
public static CloseableHttpResponse doGet(String url, Map<String, String> param, Map<String, String> header, | ||
int timeout) throws IOException { | ||
try { | ||
URIBuilder builder = new URIBuilder(url); | ||
if (param != null) { | ||
for (String key : param.keySet()) { | ||
builder.addParameter(key, param.get(key)); | ||
} | ||
} | ||
URI uri = builder.build(); | ||
HttpGet httpGet = new HttpGet(uri); | ||
if (header != null) { | ||
header.forEach(httpGet::addHeader); | ||
} | ||
CloseableHttpClient client = HTTP_CLIENT_MAP.computeIfAbsent(timeout, | ||
k -> HttpClients.custom().setConnectionManager(POOLING_HTTP_CLIENT_CONNECTION_MANAGER) | ||
.setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(timeout) | ||
.setSocketTimeout(timeout).setConnectTimeout(timeout).build()) | ||
.build()); | ||
return client.execute(httpGet); | ||
} catch (URISyntaxException | ClientProtocolException e) { | ||
LOGGER.error(e.getMessage(), e); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.