Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
feo-jobs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
feo-jobs
Commits
3b0385ff
Commit
3b0385ff
authored
Aug 10, 2021
by
王亚雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加 MyFeignInterceptor 及apollo配置
parent
12bf5adf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
pom.xml
pom.xml
+26
-0
MyFeignInterceptor.java
...n/java/com/tanpu/feo/feojob/feign/MyFeignInterceptor.java
+55
-0
No files found.
pom.xml
View file @
3b0385ff
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
<groupId>
com.baomidou
</groupId>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-generator
</artifactId>
<artifactId>
mybatis-plus-generator
</artifactId>
<version>
3.4.1
</version>
<version>
3.4.1
</version>
<exclusions>
<exclusion>
<artifactId>
mybatis-plus-extension
</artifactId>
<groupId>
com.baomidou
</groupId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<dependency>
...
@@ -63,6 +69,12 @@
...
@@ -63,6 +69,12 @@
<dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-ribbon
</artifactId>
<artifactId>
spring-cloud-starter-netflix-ribbon
</artifactId>
<exclusions>
<exclusion>
<artifactId>
jsr305
</artifactId>
<groupId>
com.google.code.findbugs
</groupId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<!--feign-->
<!--feign-->
...
@@ -74,6 +86,10 @@
...
@@ -74,6 +86,10 @@
<artifactId>
guava
</artifactId>
<artifactId>
guava
</artifactId>
<groupId>
com.google.guava
</groupId>
<groupId>
com.google.guava
</groupId>
</exclusion>
</exclusion>
<exclusion>
<artifactId>
commons-io
</artifactId>
<groupId>
commons-io
</groupId>
</exclusion>
</exclusions>
</exclusions>
</dependency>
</dependency>
<!--hystrix-->
<!--hystrix-->
...
@@ -85,6 +101,10 @@
...
@@ -85,6 +101,10 @@
<artifactId>
guava
</artifactId>
<artifactId>
guava
</artifactId>
<groupId>
com.google.guava
</groupId>
<groupId>
com.google.guava
</groupId>
</exclusion>
</exclusion>
<exclusion>
<artifactId>
HdrHistogram
</artifactId>
<groupId>
org.hdrhistogram
</groupId>
</exclusion>
</exclusions>
</exclusions>
</dependency>
</dependency>
...
@@ -103,6 +123,12 @@
...
@@ -103,6 +123,12 @@
<dependency>
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper
</artifactId>
<artifactId>
pagehelper
</artifactId>
<exclusions>
<exclusion>
<artifactId>
jsqlparser
</artifactId>
<groupId>
com.github.jsqlparser
</groupId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<dependency>
...
...
src/main/java/com/tanpu/feo/feojob/feign/MyFeignInterceptor.java
0 → 100644
View file @
3b0385ff
package
com
.
tanpu
.
feo
.
feojob
.
feign
;
import
feign.RequestInterceptor
;
import
feign.RequestTemplate
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Collection
;
import
java.util.Enumeration
;
import
java.util.Map
;
/**
* @description: 透传spring 头信息
* @author: wanglei
* @created: 2020/05/08 11:55
*/
@Slf4j
@Component
public
class
MyFeignInterceptor
implements
RequestInterceptor
{
@Override
public
void
apply
(
RequestTemplate
template
)
{
HttpServletRequest
request
=
getHttpServletRequest
();
if
(
request
!=
null
)
{
Map
<
String
,
Collection
<
String
>>
feignHeaders
=
template
.
headers
();
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
while
(
headerNames
.
hasMoreElements
())
{
String
name
=
headerNames
.
nextElement
();
// 不覆盖feign的头信息
if
(!
feignHeaders
.
containsKey
(
name
))
{
template
.
header
(
name
,
request
.
getHeader
(
name
));
}
}
log
.
debug
(
"添加后的头信息:{}"
,
template
.
headers
());
}
else
{
log
.
debug
(
"没有添加feign头信息"
);
}
}
/**
* 如果不是从controller过来的请求(例如定时器等),是没有request对象的
*/
private
HttpServletRequest
getHttpServletRequest
()
{
try
{
return
((
ServletRequestAttributes
)
RequestContextHolder
.
currentRequestAttributes
()).
getRequest
();
}
catch
(
Exception
e
)
{
}
return
null
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment