public static void setParameters(
HttpRequest request, HttpContext context, String encoding) {
String path = request.getRequestLine().getUri();
//String path = docsRoot + request.getRequestLine().getUri();
RequestParameters parameters = getParameters(context);
if (path.indexOf('?') >= 0) {
String[] requestParams = path.split("\\?");
//path = requestParams[0];
//set request parameters for Custom HttpRequest.
if (requestParams.length >= 2) {
String params = requestParams[1];
String[] param = params.split("&");
for (String kv : param) {
String[] p = kv.split("=");
if (p.length >=2) {
parameters.setParameter(p[0], decode(p[1], encoding));
}
}
}
}
if (isEntityEnclosingRequest(request) && ! RequestUtils.isMultipart(request)) {
HttpEntity entity = getEntity(request);
if (entity != null) {
InputStream in = null;
BufferedReader reader = null;
try {
in = entity.getContent();
reader = new BufferedReader(new InputStreamReader(in)); //8192byte buffers
String s;
StringBuilder sb = new StringBuilder();
while ((s = reader.readLine()) != null) {
sb.append(s);
}
String[] params = sb.toString().split("&");
for (String param : params) {
String[] keyValue = param.split("=");
if (keyValue.length >= 2) {
parameters.setParameter(keyValue[0],
decode(keyValue[1], encoding));
}
}
} catch (IOException e) {
throw new HttpException(BasicHttpStatus.SC_BAD_REQUEST, e);