/**
NOTE: This code is based on ariba.util.net.HTTPRequest
*/
protected static Parameters parameters (AWRequest request)
{
Parameters parameters = null;
String contentString = null;
String queryStringForPost = null;
String contentType = request.contentType();
if (!StringUtil.nullOrEmptyOrBlankString(contentType)) {
String[] values = StringUtil.delimitedStringToArray(contentType, ';');
contentType = values[0].trim();
}
if (contentType == null || GETMethod.equals(request.method())) {
String queryString = request.queryString();
if (queryString != null) {
contentString = queryString;
if (contentString.equals("null")) {
contentString = null;
}
}
}
else if (contentType.equalsIgnoreCase(
AWContentType.ApplicationWWWFormUrlEncoded.name)) {
byte[] contentBytes = request.content();
if (contentBytes != null && contentBytes.length > 0) {
contentString = new String(contentBytes);
}
//sometimes we need parameters in the query string for POST also.
//add query string parameters also to form values
//if they don't exist already
queryStringForPost = request.queryString();
Log.aribaweb_request.debug("queryStringForPost:%s", queryStringForPost);
if (queryStringForPost != null
&& queryStringForPost.equals("null")) {
queryStringForPost = null;
}
}
if (!StringUtil.nullOrEmptyOrBlankString(contentString)) {
parameters = parametersFromUrlEncodedString(contentString);
}
if (!StringUtil.nullOrEmptyOrBlankString(queryStringForPost) &&
parameters != null) {
Parameters queryParameters = parametersFromUrlEncodedString(queryStringForPost);
Iterator itr = queryParameters.getParameterNames();
while(itr.hasNext()) {
String name = (String)itr.next();
//add to parameters if it is not already exist.
if (parameters.getParameterValues(name) == null) {
Log.aribaweb_request.debug("Adding query string parameter to form:%s",
name);
parameters.putParameter(name,
queryParameters.getParameter(name));
}
}
}
return parameters;