0

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.

niton
9,25923 gold badges37 silver badges58 bronze badges
asked Apr 25, 2013 at 9:50

1 Answer 1

2

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.

answered Apr 25, 2013 at 9:56
2
  • i am afraid will there be order in which i put data in to List? Commented 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. Commented Apr 25, 2013 at 10:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.