use of com.huawei.gray.dubbo.utils.FieldPrivilegedAction in project Sermant by huaweicloud.
the class RegistrationServiceImpl method getVersion.
/**
* 拦截点前执行
*
* @param obj 增强的类
* @param arguments 增强方法的所有参数
*/
@Override
public void getVersion(Object obj, Object[] arguments) throws NoSuchFieldException, IllegalAccessException {
if (arguments.length <= 2 || !(arguments[2] instanceof List<?>)) {
return;
}
Field field = obj.getClass().getDeclaredField("microservice");
AccessController.doPrivileged(new FieldPrivilegedAction(field));
Microservice microservice = (Microservice) field.get(obj);
GrayConfiguration grayConfiguration = LabelCache.getLabel(DubboCache.getLabelName());
CurrentTag currentTag = grayConfiguration.getCurrentTag();
currentTag.setRegisterVersion(microservice.getVersion());
List<MicroserviceInstance> instances = (List<MicroserviceInstance>) arguments[2];
for (MicroserviceInstance instance : instances) {
for (String endpoint : instance.getEndpoints()) {
AddrCache.setRegisterVersionCache(endpoint.substring(GrayConstant.DUBBO_PREFIX.length()), instance.getVersion());
}
}
}
use of com.huawei.gray.dubbo.utils.FieldPrivilegedAction in project Sermant by huaweicloud.
the class ObjectTypeStrategy method getValue.
@Override
public String getValue(Object arg, String type) {
try {
Field field = arg.getClass().getDeclaredField(getKey(type));
AccessController.doPrivileged(new FieldPrivilegedAction(field));
Object object = field.get(arg);
return object == null ? null : String.valueOf(object);
} catch (IllegalArgumentException e) {
log(type);
return null;
} catch (IllegalAccessException e) {
log(type);
return null;
} catch (NoSuchFieldException e) {
log(type);
return null;
}
}
Aggregations