* @return
* @throws Exception
*/
private HttpMethod initMethod(String url, String methodType,
ModelMap<String, Object> parameters) throws Exception {
HttpMethod method = null;
if(parameters == null)
parameters = new ModelMap<String, Object>();
Object args = parameters != null ? parameters
.get(ModelMap.RPC_ARGS_KEY) : null;
if (methodType.equalsIgnoreCase("get")) {
method = new GetMethod(url);
} else if (methodType.equalsIgnoreCase("post")) {
PostMethod postMethod = new PostMethod(url);
if (args != null) {
byte[] output = constructArgs(method, args);
postMethod.setRequestEntity(new ByteArrayRequestEntity(output));
}
method = postMethod;
} else if (methodType.equalsIgnoreCase("put")) {
method = new PutMethod(url);
if (args != null) {
byte[] output = constructArgs(method, args);
((PutMethod) method)
.setRequestEntity(new ByteArrayRequestEntity(output));
}
} else if (methodType.equalsIgnoreCase("delete")) {
method = new DeleteMethod(url);
}
if (parameters.get(ModelMap.RPC_ARGS_KEY) != null)
method.addRequestHeader("content-type", "application/javabean");
if (parameters != null) {
Object value;
List<String> queryStringList = new ArrayList<String>();
Set<String> keySet = parameters.keySet();
for (String key : keySet) {
if (!key.toString().equalsIgnoreCase(ModelMap.RPC_ARGS_KEY)
&& !key.toString().equalsIgnoreCase(
ModelMap.FILE_ITEM_ARGS_KEY)) {
value = parameters.get(key);
method.getParams().setParameter(key, value);
queryStringList.add(key + "=" + value);
}
}
if (methodType.equalsIgnoreCase("get"))
method.setQueryString(StringUtils.join(queryStringList, "&"));
}
return method;
}