diff --git a/server/src/main/java/com/cloud/api/ApiServer.java b/server/src/main/java/com/cloud/api/ApiServer.java index 91812e655178..4ba246c40479 100644 --- a/server/src/main/java/com/cloud/api/ApiServer.java +++ b/server/src/main/java/com/cloud/api/ApiServer.java @@ -464,7 +464,11 @@ public void handle(final HttpRequest request, final HttpResponse response, final responseType = param.getValue(); continue; } - parameterMap.put(param.getName(), new String[]{param.getValue()}); + if(parameterMap.putIfAbsent(param.getName(), new String[]{param.getValue()}) != null) { + String message = String.format("Query parameter '%s' has multiple values [%s, %s]. Only the last value will be respected." + + "It is advised to pass only a single parameter", param.getName(), param.getValue(), parameterMap.get(param.getName())); + s_logger.warn(message); + } } } diff --git a/server/src/main/java/com/cloud/api/ApiServlet.java b/server/src/main/java/com/cloud/api/ApiServlet.java index 3d4167eaf4c8..09195e0fe227 100644 --- a/server/src/main/java/com/cloud/api/ApiServlet.java +++ b/server/src/main/java/com/cloud/api/ApiServlet.java @@ -136,6 +136,17 @@ public void run() { }); } + private void checkSingleQueryParameterValue(Map params) { + params.forEach((k, v) -> { + if (v.length > 1) { + String message = String.format("Query parameter '%s' has multiple values %s. Only the last value will be respected." + + "It is advised to pass only a single parameter", k, Arrays.toString(v)); + s_logger.warn(message); + } + }); + + } + void processRequestInContext(final HttpServletRequest req, final HttpServletResponse resp) { InetAddress remoteAddress = null; try { @@ -156,7 +167,9 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp // get the response format since we'll need it in a couple of places String responseType = HttpUtils.RESPONSE_TYPE_XML; final Map params = new HashMap(); - params.putAll(req.getParameterMap()); + Map reqParams = req.getParameterMap(); + checkSingleQueryParameterValue(reqParams); + params.putAll(reqParams); // For HTTP GET requests, it seems that HttpServletRequest.getParameterMap() actually tries // to unwrap URL encoded content from ISO-9959-1.