fix throw npe when router context is null (#634)

Co-authored-by: Haotian Zhang <928016560@qq.com>
pull/637/head
lepdou 2 years ago committed by GitHub
parent 62d7f9c448
commit 9a0d199e2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,3 +6,4 @@
- [Optimize: Maybe remove Chinese characters](https://github.com/Tencent/spring-cloud-tencent/pull/608)
- [Bugfix: fix feign report call result error when using feign direct call](https://github.com/Tencent/spring-cloud-tencent/pull/622)
- [Feature: support spring-retry router](https://github.com/Tencent/spring-cloud-tencent/pull/633)
- [Bugfix: fix throw npe when router context is null](https://github.com/Tencent/spring-cloud-tencent/pull/634)

@ -59,11 +59,11 @@ import static com.tencent.cloud.common.constant.ContextConstant.UTF_8;
/**
* Service routing entrance.
*
* <p>
* Rule routing needs to rely on request parameters for server filtering.
* The interface cannot obtain the context object of the request granularity,
* so the routing capability cannot be achieved through ServerListFilter.
*
* <p>
* And {@link PolarisRouterServiceInstanceListSupplier#get(Request)} provides the ability to pass in http headers,
* so routing capabilities are implemented through IRule.
*
@ -95,21 +95,23 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI
Flux<List<ServiceInstance>> allServers = getDelegate().get();
// 2. filter by router
PolarisRouterContext routerContext = null;
DefaultRequestContext requestContext = (DefaultRequestContext) request.getContext();
PolarisRouterContext key;
if (requestContext instanceof RequestDataContext) {
key = buildRouterContext(((RequestDataContext) requestContext).getClientRequest().getHeaders());
routerContext = buildRouterContext(((RequestDataContext) requestContext).getClientRequest().getHeaders());
}
else if (requestContext.getClientRequest() instanceof PolarisLoadBalancerRequest) {
key = buildRouterContext(((PolarisLoadBalancerRequest<?>) requestContext.getClientRequest()).getRequest()
routerContext = buildRouterContext(((PolarisLoadBalancerRequest<?>) requestContext.getClientRequest()).getRequest()
.getHeaders());
}
else {
if (routerContext == null) {
// return all servers if router context is null.
return allServers;
}
return doRouter(allServers, key);
return doRouter(allServers, routerContext);
}
//set method to public for unit test

Loading…
Cancel
Save