“读”使用 java 和 apache xml-rpc 从 OpenERP 获取具有多个 ID 的数据
您好,我目前正在使用 Apache XML-RPC 连接到 OpenERP 编写一个 servlet。周围没有任何好的资源,而且 OpenERP 网站上的 Java 示例非常简单且远未完成。
有谁知道我在哪里可以找到关于如何在 OpenERP 端调用以及调用什么的 API?
我真的很感激!
进一步说明,我专门寻找有关如何使用 java 并输入多个 id 来“读取”数据的语法。
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
clientConfig.setEnabledForExtensions(true);
clientConfig.setServerURL(new URL(urlStringObject));
client.setConfig(clientConfig);
Object[] params2 = { "city", "name", "email", "create_date","write_date" };
Vector<Object> arg = new Vector<Object>();
arg.add(database);
arg.add(1);
arg.add(password);
arg.add("res.partner.address");
arg.add("read");
arg.add(9); // <- THE PYTHON SYNTAX SAYS input 'LIST OF IDS' here What is the Jave equivalent???
arg.add(params2);
HashMap ids = (HashMap) client.execute("execute", arg);
更新
/* Search for all ids */
xmlrpcConfigLogin.setServerURL(new URL(urlStringObject));
Object[] searchQuery = new Object[] {"id", "!=", -1 };
Vector queryVector = new Vector();
queryVector.addElement(searchQuery);
Object[] params = new Object[] { database, theloginId , password, tableName, "search", queryVector };
Object[] po_ids = (Object[]) xmlrpcLogin.execute("execute", params);
/* Send Read Query */
Object[] readQuery = {"name"};
Vector<Object> arg = new Vector<Object>();
arg.add(database);
arg.add(1);
arg.add(password);
arg.add(tableName);
arg.add("read");
arg.add(po_ids);
arg.add(readQuery);
HashMap globalMap = new HashMap();
Object[] hm = (Object[]) xmlrpcLogin.execute("execute", arg);
for (Object object : hm) {
HashMap hash = (HashMap)object;
globalMap.put("name", hash.get("name"));
_log.info(hash.get("name"));
}
如您所见:它采用 ids 的 Object[] 作为输入 (po_ids)
Hi I am currently writing a servlet using Apache XML-RPC connecting to OpenERP. There are not any good resources around, and the java examples are very minimalistic and far from complete on the OpenERP site.
Has anyone a clue where I could find an API on how and what I can call on the OpenERP side?
I would really appreciate that!!!
On a further note, I am specifically looking for the syntax on how to "read" data, using java, with an input of multiple ids.
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
clientConfig.setEnabledForExtensions(true);
clientConfig.setServerURL(new URL(urlStringObject));
client.setConfig(clientConfig);
Object[] params2 = { "city", "name", "email", "create_date","write_date" };
Vector<Object> arg = new Vector<Object>();
arg.add(database);
arg.add(1);
arg.add(password);
arg.add("res.partner.address");
arg.add("read");
arg.add(9); // <- THE PYTHON SYNTAX SAYS input 'LIST OF IDS' here What is the Jave equivalent???
arg.add(params2);
HashMap ids = (HashMap) client.execute("execute", arg);
UPDATE
/* Search for all ids */
xmlrpcConfigLogin.setServerURL(new URL(urlStringObject));
Object[] searchQuery = new Object[] {"id", "!=", -1 };
Vector queryVector = new Vector();
queryVector.addElement(searchQuery);
Object[] params = new Object[] { database, theloginId , password, tableName, "search", queryVector };
Object[] po_ids = (Object[]) xmlrpcLogin.execute("execute", params);
/* Send Read Query */
Object[] readQuery = {"name"};
Vector<Object> arg = new Vector<Object>();
arg.add(database);
arg.add(1);
arg.add(password);
arg.add(tableName);
arg.add("read");
arg.add(po_ids);
arg.add(readQuery);
HashMap globalMap = new HashMap();
Object[] hm = (Object[]) xmlrpcLogin.execute("execute", arg);
for (Object object : hm) {
HashMap hash = (HashMap)object;
globalMap.put("name", hash.get("name"));
_log.info(hash.get("name"));
}
As you can see: It takes an Object[] of ids as input (po_ids)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您已经通读了 XML-RPC 的开发人员书籍描述。我认为它只是 ORM 类中所有 方法的包装。这就是我所看到的所有文档。除此之外,我在调试模式下运行 OpenERP,并在 LocalService.__call__() 方法中放置一个断点,以查看客户端向服务器发送哪些参数。 (它位于
server/bin/netsvc.py
中。)我还看到开发人员只是记录通过该方法发出的每个请求。至于如何在 Java 中进行调用,我不熟悉
XmlRpcClient
API,但看起来它会接受列表中的对象数组,并且可能接受任何可枚举的内容。查看数据类型描述是否有帮助,并查看单词跟踪器教程。它使用Vector
来保存列表参数。I assume you've read through the developer book description of XML-RPC. I think that it's just a wrapper around all the methods in the ORM class. That's all the documentation I've seen. Other than that, I run OpenERP in debug mode and put a break point in the
LocalService.__call__()
method to see what parameters the client is sending to the server. (It's inserver/bin/netsvc.py
.) I've also seen developers just log every request that comes through that method.As for how to make the calls in Java, I'm not familiar with the
XmlRpcClient
API, but it looks like it will accept an array of objects for a list, and probably anything that is enumerable. See if the description of data types is helpful, and check out the word tracker tutorial. It uses aVector
to hold a list parameter.