I have used Invocation handler for reflection. and in findApiKeys method, I am trying to modify the value of args array. but its not changing the value. its giving me same value.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String apiKey = findApiKey(args);
if (cache.get(method.getName()) != null) {
ServicesCacheKey cacheKey = new ServicesCacheKey();
Map<String, Object> parameters = new HashMap<>();
cacheKey.setApiKey(apiKey);
parameters.put(PARAMETERS_KEY, args[0]);
cacheKey.setParameters(parameters);
return cache.get(method.getName()).get(cacheKey);
} else if (multiMap.get(method.getName()) != null) {
Set<ServicesCacheKey> servicesCacheKeys = getCacheKeySetFromArgList((Set<Object>) args[0], apiKey);
Map<ServicesCacheKey, Object> result = multiMap.get(method.getName()).getAll(servicesCacheKeys);
return getResultMapFromCacheKeyMap(result);
} else {
return i1.invoke(proxy, method, args); // **problem here**
}
}
private String findApiKey(Object[] args) {
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
if (arg instanceof String) {
String k = (String) arg;
int index = k.indexOf("apiKey~~");
if (index != -1) {
String apiKey = k.substring(index + "apiKey~~".length());
args[i] = apiKey;
return apiKey;
}
}
}
throw new IllegalArgumentException("Api Key must not be empty");
}
stacktrace :
2016-08-24 03:54:33,849 [vli13:39922] [P7000] ERROR arch.service.thrift.SearchImpl - Invalid Request to dependencies services: null, Reason: Provided API key {apiKey~~solr} is not authorized to access experiment service. Please talk to service administrator to obtain a valid api key
Same code is working without reflection api
example:
public static void main(String[] args) throws InterruptedException {
Object[] argss = new Object[] {"Pankaj", "api~~solr"};
findApiKey(args);
System.out.println(argss[0] + " " + argss[1]);
}
output : pankaj solr
Aucun commentaire:
Enregistrer un commentaire