[FIX] JSON-RPC2 request/response process
bzr revid: xmo@openerp.com-20110317130946-ptpaihigvie31moo
This commit is contained in:
@@ -143,27 +143,28 @@ openerp.base.Session = openerp.base.BasicController.extend({
|
||||
// Construct a JSON-RPC2 request, method is currently unused
|
||||
params.session_id = this.session_id;
|
||||
params.context = typeof(params.context) != "undefined" ? params.context : this.context;
|
||||
var request = { jsonrpc: "2.0", method: "call", params: params, "id":null };
|
||||
|
||||
// This is a violation of the JSON-RPC2 over HTTP protocol
|
||||
// specification but i don't know how to parse the raw POST content from
|
||||
// cherrypy so i use a POST form with one variable named request
|
||||
var post = { request: JSON.stringify(request) };
|
||||
|
||||
// Use a default error handler unless defined
|
||||
error_callback = typeof(error_callback) != "undefined" ? error_callback : this.on_rpc_error;
|
||||
|
||||
// Call using the rpc_mode
|
||||
this.rpc_ajax(url, post, success_callback, error_callback);
|
||||
this.rpc_ajax(url, {
|
||||
jsonrpc: "2.0",
|
||||
method: "call",
|
||||
params: params,
|
||||
id:null
|
||||
}, success_callback, error_callback);
|
||||
},
|
||||
rpc_ajax: function(url, post, success_callback, error_callback) {
|
||||
rpc_ajax: function(url, payload, success_callback, error_callback) {
|
||||
var self = this;
|
||||
this.on_rpc_request();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
data: post,
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(payload),
|
||||
processData: false,
|
||||
success: function(response, textStatus, jqXHR) {
|
||||
self.on_rpc_response();
|
||||
if (response.error) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import functools
|
||||
|
||||
import os, re, sys, traceback, xmlrpclib
|
||||
|
||||
@@ -129,11 +130,11 @@ class JsonRequest(object):
|
||||
return simplejson.dumps(r)
|
||||
|
||||
def jsonrequest(f):
|
||||
# check cleaner wrapping:
|
||||
# functools.wraps(f)(lambda x: JsonRequest().dispatch(x, f))
|
||||
l=lambda self, request: JsonRequest().dispatch(self, f, request)
|
||||
l.exposed=1
|
||||
return l
|
||||
@cherrypy.expose
|
||||
@functools.wraps(f)
|
||||
def json_handler(self):
|
||||
return JsonRequest().dispatch(self, f, cherrypy.request.body.read())
|
||||
return json_handler
|
||||
|
||||
class HttpRequest(object):
|
||||
""" Regular GET/POST request
|
||||
|
||||
Reference in New Issue
Block a user