Issue 41 in android-xmlrpc: Wrong XMLRPCCommon Object array serialization

10 views
Skip to first unread message

android...@googlecode.com

unread,
Aug 20, 2012, 5:19:10 AM8/20/12
to android-x...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 41 by f.metz...@gmail.com: Wrong XMLRPCCommon Object array
serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

If the serializeParams() method in XMLRPCCommon.java is given more than one
parameter to serialize, the output is not strict to XMLRPC (though some
client implementations e.g. Python xmlrpclib will still read it).
Each parameter is put into a separate <param> tag. However, only one
<param> is allowed to occur in <params>

The output looks like:
<params>
<param><value><i4>12</i4></value></param>
<param><value><string>Egypt</string></value></param>
<param><value><boolean>0</boolean></value></param>
<param><value><i4>-31</i4></value></param>
</params>


The correct output would rather be:
<params>
<param>
<array>
<data>
<value><i4>12</i4></value>
<value><string>Egypt</string></value>
<value><boolean>0</boolean></value>
<value><i4>-31</i4></value>
</data>
</array>
</param>
</params>


The XMLRPCSerializer class can already generate this type of output. The
only change required is for XMLRPCCommon.serializeParams(Object [] params)
to not loop over each of the array entries and call the Serializer
independently but to just give the array directly to the Serializer.

android...@googlecode.com

unread,
Aug 22, 2012, 4:19:46 AM8/22/12
to android-x...@googlegroups.com

Comment #1 on issue 41 by psk...@gmail.com: Wrong XMLRPCCommon Object array
serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

i don't understand to be honest: what do you want to do? are you working on
client or server side?

android...@googlecode.com

unread,
Aug 22, 2012, 7:24:55 AM8/22/12
to android-x...@googlegroups.com

Comment #2 on issue 41 by f.metz...@gmail.com: Wrong XMLRPCCommon Object
array serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

I am using the XMLRPCServer and i am responding to a XMLRPC call with an
Object[] (that contains more than one Object).
But the existing code serializes each of the Objects in the array into its
own <param></param> tag pair. This is not allowed by the specification.
In this case, the response must be a single param tag which encloses
<array><data></data></array> which in turn contains the individual return
<value>s.

android...@googlecode.com

unread,
Aug 22, 2012, 8:31:16 AM8/22/12
to android-x...@googlegroups.com

Comment #3 on issue 41 by psk...@gmail.com: Wrong XMLRPCCommon Object array
serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

you are right: server part was done by some other guy and i don't why he
created XMLRPCServer response method as:

public void respond(Socket socket, Object[] params) throws IOException

while it really should be:

public void respond(Socket socket, Object value) throws IOException

can you confirm it works as expected?

fixed in rev r30

android...@googlecode.com

unread,
Aug 23, 2012, 3:58:43 AM8/23/12
to android-x...@googlegroups.com

Comment #4 on issue 41 by f.metz...@gmail.com: Wrong XMLRPCCommon Object
array serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

There is still something missing in XMLRPCCommon. The varargs parameter of
serializeParams(Object... params) is again just autoboxed into an Object[],
which the method would loop over and put every Object in the array in a
separate <param></param>.
Instead, you could remove the for-loop and give the array directly to the
serializer.
Maybe something like this:


protected void serializeParams(Object... params) throws
IllegalArgumentException, IllegalStateException, IOException {
if (params != null && params.length != 0)
{
serializer.startTag(null, Tag.PARAMS);
serializer.startTag(null, Tag.PARAM).startTag(null,
IXMLRPCSerializer.TAG_VALUE);
if (params.length > 1)
iXMLRPCSerializer.serialize(serializer, params);
else
iXMLRPCSerializer.serialize(serializer, params[0]);
serializer.endTag(null, IXMLRPCSerializer.TAG_VALUE).endTag(null,
Tag.PARAM);
serializer.endTag(null, Tag.PARAMS);
}
}

android...@googlecode.com

unread,
Aug 23, 2012, 4:10:48 AM8/23/12
to android-x...@googlegroups.com

Comment #5 on issue 41 by psk...@gmail.com: Wrong XMLRPCCommon Object array
serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

could you please post your server code? at least that part that uses
respond() method?

android...@googlecode.com

unread,
Aug 24, 2012, 3:00:49 AM8/24/12
to android-x...@googlegroups.com

Comment #6 on issue 41 by f.metz...@gmail.com: Wrong XMLRPCCommon Object
array serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

You can take a look at my github repo. The xmlrpcserver.respond is called
in [1] but uses reflection to construct the respond parameters. So i am
relying on the server code to do the right thing.


[1]
https://github.com/fmetzger/android-seattle-sensors/blob/master/SeattleSensors/src/at/univie/seattlesensors/XMLRPCSensorServerThread.java

android...@googlecode.com

unread,
Aug 24, 2012, 5:44:05 AM8/24/12
to android-x...@googlegroups.com

Comment #7 on issue 41 by psk...@gmail.com: Wrong XMLRPCCommon Object array
serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

note i had to change "respond" method signature from:
public void respond(Socket socket, Object[] params) throws IOException

to:
public void respond(Socket socket, Object value) throws IOException

i know its very bad idea to change an existing API but original author of
this code made a mistake about returning multiple <param> tags inside
<params> tag

that's why i think he used Object[] to represend multiple <param> tags, but
as you pointed out only one <param> is allowed within <params> tag and
that's why i changed Object[] to Object

see
http://code.google.com/p/android-xmlrpc/source/browse/trunk/XMLRPC/src/org/xmlrpc/XMLRPCServerTest.java?spec=svn30&r=30

i added method "test" that returns an array of different values and it
worked ok when i tested it

android...@googlecode.com

unread,
Aug 24, 2012, 8:36:35 AM8/24/12
to android-x...@googlegroups.com

Comment #8 on issue 41 by f.metz...@gmail.com: Wrong XMLRPCCommon Object
array serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

After removing all the Object[] encapsulations from my code, everything
seems to work as expected now.
Thanks again for your support.

android...@googlecode.com

unread,
Aug 25, 2012, 9:42:11 AM8/25/12
to android-x...@googlegroups.com
Updates:
Status: fixed

Comment #9 on issue 41 by psk...@gmail.com: Wrong XMLRPCCommon Object array
serialization
http://code.google.com/p/android-xmlrpc/issues/detail?id=41

glad to hear everything works ok, btw you probably forgot to change the
response of the method "isSeattleSensor"

Reply all
Reply to author
Forward
0 new messages