|
27 | 27 | import group.rxcloud.capa.spi.http.config.RpcServiceOptions; |
28 | 28 | import group.rxcloud.cloudruntimes.domain.core.invocation.HttpExtension; |
29 | 29 | import group.rxcloud.cloudruntimes.utils.TypeRef; |
30 | | -import okhttp3.Headers; |
31 | 30 | import okhttp3.OkHttpClient; |
32 | | -import okhttp3.Request; |
33 | | -import okhttp3.RequestBody; |
34 | 31 | import org.slf4j.Logger; |
35 | 32 | import org.slf4j.LoggerFactory; |
36 | 33 | import software.amazon.awssdk.utils.StringUtils; |
37 | 34 |
|
38 | | -import java.util.ArrayList; |
39 | 35 | import java.util.List; |
40 | 36 | import java.util.Map; |
41 | 37 | import java.util.Objects; |
42 | 38 | import java.util.concurrent.CompletableFuture; |
43 | | -import java.util.stream.Collectors; |
44 | 39 |
|
45 | 40 |
|
46 | 41 | /** |
@@ -82,32 +77,6 @@ protected <T> CompletableFuture<HttpResponse<T>> invokeSpiApi(String appId, |
82 | 77 | (AwsRpcServiceOptions) rpcServiceOptions); |
83 | 78 | } |
84 | 79 |
|
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 | | - |
111 | 80 | private interface AwsHttpInvoker { |
112 | 81 |
|
113 | 82 | /** |
@@ -208,46 +177,13 @@ private <T> CompletableFuture<HttpResponse<T>> doAsyncInvoke(String method, |
208 | 177 | } |
209 | 178 |
|
210 | 179 | // async invoke |
211 | | - CompletableFuture<HttpResponse<T>> asyncInvoke0 = invokeHttp( |
| 180 | + return invokeHttpFacade( |
212 | 181 | appMeshHttpUrl, |
213 | 182 | requestData, |
214 | 183 | httpMethod, |
215 | 184 | headers, |
| 185 | + urlParameters, |
216 | 186 | 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); |
251 | 187 | } |
252 | 188 | } |
253 | 189 | } |
0 commit comments