use of org.springframework.cloud.netflix.feign.FeignClient in project rxlib by RockyLOMO.
the class FeignInterceptor method onProcess.
@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);
}
Aggregations