org.springframework.cloud FeignInterceptor
package org.rx.feign; import org.apache.commons.lang3.ArrayUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;
import org.rx.bean.Tuple;
import org.rx.util.LogInterceptor;
import org.rx.util.StringBuilder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors; public class FeignInterceptor extends LogInterceptor {
@Override
protected Object onProcess(ProceedingJoinPoint joinPoint, StringBuilder msg) throws Throwable {
Signature signature = joinPoint.getSignature();
if (!(signature instanceof MethodSignature)) {
return joinPoint.proceed();
}
Method method = ((MethodSignature) signature).getMethod();
RequestMapping apiMapping = method.getAnnotation(RequestMapping.class);
if (apiMapping == null) {
return joinPoint.proceed();
} String url = "";
FeignClient feignClient = null;
for (Class<?> pi : joinPoint.getTarget().getClass().getInterfaces()) {
if ((feignClient = pi.getAnnotation(FeignClient.class)) != null) {
break;
}
}
if (feignClient != null) {
url += feignClient.url();
}
RequestMapping baseMapping = method.getDeclaringClass().getAnnotation(RequestMapping.class);
Function<RequestMapping, String> pf = p -> String.join(",",
!ArrayUtils.isEmpty(p.value()) ? p.value() : p.path());
if (baseMapping != null) {
url += pf.apply(baseMapping);
}
url += pf.apply(apiMapping); String httpMethod = ArrayUtils.isEmpty(apiMapping.method()) ? "POST"
: String.join(",", Arrays.stream(apiMapping.method()).map(p -> p.name()).collect(Collectors.toList()));
msg.appendLine().appendLine("%s\t\t%s", httpMethod, resolveUrl(url, signature));
return super.onProcess(joinPoint, msg);
} protected String resolveUrl(String url, Signature signature) {
return url;
} @Override
protected Tuple<String, String> getProcessFormat() {
return Tuple.of("Request:\t%s", "Response:\t%s");
}
}
org.springframework.cloud FeignInterceptor的更多相关文章
- 关于SpringCloud配置网关转发时出现一下啊错误:“com.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException”
com.netflix.zuul.exception.ZuulException: Forwarding error at org.springframework.cloud.netflix.zuul ...
- SpringCloud使用Feign出现java.lang.ClassNotFoundException: org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory异常
废话不多说!!! 在SpringCloud项目中配置了Feign来调用restful接口,项目启动的时候报错,报错信息如下: 找不到org.springframework.cloud.client.l ...
- 解决spring-test中Feign问题: No qualifying bean of type 'org.springframework.cloud.openfeign.FeignContext' available
问题现象: 启动测试类(含通过Feign远程调用的组件),报错: No qualifying bean of type 'org.springframework.cloud.openfeign.Fei ...
- Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-config:jar:unk
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframew ...
- 启动zuul时候报错:The bean 'proxyRequestHelper', defined in class path resource [org/springframework/cloud/netflix/zuul
启动zuul时候报错:The bean 'proxyRequestHelper', defined in class path resource [org/springframework/cloud/ ...
- gateway启动报错:org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found
将pom.xml中关于spring-boot-start-web模块的jar依赖去掉. 错误分析: 根据上面描述(Description)中信息了解到GatewayAutoConfiguration这 ...
- 【spring cloud】spring cloud分布式服务eureka启动时报错:java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
spring cloud分布式服务eureka启动时报错:java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApp ...
- Spring Cloud ZooKeeper集成Feign的坑1,错误:Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.
错误如下: ERROR 31473 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** A ...
- spring cloud gateway网关启动报错:No qualifying bean of type 'org.springframework.web.reactive.DispatcherHandler'
网关配置好后启动报错如下: org.springframework.context.ApplicationContextException: Unable to start web server; n ...
随机推荐
- golang协程踩坑记录
1.主线程等待多个协程执行完毕后,再执行下面的程序.golang提供了一个很好用的工具. sync.WaitGroup下面是个简单的例子. 执行结果: 2.主线程主动去结束已经启动了的多个协程.执行结 ...
- JAVA中的String类(详解)
Java.lang.String类是final类型的,因此不可以继承这个类.不能修改这个类.String是一个类不属于基本数据类型. 可以从源码中看到,String是一个final类型. String ...
- Vuex- Action的 { commit } {commit}是什么写法
Vuex- Action的 { commit } Vuex 中 使用 Action 处理异步请求时,常规写法如下: getMenuAction:(context) =>{ context.com ...
- Linux中的wheel用户组是什么?
在Linux中wheel组就类似于一个管理员的组. 通常在Linux下,即使我们有系统管理员root的权限,也不推荐用root用户登录.一般情况下用普通用户登录就可以了,在需要root权限执行一些操作 ...
- 【安卓基础】ImageView与EditText联动实现隐藏与显示密码
项目中经常会有这样的需求,在密码输入框的右边有一个小图标,点击就切换显示和隐藏密码. 其实这里需求实现起来是比较容易的,主要考虑是复用问题,因为登陆.注册.修改密码界面都会有这样的情景,如果每个界面都 ...
- efk学习整理
概念 Logstash 数据收集处理引擎.支持动态的从各种数据源搜集数据,并对数据进行过滤.分析.丰富.统一格式等操作,然后存储以供后续使用. kibana 可视化化平台.它能够搜索.展示存储在 El ...
- 《R语言入门与实践》第四章:R 的记号体系
这一章节将如何对 R 对象中的值进行选取,R 的符号规则有两种方式进行查询: 第一种记号体系:索引查询索引语法:deck[ , ](使用中括号)其中[ , ] 为索引,其中含有两个索引参数,用 &qu ...
- 在ibatis中时间段查询完整代码
ibatis.xml文件中的代码如下: <typeAlias alias="ServInvokeTest" type="com.entity.ServInvokeT ...
- DBlink 创建 删除 脚本
--配置SQLSERVER数据库的DBLINK --删除dblink Exec sp_droplinkedsrvlogin test,Null Exec sp_dropserver test --创建 ...
- Shell脚本【扔一百次硬币】
#!/bin/bash#扔一百次硬币,然后分别显示出正面和反面的次数! for i in $(seq 100) do if [ `echo $((RANDOM%2))` == 0 ] then let ...