Skip to content

Commit 236a374

Browse files
committed
chore: update
1 parent 7b39969 commit 236a374

File tree

1 file changed

+2
-66
lines changed
  • capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/http

1 file changed

+2
-66
lines changed

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/http/AwsCapaHttp.java

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,15 @@
2727
import group.rxcloud.capa.spi.http.config.RpcServiceOptions;
2828
import group.rxcloud.cloudruntimes.domain.core.invocation.HttpExtension;
2929
import group.rxcloud.cloudruntimes.utils.TypeRef;
30-
import okhttp3.Headers;
3130
import okhttp3.OkHttpClient;
32-
import okhttp3.Request;
33-
import okhttp3.RequestBody;
3431
import org.slf4j.Logger;
3532
import org.slf4j.LoggerFactory;
3633
import software.amazon.awssdk.utils.StringUtils;
3734

38-
import java.util.ArrayList;
3935
import java.util.List;
4036
import java.util.Map;
4137
import java.util.Objects;
4238
import java.util.concurrent.CompletableFuture;
43-
import java.util.stream.Collectors;
4439

4540

4641
/**
@@ -82,32 +77,6 @@ protected <T> CompletableFuture<HttpResponse<T>> invokeSpiApi(String appId,
8277
(AwsRpcServiceOptions) rpcServiceOptions);
8378
}
8479

85-
private static final String ACCEPT_KEY = "accept";
86-
private static final String ACCEPT_ALL = "*/*";
87-
88-
private void setRequestHeaderOfAccept(Map<String, String> headers, RequestBody body) {
89-
final List<String> accepts = new ArrayList<>(3);
90-
// 1. set user accept header
91-
final String userAcceptValue = headers.get(ACCEPT_KEY);
92-
if (userAcceptValue != null && userAcceptValue.length() > 0) {
93-
accepts.add(userAcceptValue);
94-
}
95-
// 2. set accept header same with content-type
96-
if (body.contentType() != null) {
97-
final String contentType = Objects.requireNonNull(body.contentType()).toString();
98-
if (contentType.length() > 0) {
99-
accepts.add(contentType);
100-
}
101-
}
102-
// 3. add */* at last
103-
accepts.add(ACCEPT_ALL);
104-
105-
final String acceptStr = accepts.stream()
106-
.distinct()
107-
.collect(Collectors.joining(","));
108-
headers.put(ACCEPT_KEY, acceptStr);
109-
}
110-
11180
private interface AwsHttpInvoker {
11281

11382
/**
@@ -208,46 +177,13 @@ private <T> CompletableFuture<HttpResponse<T>> doAsyncInvoke(String method,
208177
}
209178

210179
// async invoke
211-
CompletableFuture<HttpResponse<T>> asyncInvoke0 = invokeHttp(
180+
return invokeHttpFacade(
212181
appMeshHttpUrl,
213182
requestData,
214183
httpMethod,
215184
headers,
185+
urlParameters,
216186
type);
217-
asyncInvoke0.exceptionally(throwable -> {
218-
if (logger.isWarnEnabled()) {
219-
logger.warn("[Capa.Rpc.Client.http] [AwsCapaHttp.doAsyncInvoke] async invoke error", throwable);
220-
}
221-
throw new CapaException(CapaErrorContext.DEPENDENT_SERVICE_ERROR, throwable);
222-
});
223-
return asyncInvoke0;
224-
}
225-
226-
private <T> CompletableFuture<HttpResponse<T>> invokeHttp(String url,
227-
Object requestData,
228-
String httpMethod,
229-
Map<String, String> headers,
230-
TypeRef<T> type) {
231-
// generate http request body
232-
RequestBody body = getRequestBodyWithSerialize(requestData, headers);
233-
234-
setRequestHeaderOfAccept(headers, body);
235-
236-
Headers header = getRequestHeaderWithParams(headers);
237-
238-
if (logger.isDebugEnabled()) {
239-
logger.debug("[Capa.Rpc.Client.http] [AwsCapaHttp.invokeHttp] final request url[{}] header[{}] httpMethod[{}]",
240-
url, header, httpMethod);
241-
}
242-
243-
// make http request
244-
Request request = new Request.Builder()
245-
.url(url)
246-
.headers(header)
247-
.method(httpMethod, body)
248-
.build();
249-
250-
return doAsyncInvoke0(request, type);
251187
}
252188
}
253189
}

0 commit comments

Comments
 (0)