‘liusuyi’
2023-07-10 55c5941807a52bd1eb4fc08803d2402dd72e60a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.ruoyi.utils.forest;
 
import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.lifecycles.MethodAnnotationLifeCycle;
import com.dtflys.forest.reflection.ForestMethod;
 
public class UavAuthLifeCircle implements MethodAnnotationLifeCycle<UavAuth, Object> {
 
 
    /**
     * 当方法调用时调用此方法,此时还没有执行请求发送
     * 次方法可以获得请求对应的方法调用信息,以及动态传入的方法调用参数列表
     */
    @Override
    public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
 
        System.out.println("!!!!!onInvokeMethod!!!!!! '" + method.getMethodName() + "' Arguments>>>>>>>>>: ");
    /*    for (Object arg :
                args) {
            System.out.println(arg);
        }
        String token = (String) args[1];
        if (token != null) {
            request.addHeader("x-auth-token", token);
        }*/
 
        System.out.println("=================");
    }
 
    /**
     * 发送请求前执行此方法
     */
    @Override
    public boolean beforeExecute(ForestRequest request) {
        String token = (String) getAttribute(request, "token");
        System.out.println("!!!!beforeExecute!!!!");
        System.out.println("request.getMethod().getMethodName():" + request.getMethod().getMethodName());
        System.out.println("  token:" + token);
        System.out.println("=================");
        request.addHeader("x-auth-token", token);
        return true;
    }
 
    /**
     * 此方法在请求方法初始化的时候被调用
     */
 
    @Override
    public void onMethodInitialized(ForestMethod forestMethod, UavAuth uavAuth) {
        System.out.println("Method '" + forestMethod.getMethodName());
    }
}