XML-RPC
  1. XML-RPC
  2. XMLRPC-89

cannot use Vector, Hashtable, etc as arguments of metheds in handler

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      xmlrpc3.0b1 nightlybuild

      Description

      In handler, I have methods like

      public Vector getData(Vector req)
      {
      }

      public Vector pingHandler()
      {
      }

      On client side, I have code like:
      Vector req = new Vector();
      req.add("user");
      Vector params = new Vector(1);
      params.add(req);
      client.execute("handler.getData", params);

      I always got exception

      Jun 22, 2006 7:34:37 AM org.apache.xmlrpc.server.XmlRpcStreamServer execute
      SEVERE: execute: Error while performing request
      org.apache.xmlrpc.XmlRpcException: Illegal argument for method getData in class test.servlet.XMLRPCHandler
      at org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.execute(ReflectiveXmlRpcHandler.java:71)
      at org.apache.xmlrpc.server.XmlRpcServerWorker.execute(XmlRpcServerWorker.java:43)
      at org.apache.xmlrpc.server.XmlRpcServer.execute(XmlRpcServer.java:67)
      at org.apache.xmlrpc.server.XmlRpcStreamServer.execute(XmlRpcStreamServer.java:196)
      at org.apache.xmlrpc.webserver.XmlRpcServletServer.execute(XmlRpcServletServer.java:91)
      at org.apache.xmlrpc.webserver.XmlRpcServlet.doPost(XmlRpcServlet.java:99)
      at test.servlet.XMLRPCServlet.doPost(XMLRPCServlet.java:217)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
      at java.lang.Thread.run(Thread.java:536)
      Caused by:
      java.lang.IllegalArgumentException: argument type mismatch
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.execute(ReflectiveXmlRpcHandler.java:65)
      at org.apache.xmlrpc.server.XmlRpcServerWorker.execute(XmlRpcServerWorker.java:43)
      at org.apache.xmlrpc.server.XmlRpcServer.execute(XmlRpcServer.java:67)
      at org.apache.xmlrpc.server.XmlRpcStreamServer.execute(XmlRpcStreamServer.java:196)
      at org.apache.xmlrpc.webserver.XmlRpcServletServer.execute(XmlRpcServletServer.java:91)
      at org.apache.xmlrpc.webserver.XmlRpcServlet.doPost(XmlRpcServlet.java:99)
      at test.servlet.XMLRPCServlet.doPost(XMLRPCServlet.java:217)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
      at java.lang.Thread.run(Thread.java:536)

      While invoke pingHandler (new argument)
      I got
      org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse servers response: Unexpected non-whitespace character data
      at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:267)
      at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:216)
      at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
      at MyXmlRpcClient.main(MyXmlRpcClient.java:32)
      Caused by:
      org.xml.sax.SAXParseException: Unexpected non-whitespace character data
      at org.apache.xmlrpc.parser.TypeParserImpl.characters(TypeParserImpl.java:79)
      at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.characters(RecursiveTypeParserImpl.java:139)
      at org.apache.xmlrpc.parser.MapParser.characters(MapParser.java:79)
      at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.characters(RecursiveTypeParserImpl.java:142)
      at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.characters(RecursiveTypeParserImpl.java:142)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.characters(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanContent(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(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 org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:265)
      at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:216)
      at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
      at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
      at MyXmlRpcClient.main(MyXmlRpcClient.java:32)

      1. Req2.xml
        0.4 kB
        Zhi Han

        Issue Links

          Activity

          Hide
          Jochen Wiedmann added a comment -

          Ok, I have committed a partial solution.

          First of all, let me explain what the problem is. The XML-RPC library is working internally with certain classes only. For example, an object array, a list, and a vector are all internally mapped to an object array. Likewise, a Hashtable, and Properties, are mapped to a Map.

          Now, when we call a method, we are checking the method parameters. If, for example, the method has a vector as first parameter, then we convert the object array to a vector. No problem here. The situation is quite different, if we return a value: We do not now, whether the caller wants an object array, or a vector.

          In short, if the client calls a method

          Vector method(Vector);

          then the result will be an object array. (Although everything works fine on the server.) The recommended solution is to use the ClientFactory: An implementation, which is created by the ClientFactory, knows about the return type and can apply the same conversion. See

          http://svn.apache.org/repos/asf/webservices/xmlrpc/trunk/src/site/apt/advanced.apt

          for details on the ClientFactory.

          Show
          Jochen Wiedmann added a comment - Ok, I have committed a partial solution. First of all, let me explain what the problem is. The XML-RPC library is working internally with certain classes only. For example, an object array, a list, and a vector are all internally mapped to an object array. Likewise, a Hashtable, and Properties, are mapped to a Map. Now, when we call a method, we are checking the method parameters. If, for example, the method has a vector as first parameter, then we convert the object array to a vector. No problem here. The situation is quite different, if we return a value: We do not now, whether the caller wants an object array, or a vector. In short, if the client calls a method Vector method(Vector); then the result will be an object array. (Although everything works fine on the server.) The recommended solution is to use the ClientFactory: An implementation, which is created by the ClientFactory, knows about the return type and can apply the same conversion. See http://svn.apache.org/repos/asf/webservices/xmlrpc/trunk/src/site/apt/advanced.apt for details on the ClientFactory.
          Hide
          Jochen Wiedmann added a comment -

          Preliminary inspection: This is a serious bug, because it will be a problem for backwards compatibility. We can handle it for parameters by automatically converting them. A possible solution for the return value might be to make the type of return value for arrays configurable.

          A workaround is to use object arrays, rather than lists, or vectors. In other words, change the client code to

          Object[] value = new Object[]

          {new Integer(0), "abc"}

          ;
          Object[] parms = new Object[]

          {value}

          ;
          Object[] result = (Object[]) client.execute(methodName, parms);

          and the server methods signature to

          public Object[] methodName(Object[] values)

          { ... }

          A fix should be available within the next days. I'll defer 3.0b1 until that.

          Show
          Jochen Wiedmann added a comment - Preliminary inspection: This is a serious bug, because it will be a problem for backwards compatibility. We can handle it for parameters by automatically converting them. A possible solution for the return value might be to make the type of return value for arrays configurable. A workaround is to use object arrays, rather than lists, or vectors. In other words, change the client code to Object[] value = new Object[] {new Integer(0), "abc"} ; Object[] parms = new Object[] {value} ; Object[] result = (Object[]) client.execute(methodName, parms); and the server methods signature to public Object[] methodName(Object[] values) { ... } A fix should be available within the next days. I'll defer 3.0b1 until that.
          Hide
          Zhi Han added a comment -

          This is the request message that always raise a illegal argument error in XmlRpcException, which is captured by tpc capture tool.

          Show
          Zhi Han added a comment - This is the request message that always raise a illegal argument error in XmlRpcException, which is captured by tpc capture tool.
          Hide
          Jochen Wiedmann added a comment -

          Please try the following: Does it work, if you change the use of Vector on the server side to List? (Using a List is recommended anyways, for reasons of performance.)

          Show
          Jochen Wiedmann added a comment - Please try the following: Does it work, if you change the use of Vector on the server side to List? (Using a List is recommended anyways, for reasons of performance.)

            People

            • Assignee:
              Jochen Wiedmann
              Reporter:
              Zhi Han
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development