Search in sources :

Example 1 with FeignClient

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);
}
Also used : Arrays(java.util.Arrays) Signature(org.aspectj.lang.Signature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Tuple(org.rx.bean.Tuple) StringBuilder(org.rx.util.StringBuilder) FeignClient(org.springframework.cloud.netflix.feign.FeignClient) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) LogInterceptor(org.rx.util.LogInterceptor) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) FeignClient(org.springframework.cloud.netflix.feign.FeignClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Signature (org.aspectj.lang.Signature)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 Tuple (org.rx.bean.Tuple)1 LogInterceptor (org.rx.util.LogInterceptor)1 StringBuilder (org.rx.util.StringBuilder)1 FeignClient (org.springframework.cloud.netflix.feign.FeignClient)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1