Commit 2c1550de 2c1550de2d745fd9394d6b2fae395477c1045b44 by 文鑫

反射优化

1 parent 4a8a31f9
......@@ -18,6 +18,7 @@ import java.lang.reflect.Parameter;
*/
public class EncodeLifeCycle implements MethodAnnotationLifeCycle<Encode, Object> {
private Integer bodyIndex;
/**
* 当方法调用时调用此方法,此时还没有执行请求发送
......@@ -27,11 +28,7 @@ public class EncodeLifeCycle implements MethodAnnotationLifeCycle<Encode, Object
@Override
public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
String value = (String) getAttribute(request, "value");
Parameter[] parameters = method.getMethod().getParameters();
for (int i = 0; i < parameters.length; i++) {
EncodeBody annotation = parameters[i].getAnnotation(EncodeBody.class);
if (annotation != null) {
Object body = args[i];
Object body = args[bodyIndex];
String jsonString = JSON.toJSONString(body);
String encode = DecryptUtils.encode(value, jsonString);
EncryptEntity encodeBody = new EncryptEntity(encode);
......@@ -40,12 +37,17 @@ public class EncodeLifeCycle implements MethodAnnotationLifeCycle<Encode, Object
forestBody.clear();
request.addBody(encodeBody);
}
}
}
@Override
public void onMethodInitialized(ForestMethod method, Encode annotation) {
Parameter[] parameters = method.getMethod().getParameters();
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
EncodeBody body = parameter.getAnnotation(EncodeBody.class);
if (body != null) {
bodyIndex = i;
}
}
}
}
......