fix:fix fetching wrong PEER_SERVICE in SCG filter.

pull/83/head
skyehtzhang 3 years ago
parent 8c9da70750
commit f5c1e56cfd

@ -55,25 +55,27 @@ public class MetadataFirstScgFilter implements GlobalFilter, Ordered {
Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR); Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
// get metadata of current thread // get metadata of current thread
MetadataContext metadataContext = exchange MetadataContext metadataContext = exchange.getAttribute(MetadataConstant.HeaderName.METADATA_CONTEXT);
.getAttribute(MetadataConstant.HeaderName.METADATA_CONTEXT);
if (metadataContext == null) { if (metadataContext == null) {
metadataContext = MetadataContextHolder.get(); metadataContext = MetadataContextHolder.get();
} }
// TODO The peer namespace is temporarily the same as the local namespace // TODO The peer namespace is temporarily the same as the local namespace
metadataContext.putSystemMetadata( metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
MetadataContext.LOCAL_NAMESPACE); MetadataContext.LOCAL_NAMESPACE);
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, if (route != null) {
route.getUri().getAuthority()); metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
route.getUri().getAuthority());
}
else {
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
exchange.getRequest().getURI().getAuthority());
}
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH, metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH,
exchange.getRequest().getURI().getPath()); exchange.getRequest().getURI().getPath());
exchange.getAttributes().put(MetadataConstant.HeaderName.METADATA_CONTEXT, exchange.getAttributes().put(MetadataConstant.HeaderName.METADATA_CONTEXT, metadataContext);
metadataContext);
return chain.filter(exchange); return chain.filter(exchange);
} }
} }

Loading…
Cancel
Save