赞
踩
使用技术:
网关:SpringCloudGateway
RPC调用:Feign
-
- import com.kw.framework.common.croe.constant.CommonConstant;
- import com.kw.framework.gateway.utils.BuildHeaderFilter;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.cloud.gateway.filter.GatewayFilterChain;
- import org.springframework.cloud.gateway.filter.GlobalFilter;
- import org.springframework.core.Ordered;
- import org.springframework.stereotype.Component;
- import org.springframework.web.server.ServerWebExchange;
- import reactor.core.publisher.Mono;
- import java.util.LinkedHashMap;
- import java.util.UUID;
-
- @Component
- @Slf4j
- public class HeaderFilter implements GlobalFilter, Ordered {
- @Override
- public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
-
- // 封装需要向后续封装的header对象
- LinkedHashMap<String, String> headerMap = new LinkedHashMap<>();
- headerMap.put(CommonConstant.TRACE_ID, UUID.randomUUID().toString());
- exchange = BuildHeaderFilter.chainFilterAndSetHeaders(chain, exchange, headerMap);
-
- return chain.filter(exchange);
- }
-
- @Override
- public int getOrder() {
- return 0;
- }
-
-
- }
-
- import feign.RequestInterceptor;
- import feign.RequestTemplate;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import javax.servlet.http.HttpServletRequest;
- import java.util.Enumeration;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.Map;
-
- /**
- * feign请求头传递
- */
- @Slf4j
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。