问题
Client code:
FormDataBodyPart f = new FormDataBodyPart(...);
FormDataBodyPart f2 = new FormDataBodyPart(...);
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(f);
multiPart.bodyPart(f2);
//Execute Call
WebResource wr = resource().path(Url.X);
wr = wr.queryParam("subjectId", "value_something");
ClientResponse response = wr.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, multiPart);
Server code:
String id = req.getParameter("subjectId");
req is HttpServletRequest - injected by spring
@Context
protected HttpServletRequest httpServletRequest;
Problem: on some of the environments the id parameter retrieved is null. In the filter we print the while request parameters map to log in it is just empty.
We believe the problem is on server side since the same client executed vs. different environments gives different result.
On some servers the parameter is always empty, from all clients, and on other environments the parameter is always there, from all clients.
So... it looks like the problem on the Tomcat side, but... where?
Update: result from wireshark on server:
[Malformed Packet: MIME multipart]
Expert Info (Error/Malformed): Malformed Packet (Exception occurred)
Message: Malformed Packet (Exception occurred)
on some servers despite the error - the parameter is there and on others the param is missing.
Update: the logged request by AccessLogValve contains the parameter
127.0.0.1 - - [26/Nov/2012:03:04:58 -0800] "POST /api/get-retrieve?x=y HTTP/1.1" 200 16
So, probably the problem is somewhere in the Tomcat throwing out those params...
回答1:
Check if request object is valid? Also you can try other approaches like reading parameter using request.getParameterMap() or reading Input stream .
回答2:
We had this problem and it turned out that we were allowing multiple threads to access the HttpServletRequest object. This is not allowed. It is not thread safe.
来源:https://stackoverflow.com/questions/13560023/request-parameters-are-dropped-in-tomcat