Kuddi: xmlrpc'ing vectors

"Henrik Plate \(GMX\)" <[email protected]> Thu, 6 Mar 2003 17:43:21 +0100
Newsgroups gmane.comp.java.enhydra.kxmlrpc
Message-ID <[email protected]>
Hi everybody!

Beside (k)XMLRPC is really lightweight, easy to use/learn and efficient I do
have some problems transfering vectors from a XMLRPC server to a MIDlet.

I've got a servlet (source below, modified Apache class
org.apache.xmlrpc.XmlRpcProxyServlet) which acts as a XMLRPC server. The
servlet itself is registered as the default handler and got the method
getProviders, which simply returns a newly constructed Vector. Other methods
like getServerInfo, which returns a String, succeed.

When I call the servlet with a J2SE client (slightly modified Apache
example) the resulting object is a Vector. Fine.

When I call the method from a MIDlet, the Wireless Toolkit prints the
following exception:

org.kxml.io.ParseException: unexpected: StartTag <data> line: -1 attr: null
@-1:-1
	at org.kxml.parser.AbstractXmlParser.read(+53)
	at org.kxmlrpc.XmlRpcParser.parseValue(+15)
	at org.kxmlrpc.XmlRpcParser.parseArray(+23)
	at org.kxmlrpc.XmlRpcParser.parseValue(+241)
	at org.kxmlrpc.XmlRpcParser.parseParams(+46)
	at org.kxmlrpc.XmlRpcParser.parseResponse(+144)
	at org.kxmlrpc.XmlRpcClient.execute(+200)
	at midlet.ServerConnection.callMethod(+15)
	at midlet.XmlRpcTestControl$1.run(+18)

The via HTTP transfered xml response of the servlet is

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <methodResponse>
        <params>
            <param>
                <value>
                    <array>
                        <data>
                            <value>String 1</value>
                            <value>String 2</value>
                        </data>
                    </array>
                </value>
            </param>
        </params>
    </methodResponse>

Seems to be OK.

Does kXMLRPC miss the implementation of Vector transfers? I can't imagine,
cause the parser fails at the data-, not the array-tag. Is it versioning
problem?

Here's my enviroment:

	kXMLRPC 0.6
	XMLRPC 1.1 from Apache
	J2SE 1.4.1
	Tomcat 4.0.1

Relevant part of the servlet source:

    import org.apache.xmlrpc.*;

    public class XmlRpcServlet extends HttpServlet  {

        // The xml-rpc server.
        final XmlRpcServer server = new XmlRpcServer();

        public void init(ServletConfig config)throws ServletException{

            // Config the xml-rpc server.
            XmlRpc.setDebug(true);
            server.addHandler("$default", this);
        }

        public String getServerInfo() { return "XmlRpcServlet"; }
//"$Name$"; }

        public Vector getProviders() {
            final Vector v = new Vector();
            v.add("String 1");
            v.add("String 2");
            return v;
        }

        public void service(HttpServletRequest req, HttpServletResponse
res)throws ServletException, IOException{
            byte[] result = server.execute(req.getInputStream ());
            res.setContentType("text/xml");
            res.setContentLength(result.length);
            OutputStream output = res.getOutputStream();
            output.write(result);
            output.flush();
        }
    }

Another question: If a XMLRPC call fails, the XmlRpcClient class returns the
result of the previous call. Is that desireable? Not sure of this.

Greetings und thanks in advance,
Henrik