From 3792f46388b20f30abb843d696761eae99421535 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Mon, 25 Jan 2021 12:01:40 +0800 Subject: [PATCH] =?UTF-8?q?FeignConfig=20=E9=87=8D=E5=A4=8D=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud/config/FeignClientConfig.java | 152 +++++++++--------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/FeignClientConfig.java b/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/FeignClientConfig.java index 727cd667..612da73a 100644 --- a/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/FeignClientConfig.java +++ b/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/FeignClientConfig.java @@ -1,76 +1,76 @@ -package org.jeecg.starter.cloud.config; - -import feign.Feign; -import feign.Logger; -import feign.RequestInterceptor; -import feign.codec.Encoder; -import feign.form.spring.SpringFormEncoder; -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.constant.CommonConstant; -import org.springframework.beans.factory.ObjectFactory; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.http.HttpMessageConverters; -import org.springframework.cloud.openfeign.FeignAutoConfiguration; -import org.springframework.cloud.openfeign.support.SpringEncoder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Scope; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; - - -@ConditionalOnClass(Feign.class) -@AutoConfigureBefore(FeignAutoConfiguration.class) -@Slf4j -@Configuration -public class FeignClientConfig { - - @Bean - public RequestInterceptor requestInterceptor() { - return requestTemplate -> { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (null != attributes) { - HttpServletRequest request = attributes.getRequest(); - log.info("Feign request: {}", request.getRequestURI()); - // 将token信息放入header中 - String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); - if(token==null){ - token = request.getParameter("token"); - } - log.info("Feign request token: {}", token); - requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); - } - }; - } - - - - /** - * Feign 客户端的日志记录,默认级别为NONE - * Logger.Level 的具体级别如下: - * NONE:不记录任何信息 - * BASIC:仅记录请求方法、URL以及响应状态码和执行时间 - * HEADERS:除了记录 BASIC级别的信息外,还会记录请求和响应的头信息 - * FULL:记录所有请求与响应的明细,包括头信息、请求体、元数据 - */ - @Bean - Logger.Level feignLoggerLevel() { - return Logger.Level.FULL; - } - - /** - * Feign支持文件上传 - * @param messageConverters - * @return - */ - @Bean - @Primary - @Scope("prototype") - public Encoder multipartFormEncoder(ObjectFactory messageConverters) { - return new SpringFormEncoder(new SpringEncoder(messageConverters)); - } -} +//package org.jeecg.starter.cloud.config; +// +//import feign.Feign; +//import feign.Logger; +//import feign.RequestInterceptor; +//import feign.codec.Encoder; +//import feign.form.spring.SpringFormEncoder; +//import lombok.extern.slf4j.Slf4j; +//import org.jeecg.common.constant.CommonConstant; +//import org.springframework.beans.factory.ObjectFactory; +//import org.springframework.boot.autoconfigure.AutoConfigureBefore; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +//import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +//import org.springframework.cloud.openfeign.FeignAutoConfiguration; +//import org.springframework.cloud.openfeign.support.SpringEncoder; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.context.annotation.Primary; +//import org.springframework.context.annotation.Scope; +//import org.springframework.web.context.request.RequestContextHolder; +//import org.springframework.web.context.request.ServletRequestAttributes; +// +//import javax.servlet.http.HttpServletRequest; +// +// +//@ConditionalOnClass(Feign.class) +//@AutoConfigureBefore(FeignAutoConfiguration.class) +//@Slf4j +//@Configuration +//public class FeignClientConfig { +// +// @Bean +// public RequestInterceptor requestInterceptor() { +// return requestTemplate -> { +// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); +// if (null != attributes) { +// HttpServletRequest request = attributes.getRequest(); +// log.info("Feign request: {}", request.getRequestURI()); +// // 将token信息放入header中 +// String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); +// if(token==null){ +// token = request.getParameter("token"); +// } +// log.info("Feign request token: {}", token); +// requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); +// } +// }; +// } +// +// +// +// /** +// * Feign 客户端的日志记录,默认级别为NONE +// * Logger.Level 的具体级别如下: +// * NONE:不记录任何信息 +// * BASIC:仅记录请求方法、URL以及响应状态码和执行时间 +// * HEADERS:除了记录 BASIC级别的信息外,还会记录请求和响应的头信息 +// * FULL:记录所有请求与响应的明细,包括头信息、请求体、元数据 +// */ +// @Bean +// Logger.Level feignLoggerLevel() { +// return Logger.Level.FULL; +// } +// +// /** +// * Feign支持文件上传 +// * @param messageConverters +// * @return +// */ +// @Bean +// @Primary +// @Scope("prototype") +// public Encoder multipartFormEncoder(ObjectFactory messageConverters) { +// return new SpringFormEncoder(new SpringEncoder(messageConverters)); +// } +//} -- GitLab