1

I am trying to call this API via postman:

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void printDetails(final MultivaluedMap<String, String> formParams) {

    for(String key : formParams.keySet()) {
        System.out.println(key + "     " + formParams.get(key));
    }
}

But the map turns out to be empty. Please help me with the same.

PS: This is the first time I am trying to pass variable number of parameters to the api. I have referred to sending List/Map as POST parameter jersey and How to access parameters in a RESTful POST method.

I think my mistake is in the way I am passing the parameters in postman: postman image

Please help me with the same. Also please help with how to call this API via an ajax (in JS) call.

4
  • I am wondering whether the answer was helpful? Please let me know if it doesn't and what you get after trying this solution, so that I can look at it and resolve. Oct 10, 2016 at 11:56
  • @notionquest Sorry for the late reply. I just tried your answer. Unfortunately it also gave me an empty map!
    – Nannan AV
    Dec 20, 2016 at 11:25
  • Are you still facing the same issue or managed to find a solution? Dec 20, 2016 at 11:27
  • @notionquest i have found one possible solution. Refer to my answer below. Thank you for trying :)
    – Nannan AV
    Dec 20, 2016 at 12:01

2 Answers 2

2

Set the request header as "application/x-www-form-urlencoded".

Postman request header

Request body - Select raw and provide values as mentioned below:-

{
    "LOCATION": "Singapore"
}

enter image description here

1

I have found out one possible answer.

@POST
public void printDetails() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    Map<String, String[]> mapp =  request.getParameterMap();
    for(String key : mapp.keySet()) {
        System.out.println(key + "     " + mapp.get(key)[0]);
    }
}

Still not sure how to do it by passing "final MultivaluedMap" in the arguments

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.