It seems like Jersey 2.0 (using servlet 3.1) is not able to decode a parameter when the charset
property is specified in the Content-Type
header.
For example considering the following endpoint:
@POST
@Path("/hello")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response hello(@FormParam("name") String name) {
System.out.println(name);
return ok();
}
This curl request works:
curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "name=tom" http://localhost:8080/sampleapp/hello
The following request instead doesn't work and the name
parameter is null
:
curl -X POST -H "content-type: application/x-www-form-urlencoded; charset=UTF-8" -d "name=tom" http://localhost:8080/sampleapp/hello
I think the charset=UTF-8
addition in the content type breaks my code.
EDIT:
I've opened an official ticket just in case this is a bug: https://java.net/jira/browse/JERSEY-1978
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…