@ Resource
Private AppKeyProvider AppKeyProvider;
Public MonoThe filter (ServerWebExchange exchange, GatewayFilterChain chain) {
Try {
String app_key=exchange. GetRequest (). GetQueryParams (). The getFirst (" app_key "));
//app_key verify
Flux. Just (app_key). FlatMap (key - & gt; AppKeyProvider. GetAppKey (key)). The subscribe (
AppKey - & gt; {
If (appKey==null) {
//app_key is not valid
Throw new AppException (ErrorCode. ILLEGAL_APP_KEY);
} else {
//do... Jump to the next filter
}
},
The ex - & gt; {
Throw new AppException (ErrorCode SERVICE_BASIC_ERROR, ex);
}
);
{} the catch (AppException ex)
Exchange. The method getResponse (). SetStatusCode (HttpStatus BAD_REQUEST);
Exchange. The method getResponse (). GetHeaders () setContentType (MediaType. APPLICATION_JSON);
The String result=RestHelper. Build (ex, exchange). The toString ();
Return exchange. The method getResponse (). WriteWith (Mono) just (exchange. The method getResponse () bufferFactory (). Wrap (result. GetBytes (Charsets. UTF_8))));
}
return chain.filter(exchange);
}
CodePudding user response:
There is no reply, top a himself