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 { /** * 当方法调用时调用此方法,此时还没有执行请求发送 * 次方法可以获得请求对应的方法调用信息,以及动态传入的方法调用参数列表 */ @Override public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) { System.out.println("Invoke Method '" + method.getMethodName() + "' Arguments: " + args); } /** * 发送请求前执行此方法 */ @Override public boolean beforeExecute(ForestRequest request) { String token = (String) getAttribute(request, "token"); System.out.println(" UavAuthLifeCircle token:"+token); if(token!=null){ request.addHeader("x-auth-token", token); } return true; } /** * 此方法在请求方法初始化的时候被调用 */ @Override public void onMethodInitialized(ForestMethod forestMethod, UavAuth uavAuth) { System.out.println("Method '" + forestMethod.getMethodName()); } }