Interfacing processing.org to OpenERP using XML-RPC

Processing.org / Processing.js

Processing.js is the sister project of the popular Processing visual programming language, designed for the web. Processing.js makes your data visualizations, digital art, interactive animations, educational graphs, video games, etc. work using web standards and without any plug-ins. You write code using the Processing language, include it in your web page, and Processing.js does the rest.


Iframe Wrapper



Checking XML-RPC Messages from OpenERP


The connection to OpenERP will throw many exceptions if the requests isn't handled correctly. 

To debug the messages from client and OpenERP I use the tools tcpmon or Wireshark.  

tcpmon is an open-source utility for monitoring the data flowing on a TCP connection. tcpmon is used by placing it in-between a client and a server. The client is made to connect to tcpmon, and tcpmon forwards the data to server along-with displaying it in its GUI.

This  enable you to send request to this tool first which then forwards the request to the OpenERP server. All message between the client and server are then visible,  e.g. to probe for a list of databases on the OpenERP server the following Java script is used:

XmlrpcClient client =  new XmlrpcClient("http://localhost:8079/xmlrpc/common");
Object[] params = new Object[]{dbname,uid,pwd};
Object res;
println (client.address());  
println(client.execute("login", params));


This is converted to the following string by the XML-RPC library and forward the OpenERP server:

POST /xmlrpc/db HTTP/1.1
Content-Type: text/xml
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0_33
Host: localhost:8079
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 148

<?xml version="1.0"?><methodCall><methodName>list</methodName><params><param><value>http://192.168.178.29:8069</value></param></params></methodCall>




------

this caused and error from proccessing


<?xml version="1.0"?>
<methodCall>
    <methodName>list
        </methodName>
            <params>
                <param>
                       <value>
                            http://192.168.178.29:8069
                        </value>
                </param>
            </params>
    </methodCall>



version="1.0"?>
<methodCall>
    <methodName>
            execute
    </methodName>
    <params>
        <param>
            <value>
                Indurad_demo1
            </value>
        </param>
        <param>
            <value>
                <int>
                    1
                </int>
            </value>
        </param>
        <param>
            <value>
                admin
            </value>
        </param>
        <param>
             <value>
                mrp.bom
                  </value>
            </param>
            <param>
                <value>
                    search
                </value>
            </param>
            <param>
                <value>
                       %
                </value>
            </param>
    </params>
</methodCall>

----------

this one from Python works

<?xml version='1.0'?>
<methodCall>
        <methodName>
                   execute
        </methodName>
        <params>
             <param>
                  <value>
                       <string>
                              admin
                        </string>
                   </value>
             </param>
             <param>
                   <value>
                        <int>
                              1
                        </int>
                   </value>
             </param>
             <param>
                   <value>
                        <string>
                              admin
                        </string>
                   </value>
             </param>
             <param>
                    <value>
                         <string>
                              product.product
                         </string>
                    </value>
              </param>
              <param>
                     <value>
                          <string>
                              search
                          </string>
                     </value>
               </param>
               <param>
                     <value>
                          <array>
                               <data>
                                    <value>
                                          <array>
                                               <data>
                                                   <value>                                                           
                                                        <string>
                                                                 bom_ids
                                                                                                                        
                                                        </string>
                                                  </value>
                                                  <value>
                                                        <string>
                                                                 &gt;
                                                        </string>
                                                  </value>
                                                  <value>
                                                         <string> 
                                                         </string>
                                                  </value>
                                               </data>
                                          </array>
                                   </value>
                             </data>
                        </array>
                    </value>
             </param>
       </params>
</methodCall>


-----------

The response back is (formated be me for easier reading):

<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value><string>Database1</string></value>
<value><string>Database2</string></value>
<value><string>Sandbox1</string></value>
<value><string>Sandbox2</string></value>
<value><string>Sandbox3</string></value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>


The actual string is formated as follows:

<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><string>BC_CRM_Jobs</string></value>
<value><string>Indurad_demo1</string></value>
<value><string>Sandbox1</string></value>
<value><string>Sandbox2</string></value>
<value><string>Sandbox3</string></value>
</data></array></value>
</param>
</params>
</methodResponse>

Connection Processing.org to OpenERP using XLM-RPC

import xmlrpclib.*;
import java.util.Vector;

String uid = "1";
String pwd = "admin";  
String dbname = "demo1";
String ids;
Object[] args = new Object[6];


//XmlrpcServer sock = serverProxy("http://your IP address here:8069/xmlrpc/object");
XmlrpcClient client =  new XmlrpcClient("http://192.168.178.29:8069/xmlrpc/common");
Object[] params = new Object[]{dbname,uid,pwd};
Object res;
println (client.address());  
println(client.execute("login", params));

//------------------------------------------
//List all the databases that exist at this IP address
//Note the path is to /xlmrpc/db
Object[] params2 = new Object[]{"http://192.168.178.29:8069"};
XmlrpcClient xmlrpcDb = new XmlrpcClient("http://192.168.178.29:8069/xmlrpc/db");
res=(xmlrpcDb.execute("list", params2));
println (res);

//------------------------------------------
//List records that exist in a table
//Note the path is to /xlmrpc/object


//----setting up the login and search expression
args[0] = "demo1";    //database
args[1] = "1";                //User ID
args[2] = "admin";            //Password
args[3] = "purchase.order";   //Object
args[4] = "search";

//----building the search expression
Object names[]=new Object[3];
names[0] = "state";
names[1] = "=";
names[2] = "draft";

//----combining the complete  expression

Vector param2 = new Vector();
param2.addElement(names);
args[5] =param2;


Object po_ids;
//Object[] params3 = new Object[]{dbname,uid,pwd, "res.partner","search",};
XmlrpcClient xmlrpcSearch = new XmlrpcClient("http://192.168.178.29:8069/xmlrpc/object");

po_ids=(xmlrpcSearch.execute("execute", args));

//po_ids=xmlrpcLogin.execute(“execute”, r);
Object[] d = (Object[]) po_ids;

Integer i=0;

for(i=0; i<d.length; i++){
   println((Integer)d[i]);
}








References



Magento XLMRPC to openerp

XLM-RPC Class overview

java-openerp-xmlrpc-libraries

Comments