On (turn) Odoo web mechanism

 

https://blog.csdn.net/jehuyang/article/details/79502947

 

Odoo as open source ERP, has been widely used in Europe, but in China, basically still in its infancy, the country's application is not too much, therefore, from the market point of view, its application potential is enormous. To understand the basis Odoo secondary development, it must be necessary to run the basic principles of web Odoo of the order from the macro to Odoo have a general understanding. This article is based on this purpose, a brief analysis, hoping to help develop Odoo applications.
         Odoo used programming language python, python web itself can not directly process the request, and the like java web requests can not be processed directly, or require a bridge medium, it is possible to make based on the processing request Odoo python from WebServer after packaging What, is it the media or a bridge? The bridge is WSGI. So in the end what is WSGI it?

 

1 WSGI

        WSGI's official definition: the Python WebServer Gateway Interface. As the name suggests, this is a Gateway, which is the gateway, specific criteria see http://legacy.python.org/dev/peps/pep-0333/

         (Note: The following is an excerpt from the article [1])

        A gateway conversion is performed, as shown in FIG protocol between

                                      

 

        WSGI while attached to the web server, the other side attached to the user's application. However, the function of this bridge is very weak, and sometimes need anything else to help bridge can be processed, as shown below:

                                                       

 

In the figure above:

         wsgiapp also known as the application is a WSGIapplication.

         wsgi container, also known as the container, although this is often referred to as section handler, handler and app easy to confuse, so called containers.

         wsgi_middleware, also known as middleware, a special type of program, specializing in container and additional processing applications

 Details of specific wsgi app, wsgi container and wsgi middleware relations see article [1]

web operating mechanism of 2 Odoo    

2.1 Odoo in web server

Odoo defines itself to achieve the 4 types of web server, the file can be known from server.py

   

  

 

CommonServer three other server parent

 
   

                                                                                                                                          

 

 

When Odoo running default choice ThreadedServer as standard web server

The 2.2 Odoo web container

Odoo the web container is defined in the wsgi_server.py

                                                     

 

Entry function shall be:

def application(environ, start_response)

 

By determining whether a proxy mode defined in the header information and proxy_mode openerp-server.conf in "HTTP_X_FORWARDED_HOST" request to determine whether the agent, thereby performing corresponding processing

 

2.3 Odoo 中 的 webhandler

   In the Odoo, since the present odoocontainer, then there must be specific handler for processing the request, the hander will be appreciated that a particular container servelt

   odoo handler defined in http.py file

  

At run time, by the calling method register_wsgi_handler HandlerRoot odoo container will register into the container, as shown in the following code:

 

  

This handler is implemented using a full packet werkzeug second package, and the common subject in reponse request. Werkzeug specific content, see http://werkzeug.pocoo.org/

 

2.3.1 Handler request distribution

Http request for a

     既然可以把handler当做java中的servlet,且Odoo中只有Root这样一个handler,那么可以推定Root必然要负责对所有外部来的请求进行分发处理,通过url映射到具体的controller中来进行处理,执行这个操作的就是Root类的dispatch函数   

 2 对于Http  XML-RPC请求

        则由http.py中的dispatch_rpc函数进行处理

2.3.2 Session的处理

     Session对于web应用来说相当重要,在Odooo中,session类为OpenERPSession类,定义在http.py文件中

       

  Session什么时候被创建?

  在handler类初始化时,创建一个空的session对象,该对象并没有具体的值,如下图所示

    

 

当用户第一次登录或者访问系统时,Root类的dispatch方法被调用时被创建

Session 保存在什么地方?

Odoo中的session不是保存在内存中,而是保存在磁盘中,通过openerp.tools.config.session_dir参数设置保存地址,默认地址是在本地应用数据目录,以我的机子为例,默认的存放地址就是:C:\Users\janusx\AppData\Local\OpenERPS.A.\OpenERP\sessions\8.0

因此,我们可以通过设置openerp.tools.config.session_dir变量的值来改变odoo session保存的位置,可以是保存在本地或者结合Redis将Session保存到Redis中

Session 保存的时间是多少?

Odoo对于session的保存,默认是一周,对于超过一周的session,session_gc函数会将其从文件中移除,如下代码所示:

                                                                

因此,我们可以通过自定义这个时间,来延长或者缩短Odoo的session的保存时间

2.4 Odoo web启动流程

           通过以上分析,我们可知Odoo的启动流程,如下图所示

 

 

参考:

[1] http://linluxiang.iteye.com/blog/799163

Guess you like

Origin www.cnblogs.com/stableboy/p/11106578.html