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
  • 8,771
  • 21
  • 32
  • 52
Java Questions
  • 7,813
  • 41
  • 118
  • 176

1 Answers1

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.

Jean Logeart
  • 52,687
  • 11
  • 83
  • 118