Menu

XmlRpcArray

Furios
2007-10-24
2013-04-25
  • Furios

    Furios - 2007-10-24

    Hello,

    i new to XML-RPC and using redstone xml-rpc for serverside.
    i send a vector of parameters. This vector is containing a vector of strings. When i call my service i get the following exception:

    redstone.xmlrpc.XmlRpcException: The method cannot be found. Signature: redstone.xmlrpc.XmlRpcArray
        at org.kxmlrpc.XmlRpcClient.execute(+368)
        at parseSynch.Synch.rpcFunc(+20)
        at order.OrderForm.commandAction(+312)
        at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
        at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
        at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
        at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
        at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+194)
        at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+51)
    Execution completed.

    my handler looks like that:

    ublic class SynchService {
       
        public int orderFunc(XmlRpcArray prodArray) {
     
            //....
            return 5;
        }

    and on client side i call the method :

            Vector v=new Vector();
           
            v.addElement("someString");
           v.addElement("someString");

             Vector params= new Vector();
           params.addElement(v);
            Object result = null;
            try {
                // Execute the call and return the result
               
                result = rpc.execute(method, params);
                // v = (Vector)result;
                System.out.println("This is the result"+result);
            } catch (Exception e) {
                e.printStackTrace();
            }

    i hope anybody can help me on this.

    thanks in advance

    Fari

     
    • Greger Ohlson

      Greger Ohlson - 2007-10-24

      Hi,

      Can you please tell me what the variable "method" is set to in your client
      where you call "result = rpc.execute(method, params);". And also, please
      supply the line on the server side where SynchService is registered. From
      what I can tell so far, it doesn't appear to be a problem with matching
      the arguments sent from the client with the parameters of you orderFunc()
      method, but rather some mimatch with the lookup of the method name altogether.

      Thanks,
      Greger.

       
    • Furios

      Furios - 2007-10-25

      Hey Gregor,

      thanks for answering fast. But i solved the problem. My parameter was a type of Array or Vector, and the signature of my serverside method should be : public Vector customerListSynchFunc(redstone.xmlrpc.XmlRpcArray prodArray)
      then the programm works. But thanks a lot anyways.
      Another Question what about serialization and objects of my class? can i send them with kxmlrpc or redstone xmlrpc?

      Thanks

      Fari

       
      • Greger Ohlson

        Greger Ohlson - 2007-10-25

        Hi,

        I'm not exactly sure what you mean here. A short comment about serialization though:

        On the wire, between XML-RPC implementations like kxmlrpc and Redstone XML-RPC, custom data types are not preserved. So whatever you want to send from any XML-RPC implementation the serialization mechanism in that implementation needs to be able to break the arguments down into XML-RPC primitives, XML-RPC arrays or XML-RPC structs, according to the spec. When the receiving end of an invocation deserializes the arguments they are reconstructed to whatever data type that particular implementation has chosen to represent the primitives, arrays, and structs.

        So for Redstone XML-RPC, an array of something is recreated into an XmlRpcArray which is a plain java.util.List with some helper methods in it. So your handler can accept either a java.util.List (if you don't want your handlers to have a dependency on the Redstone library). XML-RPC structs are converted to XmlRpcStruct which is a java.util.Map with some helper methods. Your invocation handler can have a Map parameter or an XmlRpcStruct parameter.

        Now to what I think is your question; since the only option for any XML-RPC library is to send complex values as XML-RPC structs there need to be built-in support for converting complex object into structs. Redstone supports sending any object as an XML-RPC struct in the XmlRpcClient, or return any object from an invocation handler. Nevertheless, when the other en unpacks the complex object it will be recreated into whatever representation of XML-RPC structs that implementation has chosen.

        Example:

        client = new XmlRpcClient("http://some.url", true);
        client.invoke("Some.method", new Object[] { new MyClassWithLotsOfMembers() } );

        Since MyClassWithLotsOfMembers is not a primitive or an array, XmlRpcClient will convert it into an XML-RPC struct on the wire. The invocation handler at some.url for Some.method will deserialize the struct into some kind of hash map. For Redstone XML-RPC this is an XmlRpcStruct, for Apache I guess it is a java.util.Map implementation, for Python, Ruby, and other script implementations, it is some other hash representation. In either case, the fact that it once was a MyClassWithLotsOfMembers is forever lost.

        Hope this clears things up?

        Regards,
        Greger.

         
    • Furios

      Furios - 2007-10-25

      Hello Greger,

      many thanks for this detailed information. Now the whole process is much clearer for me. How efficient is the ksoap serialization do you have an idea ? what is for your more efficient to use kxmlrpc or ksoap, when you have small objects with some 2 or 3 methods and attributs.
      It would be great to have the opinion you u in this case.

      thanks

      fari

       
      • Greger Ohlson

        Greger Ohlson - 2007-10-25

        Hi Fari,

        Well, I think the latency of the socket communication will far outweigh the time it takes to serialize small objects into XML, whether it be XML-RPC or SOAP. So the question in my opinion is what kind of interoperability you are looking for. That is, what kind of clients do you want to expose your web service to?

        Based on your previous messages, it appears that you currently have control over both the client and server side where you tried exposing your service using XML-RPC and the Redstone library (and I assume your client application is running on some hand-held device based on your use of kxmlrpc).

        If you don't plan on exposing your web service to other clients I would personally recommend going with XML-RPC since it is a bit more lightweight. XML-RPC also gives you
        great interoperability with clients written in just about any other language if you choose to open up your web service at some later time. However, SOAP has perhaps become more mainstream and supports more features.

        Tough choice, but again, performance is probably not the driving force when making a decision.

        Cheers,
        Greger.

         
    • Furios

      Furios - 2007-10-26

      HI Gregor,

      i actually working on my thesis and the topic is XML processing on mobile devices. So one part of my thesis is to create an order applikation which is updating the clients data list to the server and sending the list of ordered items via i-net to the server. The server is checking the order list and gives a reply about the products if they are available or not. So i wanted to test to different ways the ksoap/Soap and XML-RPC for sending data and web services.

      another part of my thesis is xml parsers for mobile devices. I am working on that too.

      BTW: i am good now with xml-rpc and kxml-rpc... right now i am trying ksoap and on serverside axis... but i have problems. How is your experience with that? can you help me setup them?

      I already installed tomcat and axis. Axis is working. So the hard part is to write a web service and access it from the mobile device via ksoap.
      Would be great to get some help on that.

      Thanks

      Fari

       
      • Greger Ohlson

        Greger Ohlson - 2007-10-26

        Hi,

        Unfortunately I'm a bit short on time right now. I'm working overtime on a project that is to be delivered on monday so I can't help you troubleshoot the Axis issues you have right now.

        I have used Axis occasionally through my work, but I'm not very fond of it. Personally I like XFire better (xfire.codehaus.org).

        Just out of curiosity, what problems are you experiencing?

        Good luck with your thesis!

        Regards,
        Greger.

         
    • Furios

      Furios - 2007-11-09

      Hello Greger,

      hope you doing fine.
      I have some question regarding XML-RPC. What happens when xml-rpc hand overs the objects? how is the mechanism working?
      How is the mapping of java types working?
      I would appreciate it

      thanks

       
      • Greger Ohlson

        Greger Ohlson - 2007-11-09

        Hi!

        I assume you are referring to sending arbitrary objects like "new MyClass()" and not just primitive arguments or arrays, lists, and hashes?

        In that case, the Redstone library contains an introspecting serializer (redstone.xmlrpc.serializers.IntrospectingSerializer) that uses the reflection and introspection API in Java to examine which properties that are exposed by the object. For example:

        class Address
        {
           public String getStreet() { return street; }
           private String street; // Set in c-tor perhaps
        }

        class Person
        {
            String getName() { return name; }
            Address getAddress() { return address; }
            private String name; // Set in c-tor perhaps
            private Address address; // -"-
        }

        client.invoke( "SomeService.someMethod", new Object[] { new Person("My Name", new Address("My Street")) } );

        Given the above, the serializer in XmlRpcClient client takes a look at the first argument which is a Person object. The Person type is not recognized by any of the built-in serializers in the library so it asks the IntrospectingSerializer to serializer the Person argument. The Introspecting serializer treats all objects as being XML-RPC structs, so the Person object will arrive at the service as such. The introspecting serializer extracts all getter's from the Person (getName() and getObject()) via the introspection API and extracts the values they return.

        Each value returned are in turn serialized again through the built-in serializer. Since getName() returns a String it will be recognized by the built-in serializer and is serialized as a regular XML-RPC string. But since getAddress() returns an Address which is not recognized by the built-in serializer, the IntrospectingSerializer is the recursively invoked to serialize that object too, which results in another struct, within that struct.

        So the final struct on the wire will be

        <struct>
           <member>
              <name>name</name>
              <value><string>My Name</string></value>
           </member>
           <member>
              <name>address</name>
              <value>
                <struct>
                   <member>
                      <name>street</name>
                      <value>My Street<string>
                   </mamber>
                </struct>
              </value>
           </member>
        </struct>

        If the receiving end of the invocation was implemented using Redstone XML-RPC it would arrive as a Map (or XmlRpcStruct if you want extra helper methods):

        public class SomeService
        {
          public String method(XmlRpcStruct person)
          {
            String name = person.getString("name");
            String street = person.getStruct("address").getString("street");

            return "Hi " + name + "! Nice living on " + street + "?";
          }
        }

        If you want to experiment with serialization, you can instantiate the XmlRpcSerializer directly if you want and output the result on System out:

        public static void main(String[] args) throws Exception
        {
            OutputStreamWriter writer = new OutputStreamWriter(System.out);
            XmlRpcSerializer serializer = new XmlRpcSerializer();
            serializer.serialize("Test", writer);
            serializer.serialize(new Integer(42), writer);
            serializer.serialize(new Person("Name", new Address("Street")), writer);
            writer.flush();
        }

        Cheers!
        Greger.

         
    • Furios

      Furios - 2007-11-09

      Hey Greger,

      thanks a lot, thats what i am looking for. So my questions:
      is this mechanism only on Redstome XML -RPC or is it a part of the XML -RPC Specification? and another question. How is the Mapping of JAVA in XML - RPC happening? Do you where it is specified?

      Thanks,

      Fari

       
      • Greger Ohlson

        Greger Ohlson - 2007-11-09

        Hi,

        The specification does not state anything about mapping. It is up to each language to map an XML-RPC document into an invocation, including how to deserialize the values in the invocation into something that makes sense for that particular language and that particular XML-RPC implementation for that language.

        The spec only specifies what is correct XML-RPC on the wire. You can write up an XML-RPC invocation in Notepad if you want and send it over HTTP to a server. XML-RPC libraries make it a little easier, though :-), especially when it comes to intepreting the response from a service.

        In other words, there is no language mapping specification. It's up to each library to decide what kind of support it wants to give developers when it comes to creating XML-RPC documents to be sent over HTTP. If the implementation contains a server part as well, the library also determines how an invocation received over HTTP is dispatched to an invocation handler. For Redstone XML-RPC the server is implemented as a Servlet which includes a few extra features like invocation interceptors which can be used to implement some special features. Other implementation may have other requirements as to how you implement clients, invocation handlers, and what kind of data types that support during the translation to and from XML-RPC documents.

        Cheers,
        Greger.

         
    • Furios

      Furios - 2007-11-09

      Ok i got it. Thanks.
      Another question to the previous mail. Must classes like MyClass have a getter method to serialize it?

       
      • Greger Ohlson

        Greger Ohlson - 2007-11-09

        Yep, that's the way introspection and JavaBeans work. Private fields without getters will not be serialized.

        Cheers,
        Greger

         
    • Furios

      Furios - 2007-11-09

      And this way of Serialization is it an redstone specefic way or is it general to all XML - RPC APIs that they can serialize like that?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.