_defaultContext.put("lang", language);
}
public HttpRequest JsonRpc( String url, String method, JSONObject args) {
HttpRequest request = HttpRequest.post(url);
// We re-inject sid cookie
if( !this._cookies.isEmpty() ) {
StringBuffer cookieHeader = new StringBuffer();
for( HttpCookie cookie : this._cookies) {
cookieHeader.append(cookie.toString());
cookieHeader.append(';');
}
request.header("Cookie", cookieHeader.toString());
};
JSONObject postData = new JSONObject();
postData.put("json-rpc", "2.0");
postData.put("method", method);
postData.put("params", args);
postData.put("id", "r"+this._rid);
this._rid++;
// set content type to json
request.contentType(HttpRequest.CONTENT_TYPE_JSON);
request.acceptJson();
request.send(postData.toString());
// We force method call
int statusCode = request.code();
if( statusCode != 200 ) {
// Here, user failed to provide a valid URL so either, method or service is incorrect
throw new OpenERPServiceOrMethodException("URL="+url);
};