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的更多相关文章

  1. 关于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 ...

  2. SpringCloud使用Feign出现java.lang.ClassNotFoundException: org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory异常

    废话不多说!!! 在SpringCloud项目中配置了Feign来调用restful接口,项目启动的时候报错,报错信息如下: 找不到org.springframework.cloud.client.l ...

  3. 解决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 ...

  4. Failed to read artifact descriptor for org.springframework.cloud:spring-cloud-starter-config:jar:unk

    <dependencyManagement> <dependencies> <dependency> <groupId>org.springframew ...

  5. 启动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/ ...

  6. 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这 ...

  7. 【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 ...

  8. 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 ...

  9. spring cloud gateway网关启动报错:No qualifying bean of type 'org.springframework.web.reactive.DispatcherHandler'

    网关配置好后启动报错如下: org.springframework.context.ApplicationContextException: Unable to start web server; n ...

随机推荐

  1. Unity自定义定时器,模拟协程,脱离MonoBehavior控制

    using System; using System.Collections.Generic; using System.Timers; public class PETimer { private ...

  2. vue-router 中踏过的坑

    1.做完页面滚动,然后再加上路由,发现路由一直跳转不了,经历千辛万苦才发现是BScroll没有配置click:true,当看过文档时心里一万只草泥马奔腾而过,我预感到成长道路上还有多少坑在等着我. 2 ...

  3. day3——两数之和

    // 小白一名,0算法基础,艰难尝试算法题中,若您发现本文中错误, 或有其他见解,往不吝赐教,感激不尽,拜谢. 领扣 第2题 今日算法 题干 //给定一个整数数组和一个目标值,找出数组中和为目标值的两 ...

  4. OSPFv3与OSPF的配置

    IPv6 路由-OSPFv3 实验目的 1.   掌握 OSPFv3 的配置方法 2.   掌握在帧中继环境下 OSPFv3 的配置方法 3.   掌握 OSPFv3 NSSA 的配置方法 4.   ...

  5. 采用梯度下降优化器(Gradient Descent optimizer)结合禁忌搜索(Tabu Search)求解矩阵的全部特征值和特征向量

    [前言] 对于矩阵(Matrix)的特征值(Eigens)求解,采用数值分析(Number Analysis)的方法有一些,我熟知的是针对实对称矩阵(Real Symmetric Matrix)的特征 ...

  6. 当你的layui表格要做全选+删除功能【兼容ie8】

    <!-- 全选 --> <div class="choose"> <input type="checkbox" id=" ...

  7. mysql 循环、游标

    mysql 循环只能在存储过程.代码记录 CREATE DEFINER=`front`@`%` PROCEDURE `a_1`() BEGIN -- 声明变量,接收游标循环变量 DECLARE _co ...

  8. GD库imagettftext中文乱码的问题

    linux下出现乱码,加上编码转换就可以了. $str = mb_convert_encoding($str, "html-entities", "utf-8" ...

  9. Mac下如何配置环境变量JDK

    1.在英文输入法的状态下,按键盘“Ctrl + 空格”组合键,调出Spotlight搜索,在这里可以快速启动终端,输入ter,然后回车,即可打开终端: 2.如果你是第一次配置环境变量,可以使用“tou ...

  10. SqlSugar GridView aspnetpager 分页排序

    HTML页面 <%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefi ...