1818
1919import group .rxcloud .capa .component .http .CapaHttp ;
2020import group .rxcloud .capa .component .http .HttpResponse ;
21+ import group .rxcloud .capa .infrastructure .exceptions .CapaErrorContext ;
22+ import group .rxcloud .capa .infrastructure .exceptions .CapaException ;
2123import group .rxcloud .capa .infrastructure .serializer .CapaObjectSerializer ;
2224import group .rxcloud .capa .spi .http .config .CapaSpiOptionsLoader ;
2325import group .rxcloud .capa .spi .http .config .CapaSpiProperties ;
@@ -63,16 +65,16 @@ protected <T> CompletableFuture<HttpResponse<T>> doInvokeApi(String httpMethod,
6365 TypeRef <T > type ) {
6466 if (logger .isDebugEnabled ()) {
6567 if (httpMethod != null ) {
66- logger .debug ("[CapaHttpSpi] invoke rpc httpMethod[{}]" , httpMethod );
68+ logger .debug ("[Capa.Rpc.Client.http] [ CapaHttpSpi] invoke rpc httpMethod[{}]" , httpMethod );
6769 }
6870 if (urlParameters != null && !urlParameters .isEmpty ()) {
69- logger .debug ("[CapaHttpSpi] invoke rpc urlParameters[{}]" , urlParameters );
71+ logger .debug ("[Capa.Rpc.Client.http] [ CapaHttpSpi] invoke rpc urlParameters[{}]" , urlParameters );
7072 }
7173 if (headers != null && !headers .isEmpty ()) {
72- logger .debug ("[CapaHttpSpi] invoke rpc headers[{}}]" , headers );
74+ logger .debug ("[Capa.Rpc.Client.http] [ CapaHttpSpi] invoke rpc headers[{}}]" , headers );
7375 }
7476 if (context != null ) {
75- logger .debug ("[CapaHttpSpi] invoke rpc context[{}]" , context );
77+ logger .debug ("[Capa.Rpc.Client.http] [ CapaHttpSpi] invoke rpc context[{}]" , context );
7678 }
7779 }
7880
@@ -84,45 +86,32 @@ protected <T> CompletableFuture<HttpResponse<T>> doInvokeApi(String httpMethod,
8486 final String _method = pathSegments [3 ];
8587 final String method = pathSegments [4 ];
8688 if (logger .isDebugEnabled ()) {
87- logger .debug ("[CapaHttpSpi] invoke rpc url_path[/version={}/{}/appId={}/{}/methodName={}]" ,
89+ logger .debug ("[Capa.Rpc.Client.http] [ CapaHttpSpi] invoke rpc url_path[/version={}/{}/appId={}/{}/methodName={}]" ,
8890 version , _invoke , appId , _method , method );
8991 }
9092
9193 // load spi service options
9294 RpcServiceOptions rpcServiceOptions = getRpcServiceOptions (appId );
9395 Objects .requireNonNull (rpcServiceOptions , "rpcServiceOptions" );
9496 if (logger .isDebugEnabled ()) {
95- logger .debug ("[CapaHttpSpi] invoke rpc options[{}]" ,
97+ logger .debug ("[Capa.Rpc.Client.http] [ CapaHttpSpi] invoke rpc options[{}]" ,
9698 rpcServiceOptions );
9799 }
98100
99- // spi invoke
100- CompletableFuture <HttpResponse <T >> invokeSpiApi =
101- invokeSpiApi (appId , method , requestData , httpMethod , headers , urlParameters , type , rpcServiceOptions );
102- invokeSpiApi .whenComplete ((tHttpResponse , throwable ) -> {
103- if (throwable != null ) {
104- if (logger .isWarnEnabled ()) {
105- logger .warn ("[CapaHttpSpi] invoke rpc response error" ,
106- throwable );
107- }
108- return ;
109- }
110- if (tHttpResponse == null ) {
111- if (logger .isWarnEnabled ()) {
112- logger .warn ("[CapaHttpSpi] invoke rpc response empty[{}]" ,
113- tHttpResponse );
114- }
115- return ;
101+ try {
102+ // spi invoke
103+ CompletableFuture <HttpResponse <T >> invokeSpiApi = invokeSpiApi (
104+ appId , method , requestData , httpMethod , headers , urlParameters , type , rpcServiceOptions );
105+ invokeSpiApi .whenComplete (this ::callbackLog );
106+ return invokeSpiApi ;
107+ } catch (CapaException e ) {
108+ throw e ;
109+ } catch (Exception e ) {
110+ if (logger .isErrorEnabled ()) {
111+ logger .error ("[Capa.Rpc.Client.http] [CapaHttpSpi] invoke error, un-catch throwable is: " , e );
116112 }
117- final int responseStatusCode = tHttpResponse .getStatusCode ();
118- final Map <String , String > responseHeaders = tHttpResponse .getHeaders ();
119- final T responseBody = tHttpResponse .getBody ();
120- if (logger .isDebugEnabled ()) {
121- logger .debug ("[CapaHttpSpi] invoke rpc response code[{}] headers[{}] body[{}]" ,
122- responseStatusCode , responseHeaders , responseBody );
123- }
124- });
125- return invokeSpiApi ;
113+ throw new CapaException (CapaErrorContext .SYSTEM_ERROR , e );
114+ }
126115 }
127116
128117 /**
@@ -136,6 +125,35 @@ protected RpcServiceOptions getRpcServiceOptions(String appId) {
136125 return capaSpiOptionsLoader .loadRpcServiceOptions (appId );
137126 }
138127
128+ private <T > void callbackLog (HttpResponse <T > tHttpResponse , Throwable throwable ) {
129+ if (throwable != null ) {
130+ if (throwable instanceof CapaException ) {
131+ return ;
132+ }
133+ // un-catch throwable
134+ else {
135+ if (logger .isErrorEnabled ()) {
136+ logger .error ("[Capa.Rpc.Client.http.callback] [CapaHttpSpi] invoke rpc response error" ,
137+ throwable );
138+ }
139+ return ;
140+ }
141+ }
142+ if (tHttpResponse == null ) {
143+ if (logger .isWarnEnabled ()) {
144+ logger .warn ("[Capa.Rpc.Client.http.callback] [CapaHttpSpi] invoke rpc response empty." );
145+ }
146+ return ;
147+ }
148+ final int responseStatusCode = tHttpResponse .getStatusCode ();
149+ final Map <String , String > responseHeaders = tHttpResponse .getHeaders ();
150+ final T responseBody = tHttpResponse .getBody ();
151+ if (logger .isDebugEnabled ()) {
152+ logger .debug ("[Capa.Rpc.Client.http.callback] [CapaHttpSpi] invoke rpc response code[{}] headers[{}] body[{}]" ,
153+ responseStatusCode , responseHeaders , responseBody );
154+ }
155+ }
156+
139157 /**
140158 * Invoke spi api and then return async completable future.
141159 *
0 commit comments