YvCeung commented on code in PR #7903:
URL: https://github.com/apache/incubator-seata/pull/7903#discussion_r2657054311
##########
common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java:
##########
@@ -265,25 +188,77 @@ private static String buildUrlWithParams(String url,
Map<String, String> params)
return urlBuilder.toString();
}
- private static void executeAsync(OkHttpClient client, Request request,
final HttpCallback<Response> callback) {
- client.newCall(request).enqueue(new Callback() {
- @Override
- public void onResponse(Call call, Response response) {
- try {
- callback.onSuccess(response);
- } finally {
- response.close();
- }
- }
+ private static OkHttpClient createHttp2WatchClient(int
connectTimeoutSeconds) {
+ return new OkHttpClient.Builder()
+
.protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE))
+ .connectTimeout(connectTimeoutSeconds, TimeUnit.SECONDS) //
连接阶段快速失败
+ .readTimeout(0, TimeUnit.SECONDS) // 等待TC推送数据(建立连接后持续监听服务器推送)
+ .writeTimeout(connectTimeoutSeconds, TimeUnit.SECONDS)
+ .build();
+ }
- @Override
- public void onFailure(Call call, IOException e) {
- if (call.isCanceled()) {
- callback.onCancelled();
- } else {
- callback.onFailure(e);
- }
- }
- });
+ public static <T> SeataHttpWatch<T> watch(String url, Map<String, String>
headers, Class<T> eventType)
+ throws IOException {
+ return watch(url, headers, null, "GET", eventType);
+ }
+
+ public static <T> SeataHttpWatch<T> watch(String url, Class<T> eventType)
throws IOException {
+ return watch(url, null, null, "GET", eventType);
+ }
Review Comment:
The non-empty url determination will be uniformly performed in the
underlying watch method
```java
private static <T> SeataHttpWatch<T> watch(
String url, Map<String, String> headers, RequestBody
requestBody, String method, Class<T> eventType)
throws IOException {
if (StringUtils.isBlank(url)) {
throw new IllegalArgumentException("URL must not be null or
blank");
}
OkHttpClient client =
createHttp2WatchClient(HTTP2_WATCH_CONNECT_TIMEOUT_SECONDS);
Request request = buildHttp2WatchRequest(url, headers, requestBody,
method);
return SeataHttpWatch.createWatch(client, request, eventType);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]