Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

关于java xmlrpc调用时的int参数遇到问题



  • 本人打算在android手机上实现im_chat功能,<br />调其中一个方法时遇到问题,当方法中有参数是int类型时失败。如果参数为字符串类型,则没问题。<br />不知各位仁兄有没遇到过类似问题,请指教。<br /><br />调用片段:<br /> XmlRpcClient xmlrpc = new XmlRpcClient();<br /><br />         XmlRpcClientConfigImpl xmlrpcConfgDb = new XmlRpcClientConfigImpl();<br />         xmlrpcConfgDb.setEnabledForExceptions(true);<br />         xmlrpcConfgDb.setServerURL(new URL(<br />                 "http://localhost:8069/xmlrpc/object"));<br /><br />         xmlrpc.setConfig(xmlrpcConfgDb);<br /><br />          <br />         Object[] params = new Object[] { "sentai", 1, "admin", "im_chat.session",<br />                 "session_get",new Integer(5)};<br /><br />         try {<br />         Object[] o = (Object[]) xmlrpc.execute("execute_kw", params);<br /><br />         } catch (Exception e) {<br />             e.printStackTrace();<br />         }<br /> 出错信息:<br />java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer<br /> at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)<br /> at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)<br /> at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)<br /> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)<br /> at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)<br /> at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)<br /> at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)<br /> at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)<br /> at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)<br /> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)<br /> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)<br /> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)<br /> at odootest.imchat.main(imchat.java:158)<br />被调用的方法:<br />    def session_get(self, cr, uid, user_to, context=None):<br />    其中user_to为int型,在设用其他方法,当参数为字符串类型时均成功能。



  • 本人打算在android手机上实现im_chat功能,<br />调其中一个方法时遇到问题,当方法中有参数是int类型时失败。如果参数为字符串类型,则没问题。<br />不知各位仁兄有没遇到过类似问题,请指教。<br /><br />调用片段:<br /> XmlRpcClient xmlrpc = new XmlRpcClient();<br /><br />         XmlRpcClientConfigImpl xmlrpcConfgDb = new XmlRpcClientConfigImpl();<br />         xmlrpcConfgDb.setEnabledForExceptions(true);<br />         xmlrpcConfgDb.setServerURL(new URL(<br />                 "http://localhost:8069/xmlrpc/object"));<br /><br />         xmlrpc.setConfig(xmlrpcConfgDb);<br /><br />          <br />         Object[] params = new Object[] { "sentai", 1, "admin", "im_chat.session",<br />                 "session_get",new Integer(5)};<br /><br />         try {<br />         Object[] o = (Object[]) xmlrpc.execute("execute_kw", params);<br /><br />         } catch (Exception e) {<br />             e.printStackTrace();<br />         }<br /> 出错信息:<br />java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer<br /> at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)<br /> at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)<br /> at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)<br /> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)<br /> at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)<br /> at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)<br /> at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)<br /> at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)<br /> at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)<br /> at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)<br /> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)<br /> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)<br /> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)<br /> at odootest.imchat.main(imchat.java:158)<br />被调用的方法:<br />    def session_get(self, cr, uid, user_to, context=None):<br />    其中user_to为int型,在设用其他方法,当参数为字符串类型时均成功能。



  • 用python的xmlrpclib调用没有问题。<br />代码段如下:<br />model="im_chat.session"  ##要运行哪个类中的函数?<br />method="session_get"      ##要运行的函数<br />result = sock.execute(dbname, uid, pwd, <br />                      model,method,5 )<br />print "\n==== %s of %s ====" % (model, method)<br />pprint(result)



  • java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer<br /><br />java的问题。。不会



  • [quote author=lixuchao link=topic=17147.msg30551#msg30551 date=1434618005]<br />用python的xmlrpclib调用没有问题。<br />代码段如下:<br />model="im_chat.session"  ##要运行哪个类中的函数?<br />method="session_get"      ##要运行的函数<br />result = sock.execute(dbname, uid, pwd, <br />                      model,method,5 )<br />print "\n==== %s of %s ====" % (model, method)<br />pprint(result)<br />[/quote]<br /><br />python不是严格类型绑定的语言,java是,所以你老老实实用String吧。



  • 参数要求的是int,改成字符串不行。


  • 管理员

    <br />你的这个错误信息,我猜是RPC调用出错后,JAVA期待的是Integer类型错误返回值而实际的错误返回值是Sting Type引起的。<br />的确是传入参数错误,to_user应该是一个Array List而不是Integer, 理论上你的python代码也会返回错误



  • 现在情况是python能成功调用,java调用失败,另外,我写了一个module做了测试,返回结果是一个整数,出错提示相同。<br />python调用成功时返回结果是:<br /><br />==== im_chat.session of session_get ====<br />{'state': 'closed',<br /> 'users': [{'id': 1, 'im_status': 'online', 'name': 'Administrator'},<br />          {'id': 5, 'im_status': 'offline', 'name': u'\u674e\u6829\u8d85'}],<br /> 'uuid': '438e8348-0009-46b5-a411-229b19fe4967'}<br /><br />有可能是java的xmlrpc不支持此种类型结果吗?<br /><br />另外,把参数改成ArrayLlist后出错如下:<br />java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;<br /> at odootest.imchat.main(imchat.java:161)<br /><br />



  • 换一个  Java XMLRPC 库试试...



  • 估计不是传入参数问题,<br />新写了个module里面的方法为:<br />    def session_get(self, cr, uid, context=None):<br />        return 10<br />没有调用参数,用python调用没问题,用java调用仍报错:java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer<br />



  • rpc 调用, 最好是 HTTP 抓包...



  • 问题已解决。<br />调用时用 HashMap  a = (HashMap) xmlrpc.execute("execute", params);  "execute"改为"execute_kw"就有问题,不知两个有什么区别。<br />就可以。<br />程序段如下:<br /> try{<br /> XmlRpcClient xmlrpc = new XmlRpcClient();<br /><br />         XmlRpcClientConfigImpl xmlrpcConfgDb = new XmlRpcClientConfigImpl();<br />         xmlrpcConfgDb.setEnabledForExceptions(true);<br />         xmlrpcConfgDb.setServerURL(new URL(<br />                 "http://localhost:8069/xmlrpc/object"));<br /><br />         xmlrpc.setConfig(xmlrpcConfgDb);<br /><br />         Object[] params = new Object[] { "sentai",1, "admin", "im_chat.session",<br />                 "session_get",5};<br /><br />         try {<br />         HashMap  a = (HashMap) xmlrpc.execute("execute", params);<br />         System.out.println(a);<br /><br />         } catch (Exception e) {<br />             e.printStackTrace();<br />         }<br />        <br /> }catch(Exception e){<br /> e.printStackTrace();<br /> }


登录后回复
 

与 Odoo 中文社区 的连接断开,我们正在尝试重连,请耐心等待