Details
-
Sub-task
-
Status: Resolved
-
Major
-
Resolution: Not A Problem
-
None
-
None
-
None
Description
Sqoop client posts parameters as JSON to server. As it is not query string based pattern, HttpServletRequest is not able to return the JSON using getParameterValue(...). The current solution is to call getReader() to get raw post data. There is a danger, if the method is NOT called at the first place. You do not know, whether the reading position is at the beginning. You might get unexpected result without notice. SQOOP-1784 is a unfortunate case.
// 2 line unlucky code String username = ctx.getUserName(); // The method will change reading position of reader internally JSONObject postData = (JSONObject) JSONValue.parse(ctx.getRequest().getReader()); // No contents read // 2 line lucky code JSONObject postData = (JSONObject) JSONValue.parse(ctx.getRequest().getReader()); // Good String username = ctx.getUserName(); // Good
In practice, it'd suggest to use query string base pattern, i.e. jsonObject=JSON. The server can call ctx.getParameterValue("jsonObject") to get the value without any problem. But we need to change the api.
Now it is perfectly clear:
1. For query string based pattern, caller should always use getParameterValue(...).
2. For raw post data usage, the post data is parsed as the first parameter's key. So I'd suggest to add RequestContext.getFirstParameterName(). so that we can keep fingers away from getReader().
Attachments
Issue Links
- links to