parent
36cb6f874e
commit
266ee13bd2
@ -1,5 +1,4 @@
|
||||
# Change Log
|
||||
---
|
||||
|
||||
- [fix:fix routes of gateway doesn't refresh bug.](https://github.com/Tencent/spring-cloud-tencent/pull/158)
|
||||
- [fix:Turn off automatic injection of Polars rule.](https://github.com/Tencent/spring-cloud-tencent/pull/162)
|
||||
- [fix:fix wrong context data storage.](https://github.com/Tencent/spring-cloud-tencent/pull/170)
|
||||
|
@ -0,0 +1,5 @@
|
||||
# Change Log
|
||||
---
|
||||
|
||||
- [fix:fix routes of gateway doesn't refresh bug.](https://github.com/Tencent/spring-cloud-tencent/pull/158)
|
||||
- [fix:Turn off automatic injection of Polars rule.](https://github.com/Tencent/spring-cloud-tencent/pull/162)
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
package com.tencent.cloud.common.metadata.filter.gateway;
|
||||
|
||||
import com.netflix.zuul.ZuulFilter;
|
||||
import com.netflix.zuul.context.RequestContext;
|
||||
import com.tencent.cloud.common.constant.MetadataConstant;
|
||||
import com.tencent.cloud.common.metadata.MetadataContext;
|
||||
import com.tencent.cloud.common.metadata.MetadataContextHolder;
|
||||
|
||||
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER;
|
||||
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;
|
||||
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.REQUEST_URI_KEY;
|
||||
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.SERVICE_ID_KEY;
|
||||
|
||||
/**
|
||||
* Zuul output first filter used for setting peer info in context.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public class MetadataFirstZuulFilter extends ZuulFilter {
|
||||
|
||||
@Override
|
||||
public String filterType() {
|
||||
return PRE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int filterOrder() {
|
||||
return PRE_DECORATION_FILTER_ORDER + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldFilter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object run() {
|
||||
// get request context
|
||||
RequestContext requestContext = RequestContext.getCurrentContext();
|
||||
|
||||
// TODO The peer namespace is temporarily the same as the local namespace
|
||||
MetadataContextHolder.get().putSystemMetadata(
|
||||
MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
|
||||
MetadataContext.LOCAL_NAMESPACE);
|
||||
MetadataContextHolder.get().putSystemMetadata(
|
||||
MetadataConstant.SystemMetadataKey.PEER_SERVICE,
|
||||
(String) requestContext.get(SERVICE_ID_KEY));
|
||||
MetadataContextHolder.get().putSystemMetadata(
|
||||
MetadataConstant.SystemMetadataKey.PEER_PATH,
|
||||
(String) requestContext.get(REQUEST_URI_KEY));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
|
||||
*
|
||||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.tencent.cloud.common.metadata.interceptor.feign;
|
||||
|
||||
import com.tencent.cloud.common.constant.MetadataConstant;
|
||||
import com.tencent.cloud.common.metadata.MetadataContext;
|
||||
import com.tencent.cloud.common.metadata.MetadataContextHolder;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
/**
|
||||
* Interceptor used for setting peer info in context.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
public class MetadataFirstFeignInterceptor implements RequestInterceptor, Ordered {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return MetadataConstant.OrderConstant.METADATA_FIRST_FEIGN_INTERCEPTOR_ORDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
// get metadata of current thread
|
||||
MetadataContext metadataContext = MetadataContextHolder.get();
|
||||
|
||||
// TODO The peer namespace is temporarily the same as the local namespace
|
||||
metadataContext.putSystemMetadata(
|
||||
MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
|
||||
MetadataContext.LOCAL_NAMESPACE);
|
||||
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
|
||||
requestTemplate.feignTarget().name());
|
||||
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH,
|
||||
requestTemplate.path());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue