Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How can a new WSGI handler be registered ?

By
Nicolas Wisniewski (nwi)
on 1/29/13, 11:59 AM 1,686 views

What is the correct way to register a new WSGI handler provided by an addons?

4
Vo Minh Thu
On 2/5/13, 5:27 PM

To register a new WSGI handler, the best way is to mimic what is done by the web module:

In its __openerp__.py file, it declares a hook to be called when the module is loaded (that is, even if a database/registry is not loaded).

'post_load': 'wsgi_postload'

Then, grepping for wsgi_postload's definition, we see it simply registers its WSGI handler with the openerp.wsgi.register_wsgi_handler() function.

Note that routing between the different WSGI handlers is pretty basic in OpenERP: each handler is tried. If the handler returns None, the next one is tried and so on. If it does not return None, it must instead handle the request.

1
Jigar Amin
On 2/5/13, 12:41 PM

Hello Niko,

All OpenERP Services which are exposed on any Kind of Service Weather it's WSGI or any other way.

So all in all you need to create new web service under file : - /70/server/openerp/service/web_services.py

Then write your service handlers like below example:

class testservice(netsvc.ExportService):
    def __init__(self, name="db"):
        netsvc.ExportService.__init__(self, name)
        self.actions = {}
        self.id = 0
        self.id_protect = threading.Semaphore()

    def dispatch(self, method, params):
        if method in [ 'create',:
            passwd = params[0]
            params = params[1:]
            security.check_super(passwd)
        else:
            raise KeyError("Method not found: %s" % method)
        fn = getattr(self, 'exp_'+method)
        return fn(*params)

    def exp_create(self, param, param):
        #Your Service hanlder Code goes here...
        return id

and this service will be exposed as regular service.

and can be used as other services.

Thank YOu

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 1/29/13, 11:59 AM
Seen: 1686 times
Last updated: 3/16/15, 8:10 AM