2

I'm trying to gather all parameters of an HTTP POST request into a map, however it's not working.

With a GET, I used:

@Context
private HttpServletRequest request;

and

@GET
@Path("/{uuid}/invoke/{method}")
public Response invokeMethod (
    @PathParam("uuid") String uuid,
    @PathParam("method") String methodz
) {
    Map<String, String[]> params = request.getParameterMap();

and it returned the map. However, when sending form data via a POST instead of inline with the URL, the map is being returned as NULL.

Is there a similar way to retrieve all the parameters at once using a POST?

EDIT:

My data is being submitted as a serialized JSON, so using a cURL statement as an example:

curl --data "firstname=john&lastname=smith" http://localhost:8080/uuid1/apitest/method1

Ideally, I'd want to get a hashmap of something like:

ParamMap["firstname"] = "john"
ParamMap["lastname"] = "smith"

Also, the parameters won't be static, so this cURL:

curl --data "job=construction" http://localhost:8080/uuid2/apitest/method2

would result in:

ParamMap["job"] = "construction"
ev0lution37
  • 1,129
  • 2
  • 14
  • 28

2 Answers2

1

Finally got this resolved using this thread:

Jersey: Consume all POST data into one object

My new function is:

@POST
@Path("/{uuid}/invoke/{method}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response invokeMethod (
    MultivaluedMap<String,String> params,
    @PathParam("uuid") String uuid,
    @PathParam("method") String method
) {

Variable 'params' is now a map containing form data key/value pairs.

Community
  • 1
  • 1
ev0lution37
  • 1,129
  • 2
  • 14
  • 28
-1

You can try following code

@POST
@Path("/{uuid}/invoke/{method}")
public Response invokeMethod (
    @Context UriInfo request
) {
    Map<String, List<String>> params = request.getPathParameters();
  }

You no need to write

 @Context
 private HttpServletRequest request;

Now You can get idea...

Hardik Visa
  • 323
  • 6
  • 23
  • This would just get parameters set within the URI, not the actual POST data in the body. I've updated my question with how I'd be submitting the HTTP request to give you a better idea of what I'm looking for. – ev0lution37 Sep 10 '14 at 13:21