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 ...
随机推荐
- selenium+java 数据驱动
一.数据驱动测试概念 数据驱动测试是相同的测试脚本使用不同的测试数据执行,测试数据和测试行为完全分离. 二.实施数据驱动测试的步骤: 1.编写测试脚本,脚本需要支持程序对象.文件或者数据库读入测试数据 ...
- visual studio常用技法相关
(1)查看dll里面包含了那些函数(dumpbin是visual studio内置工具)dumpbin -exports user32.lib (2)#include "stdlib.h&q ...
- 新工具DPR的一些想法
可行性分析 假设: 连续性 - 与clustering的假设正好相反 分支事件 特征的选择:距离的度量: 限定KNN的必要性: MST构建: 主支的构建和简化:省略中间点:最短路径: 迭代处理所有分支 ...
- 如何解锁亚马逊A9的新算法?
亚马逊每一次变动总能在跨境圈里掀起一场场风波,最近A9算法的更新更是牵动着不少卖家的心. A9算法是亚马逊运行的内核算法,只要消费者在亚马逊上面搜索了商品,那么他就已经开始使用了A9算法,通过分析每一 ...
- AndroidStudio中导入jar包的方法
1.首先去下载需要的jar包 2.将jar包复制到project下的app->libs目录下(如果不存在libs目录新建一个) 3.右击该jar包,选择add as library,弹出窗口,点 ...
- Vue-devtools 安装浏览器调试
工欲善其事,必先利其器. 本文主要讲解Vue-devtools的安装和使用 安装方法有两个: 方法一:(前提条件需要FQ,省事省力省心方便快速) FQ =>谷歌商店 =>搜索 =>V ...
- WPF程序打包发布
1.新建安装项目: 新建项目——其他项目类型——安装与部署——InstallShield Limited Edition Project 2.配置安装信息: 选择Project Assistant进入 ...
- 在Postman中使用不受信任的SSL证书
阅读目录 第一种方案——临时添加到受信任的证书颁发机构: 第二种方案——永久添加到受信任的证书颁发机构: add by zhj: 在http://www.cnblogs.com/ajianbeyour ...
- PDF 补丁丁 0.6.0.3383 版发布(修复书签编辑器坐标定位错误的问题)
新的测试版本修复了书签编辑器坐标定位错误的问题. 另外,增加了鼠标双击关闭功能标签的功能.
- Daily record-November
November 11. I managed to grab her hand. 我抓到了她的手.2. He passed a hand wearily over his eyes. 他疲倦地用手抹了 ...