1

I'd like to ask a question related to an issue I encountered with Glassfish 4.0 Web application deployment.

I created a REST Web service application with JAX-RS and deployed it on Glassfish 3.1.2 with no issue. Recently I tried deploying it on Glassfish 4.0 and encountered a warning as follows.

A servlet request to the URI http://localhost:8080/IipDev3/root/provider/publication/info:647254662 contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

I use javax.ws.rs.core.MultivaluedMap to store the form parameters, but it is indeed empty for HTTP POST requests. Strangely, it is not empty for HTTP PUT requests. I have tried searching for solutions on the Internet but got stuck (in the worst case I can fallback to Glassfish 3.1.2 deployment of course).

Code snippets:

@POST
@Path("publication/{infoId}")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/xml")
public String publishToAnInformationChannel(@PathParam("infoId") String infoId,
MultivaluedMap formParams, @Context SecurityContext sc) {
// formParams empty + warning
}

@PUT
@Path("registration/information/{infoId}")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/xml")
public String updateAnInformationChannel(@PathParam("infoId") String infoId,
MultivaluedMap formParams, @Context SecurityContext sc) {
// formParams filled in + no warning
}

If anyone knows how to solve this issue, please let me know. Thanks a lot.

  • Can you not use the `@FormParam` annotation to inject the parameters instead of using the map? Also, it might be worth trying to add a single `@FormParam` in addition to the `MultivalueMap` to see if that prevents the parameters from being consumed (e.g. add `@FormParam("unused") String unused` but continue to use the map) – DannyMo Aug 14 '13 at 21:45
  • 1
    Thanks for the feedback. `@FormParam` worked fine for both `@POST` and `@PUT` to inject parameters. I tried adding a single `@FormParam` in addition to the `MultivaluedMap` for `@POST`, but the `MultivaluedMap` variable is still empty. The reason why I use `MultivaluedMap` instead of `@FormParam` is that I need to enable the resource to handle multiple parameters without being known in advanced (`@FormParam` limits the number and names of the parameters). Currently I fallback to older Glassfish 3.1.2.2 and deploy the application with no issue. – Dafferianto Trinugroho Aug 21 '13 at 16:01

1 Answers1

0

MultivaluedMap needs generic information:

MultivaluedMap<String, String> formParams
Georg
  • 987
  • 8
  • 16