Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

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

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

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

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

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

    Odoo 开发与实施交流
    5
    12
    5554
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      lixuchao last edited by

      本人打算在android手机上实现im_chat功能,
      调其中一个方法时遇到问题,当方法中有参数是int类型时失败。如果参数为字符串类型,则没问题。
      不知各位仁兄有没遇到过类似问题,请指教。

      调用片段:
      XmlRpcClient xmlrpc = new XmlRpcClient();

              XmlRpcClientConfigImpl xmlrpcConfgDb = new XmlRpcClientConfigImpl();
              xmlrpcConfgDb.setEnabledForExceptions(true);
              xmlrpcConfgDb.setServerURL(new URL(
                      "http://localhost:8069/xmlrpc/object"));

              xmlrpc.setConfig(xmlrpcConfgDb);

               
              Object[] params = new Object[] { "sentai", 1, "admin", "im_chat.session",
                      "session_get",new Integer(5)};

              try {
              Object[] o = (Object[]) xmlrpc.execute("execute_kw", params);

              } catch (Exception e) {
                  e.printStackTrace();
              }
      出错信息:
      java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
      at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)
      at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)
      at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
      at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)
      at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
      at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
      at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
      at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
      at odootest.imchat.main(imchat.java:158)
      被调用的方法:
          def session_get(self, cr, uid, user_to, context=None):
          其中user_to为int型,在设用其他方法,当参数为字符串类型时均成功能。

      1 Reply Last reply Reply Quote 0
      • L
        lixuchao last edited by

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

        1 Reply Last reply Reply Quote 0
        • Y
          yanggg1133 last edited by

          java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

          java的问题。。不会

          1 Reply Last reply Reply Quote 0
          • A
            alex1069010 last edited by

            [quote author=lixuchao link=topic=17147.msg30551#msg30551 date=1434618005]
            用python的xmlrpclib调用没有问题。
            代码段如下:
            model="im_chat.session"  ##要运行哪个类中的函数?
            method="session_get"      ##要运行的函数
            result = sock.execute(dbname, uid, pwd,
                                  model,method,5 )
            print "\n==== %s of %s ====" % (model, method)
            pprint(result)
            [/quote]

            python不是严格类型绑定的语言,java是,所以你老老实实用String吧。

            1 Reply Last reply Reply Quote 0
            • L
              lixuchao last edited by

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

              1 Reply Last reply Reply Quote 0
              • digitalsatori
                digitalsatori 管理员 last edited by


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

                【上海先安科技】(tony AT openerp.cn)

                1 Reply Last reply Reply Quote 0
                • L
                  lixuchao last edited by

                  现在情况是python能成功调用,java调用失败,另外,我写了一个module做了测试,返回结果是一个整数,出错提示相同。
                  python调用成功时返回结果是:

                  ==== im_chat.session of session_get ====
                  {'state': 'closed',
                  'users': [{'id': 1, 'im_status': 'online', 'name': 'Administrator'},
                            {'id': 5, 'im_status': 'offline', 'name': u'\u674e\u6829\u8d85'}],
                  'uuid': '438e8348-0009-46b5-a411-229b19fe4967'}

                  有可能是java的xmlrpc不支持此种类型结果吗?

                  另外,把参数改成ArrayLlist后出错如下:
                  java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
                  at odootest.imchat.main(imchat.java:161)

                  1 Reply Last reply Reply Quote 0
                  • mrshelly
                    mrshelly last edited by

                    换一个  Java XMLRPC 库试试...

                    1 Reply Last reply Reply Quote 0
                    • L
                      lixuchao last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • mrshelly
                        mrshelly last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • L
                          lixuchao last edited by

                          问题已解决。
                          调用时用 HashMap  a = (HashMap) xmlrpc.execute("execute", params);  "execute"改为"execute_kw"就有问题,不知两个有什么区别。
                          就可以。
                          程序段如下:
                          try{
                          XmlRpcClient xmlrpc = new XmlRpcClient();

                                  XmlRpcClientConfigImpl xmlrpcConfgDb = new XmlRpcClientConfigImpl();
                                  xmlrpcConfgDb.setEnabledForExceptions(true);
                                  xmlrpcConfgDb.setServerURL(new URL(
                                          "http://localhost:8069/xmlrpc/object"));

                                  xmlrpc.setConfig(xmlrpcConfgDb);

                                  Object[] params = new Object[] { "sentai",1, "admin", "im_chat.session",
                                          "session_get",5};

                                  try {
                                  HashMap  a = (HashMap) xmlrpc.execute("execute", params);
                                  System.out.println(a);

                                  } catch (Exception e) {
                                      e.printStackTrace();
                                  }
                                 
                          }catch(Exception e){
                          e.printStackTrace();
                          }

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post