2525import group .rxcloud .capa .spi .aws .mesh .http .serializer .AwsCapaSerializerProvider ;
2626import group .rxcloud .capa .spi .http .CapaSerializeHttpSpi ;
2727import group .rxcloud .capa .spi .http .config .RpcServiceOptions ;
28+ import group .rxcloud .cloudruntimes .domain .core .invocation .HttpExtension ;
2829import group .rxcloud .cloudruntimes .utils .TypeRef ;
2930import okhttp3 .Headers ;
3031import okhttp3 .OkHttpClient ;
3435import org .slf4j .LoggerFactory ;
3536import software .amazon .awssdk .utils .StringUtils ;
3637
38+ import java .util .List ;
3739import java .util .Map ;
3840import java .util .Objects ;
3941import java .util .concurrent .CompletableFuture ;
@@ -54,15 +56,25 @@ public AwsCapaHttp(OkHttpClient httpClient, CapaObjectSerializer objectSerialize
5456 }
5557
5658 @ Override
57- protected <T > CompletableFuture <HttpResponse <T >> invokeSpiApi (String appId ,
58- String method ,
59- Object requestData ,
60- Map <String , String > headers ,
61- TypeRef <T > type ,
62- RpcServiceOptions rpcServiceOptions ) {
59+ protected <T > CompletableFuture <HttpResponse <T >> invokeSpiApi (
60+ String appId ,
61+ String method ,
62+ Object requestData ,
63+ String httpMethod ,
64+ Map <String , String > headers ,
65+ Map <String , List <String >> urlParameters ,
66+ TypeRef <T > type ,
67+ RpcServiceOptions rpcServiceOptions ) {
6368 Objects .requireNonNull (rpcServiceOptions , "rpcServiceOptions" );
6469 AwsToAwsHttpServiceMeshInvoker awsToAwsHttpServiceMeshInvoker = new AwsToAwsHttpServiceMeshInvoker ();
65- return awsToAwsHttpServiceMeshInvoker .doInvokeSpiApi (appId , method , requestData , headers , type , (AwsRpcServiceOptions ) rpcServiceOptions );
70+ return awsToAwsHttpServiceMeshInvoker .doInvokeSpiApi (
71+ appId ,
72+ method ,
73+ requestData ,
74+ httpMethod ,
75+ headers , urlParameters ,
76+ type ,
77+ (AwsRpcServiceOptions ) rpcServiceOptions );
6678 }
6779
6880 private interface AwsHttpInvoker {
@@ -79,12 +91,15 @@ private interface AwsHttpInvoker {
7991 * @param rpcServiceOptions the rpc service options
8092 * @return the async completable future
8193 */
82- <T > CompletableFuture <HttpResponse <T >> doInvokeSpiApi (String appId ,
83- String method ,
84- Object requestData ,
85- Map <String , String > headers ,
86- TypeRef <T > type ,
87- AwsRpcServiceOptions rpcServiceOptions );
94+ <T > CompletableFuture <HttpResponse <T >> doInvokeSpiApi (
95+ String appId ,
96+ String method ,
97+ Object requestData ,
98+ String httpMethod ,
99+ Map <String , String > headers ,
100+ Map <String , List <String >> urlParameters ,
101+ TypeRef <T > type ,
102+ AwsRpcServiceOptions rpcServiceOptions );
88103 }
89104
90105 /**
@@ -98,12 +113,15 @@ private class AwsToAwsHttpServiceMeshInvoker implements AwsHttpInvoker {
98113 private static final String POST = "POST" ;
99114
100115 @ Override
101- public <T > CompletableFuture <HttpResponse <T >> doInvokeSpiApi (String appId ,
102- String method ,
103- Object requestData ,
104- Map <String , String > headers ,
105- TypeRef <T > type ,
106- AwsRpcServiceOptions rpcServiceOptions ) {
116+ public <T > CompletableFuture <HttpResponse <T >> doInvokeSpiApi (
117+ String appId ,
118+ String method ,
119+ Object requestData ,
120+ String httpMethod ,
121+ Map <String , String > headers ,
122+ Map <String , List <String >> urlParameters ,
123+ TypeRef <T > type ,
124+ AwsRpcServiceOptions rpcServiceOptions ) {
107125 AwsRpcServiceOptions .AwsToAwsServiceOptions awsToAwsServiceOptions = rpcServiceOptions .getAwsToAwsServiceOptions ();
108126 final String serviceId = awsToAwsServiceOptions .getServiceId ();
109127 if (StringUtils .isBlank (serviceId )) {
@@ -114,25 +132,50 @@ public <T> CompletableFuture<HttpResponse<T>> doInvokeSpiApi(String appId,
114132 final int servicePort = awsToAwsServiceOptions .getServicePort ();
115133 final String namespace = awsToAwsServiceOptions .getNamespace ();
116134
117- return doAsyncInvoke (method , requestData , headers , type , serviceId , namespace , servicePort );
135+ if (httpMethod == null ) {
136+ httpMethod = POST ;
137+ }
138+
139+ return doAsyncInvoke (
140+ method ,
141+ requestData ,
142+ httpMethod ,
143+ headers ,
144+ urlParameters ,
145+ type ,
146+ serviceId ,
147+ namespace ,
148+ servicePort );
118149 }
119150
120- private <T > CompletableFuture <HttpResponse <T >> doAsyncInvoke (String method ,
121- Object requestData ,
122- Map <String , String > headers ,
123- TypeRef <T > type ,
124- String serviceId ,
125- String namespace ,
126- int servicePort ) {
151+ private <T > CompletableFuture <HttpResponse <T >> doAsyncInvoke (
152+ String method ,
153+ Object requestData ,
154+ String httpMethod ,
155+ Map <String , String > headers ,
156+ Map <String , List <String >> urlParameters ,
157+ TypeRef <T > type ,
158+ String serviceId ,
159+ String namespace ,
160+ int servicePort ) {
127161 // generate app mesh http url
128162 final String appMeshHttpUrl = AwsCapaRpcProperties .AppMeshProperties .Settings .getRpcAwsAppMeshTemplate ()
129163 .replace ("{serviceId}" , serviceId )
130164 .replace ("{namespace}" , namespace )
131165 .replace ("{servicePort}" , String .valueOf (servicePort ))
132166 .replace ("{operation}" , method );
133167
168+ if (HttpExtension .GET .getMethod ().toString ().equals (httpMethod )) {
169+ // TODO: 2021/11/30 append urlParameters to url
170+ }
171+
134172 // async invoke
135- CompletableFuture <HttpResponse <T >> asyncInvoke0 = post (appMeshHttpUrl , requestData , headers , type );
173+ CompletableFuture <HttpResponse <T >> asyncInvoke0 = invokeHttp (
174+ appMeshHttpUrl ,
175+ requestData ,
176+ httpMethod ,
177+ headers ,
178+ type );
136179 asyncInvoke0 .exceptionally (throwable -> {
137180 if (logger .isWarnEnabled ()) {
138181 logger .warn ("[AwsCapaHttp] async invoke error" , throwable );
@@ -142,10 +185,12 @@ private <T> CompletableFuture<HttpResponse<T>> doAsyncInvoke(String method,
142185 return asyncInvoke0 ;
143186 }
144187
145- private <T > CompletableFuture <HttpResponse <T >> post (String url ,
146- Object requestData ,
147- Map <String , String > headers ,
148- TypeRef <T > type ) {
188+ private <T > CompletableFuture <HttpResponse <T >> invokeHttp (
189+ String url ,
190+ Object requestData ,
191+ String httpMethod ,
192+ Map <String , String > headers ,
193+ TypeRef <T > type ) {
149194 // generate http request body
150195 RequestBody body = getRequestBodyWithSerialize (requestData , headers );
151196 Headers header = getRequestHeaderWithParams (headers );
@@ -154,7 +199,7 @@ private <T> CompletableFuture<HttpResponse<T>> post(String url,
154199 Request request = new Request .Builder ()
155200 .url (url )
156201 .headers (header )
157- .method (POST , body )
202+ .method (httpMethod , body )
158203 .build ();
159204
160205 return doAsyncInvoke0 (request , type );
0 commit comments