I have the following LinkedHashMap in which I put values in the following way:
if (preAuthorizeAnnotation != null) {
requestMappingValues = requestMappingAnnotation.value(); // to get the url value
RequestMethod[] methods = requestMappingAnnotation.method(); // to get the request method type
System.out.println(+i + ":Method : " + method2.getName() + " is secured ");
//System.out.println("Requestion method type : "+methods[0].name());
Class[] parameterTypes = method2.getParameterTypes();
for (Class class1: parameterTypes) {
userDefinedParams = new UserDefinedParams();
strClassNameToFix = class1.getName();
strClassname = strClassNameToFix.replaceAll("\\[L", "").replaceAll("\\;", "");
if (class1.isArray()) {
//classObj = strClassnames.substring(strClassnames.lastIndexOf('.')+1, strClassnames.length()-1);
userDefinedParams.setDataType(strClassname);
userDefinedParams.setIsArray("Y");
paramsList.add(userDefinedParams);
} else if (class1.isPrimitive() && class1.isArray()) {
userDefinedParams.setDataType(strClassname);
userDefinedParams.setIsArray("Y");
paramsList.add(userDefinedParams);
} else {
userDefinedParams.setDataType(strClassname);
userDefinedParams.setIsArray("N");
paramsList.add(userDefinedParams);
}
System.out.println("strClassname : " + strClassname);
}
paramsMap.put("url_" + i, requestMappingValues[0]);
paramsMap.put("params_" + i, paramsList);
I try to loop through the map like the following :
for (Object key: paramsMap.keySet()) {
uri = "http://localhost:8080/api" + paramsMap.get(key);
statusCode = httpRequest.handleHTTPRequest(client, uri);
System.out.println("Statuscode : " + statusCode);
}
I get the following exception :
java.lang.IllegalArgumentException
because for the first time it gets the url
correctly but it misses the params
.
I want the url and paramList
separately so that I can process it.
I am trying to get the url and corrresponding paramlist for the url and convert the paramList back to userdefined and the value for the further process.
1 Answer 1
The best solution is probably to have 2 separate maps: one for the urls and the other one for the params.
However, it seems you do not need maps since you only use them as lists for storing urls and params. You should therefore consider using one list for the urls and one list for the params, the i
you currently append to the String being the key in your maps would be the index in the lists:
urls.add(requestMappingValues[0]);
params.add(paramsList);
And later you just iterate over those lists to retrieve the values inserted.
-
i am afraid will there be order in which i put data in to List?Java Questions– Java Questions04/25/2013 09:58:26Commented Apr 25, 2013 at 9:58
-
Hi Vakh thanks a lot, it worked i changed my way of putting things and changed as you suggested. It works like charms now. :) +1 for the suggestion.Java Questions– Java Questions04/25/2013 10:09:36Commented Apr 25, 2013 at 10:09