Endpoints can be explicitly marked as `save_session=False` (default is true across the board). In that case they will have an in-memory session (either the existing one or a brand new one) but the session won't be persisted to disk. Currently used for non-browser RPC endpoints: the APIs don't use cookies/sessions and we can't assume the RPC libraries keep cookies across calls. This means a new session is created and saved to disk for each RPC calls, for no useful reason.
45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from xmlrpc.client import dumps, loads
|
|
|
|
from werkzeug.wrappers import Response
|
|
|
|
from odoo.http import Controller, dispatch_rpc, request, route
|
|
from odoo.service import wsgi_server
|
|
|
|
|
|
class RPC(Controller):
|
|
"""Handle RPC connections."""
|
|
|
|
def _xmlrpc(self, service):
|
|
"""Common method to handle an XML-RPC request."""
|
|
data = request.httprequest.get_data()
|
|
params, method = loads(data)
|
|
result = dispatch_rpc(service, method, params)
|
|
return dumps((result,), methodresponse=1, allow_none=False)
|
|
|
|
@route("/xmlrpc/<service>", auth="none", method="POST", csrf=False, save_session=False)
|
|
def xmlrpc_1(self, service):
|
|
"""XML-RPC service that returns faultCode as strings.
|
|
|
|
This entrypoint is historical and non-compliant, but kept for
|
|
backwards-compatibility.
|
|
"""
|
|
try:
|
|
response = self._xmlrpc(service)
|
|
except Exception as error:
|
|
response = wsgi_server.xmlrpc_handle_exception_string(error)
|
|
return Response(response=response, mimetype='text/xml')
|
|
|
|
@route("/xmlrpc/2/<service>", auth="none", method="POST", csrf=False, save_session=False)
|
|
def xmlrpc_2(self, service):
|
|
"""XML-RPC service that returns faultCode as int."""
|
|
try:
|
|
response = self._xmlrpc(service)
|
|
except Exception as error:
|
|
response = wsgi_server.xmlrpc_handle_exception_int(error)
|
|
return Response(response=response, mimetype='text/xml')
|
|
|
|
@route('/jsonrpc', type='json', auth="none", save_session=False)
|
|
def jsonrpc(self, service, method, args):
|
|
""" Method used by client APIs to contact OpenERP. """
|
|
return dispatch_rpc(service, method, args)
|