|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
No string element for String typesHello.
I'm a bit hesitant about this change since it seems to have been around since day-one, but maybe someone on this list knows the reasoning behind it. /****** BEGIN_REPRO_CODE *******/ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setServerURL("http://betty.userland.com/rpc"); client = new XmlRpcClient(); client.setTransportFactory(new XmlRpcCommonsTransportFactory(client)); client.setConfig(config); Vector<Object> outerParams = new Vector<Object>(); Map<String, Object> innerParams = new HashMap<String, Object>(); innerParams.put("id", 100); innerParams.put("name", "abcdef"); outerParams.add(innerParams); client.execute("do.something", outerParams); /****** END_REPRO_CODE *******/ // outgoing request looks like this <?xml version="1.0"encoding="UTF-8"?> <methodCall> <methodName>do.something</methodName> <params> <param> <value> <struct> <member> <name>id</name> <value> <i4>100</i4> </value> </member> <member> <name>name</name> <value>abcdefg</value> </member> </struct> </value> </param> </params> </methodCall> Whereas I would expect the value to have an additional <string/> elemement like this: <member> <name>name</name> <value> <string>abcdefg</string> </value> </member> I've attached a diff that makes it behave like I would expect but I'm wondering if there was a reason for this to *not* be there already? Thanks, Joshua Hansen Software Engineer | Slant Six Games Direct: +1 604-637-9862 |
|
|
Re: No string element for String typesI have added the following FAQ entry now.
Apache XML-RPC is sending strings as <value>SomeString</value>. Whereas I would expect <value><string>SomeString</string></value>. Both formats are valid. XML-RPC compliant software (as Apache XML-RPC is) must be able to understand both. Of course, you can only produce one. Unfortunately there are a lot of processors out there, which understand just one. Which is the reason, why this FAQ entry exists. Fortunately, it is not overly difficult to change the format, that Apache XML-RPC produces. First of all, create a custom type factory: package mypackage; import org.apache.xmlrpc.common.TypeFactoryImpl; import org.apache.xmlrpc.common.XmlRpcController; import org.apache.xmlrpc.common.XmlRpcStreamConfig; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; public class MyTypeFactory extends TypeFactoryImpl { private static final TypeSerializer myStringSerializer = new StringSerializer(){ public void write(ContentHandler pHandler, Object pObject) throws SAXException { write(pHandler, STRING_TAG, pObject.toString()); } }; public MyTypeFactory(XmlRpcController pController) { super(pController); } public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException { if (pObject instanceof String) { return myStringSerializer; } return super.getSerializer(pConfig, pObject); } } Then you'e got to install that custom type factory. This works as described in the section on "Custom Data Types". |
| Free embeddable forum powered by Nabble | Forum Help |