如下所示。对于String中的所有值,输出为<value>{val}</value>
而不是<value><string>EXT</string></value>
HashMap parameterMap = new HashMap();
client.setTransportFactory(new CustomXmlRpcCommonsTransportFactory(client));
client.setConfig(config);
parameterMap.put("hostName", "EXT");
parameterMap.put("externalData1", "EXEMPLE");
parameterMap.put("originTimeStamp", new Date());
parameterMap.put("subscriberNumberNAI", 2);
parameterMap.put("subscriberNumber", "278980890");
ArrayList params = new ArrayList();
params.add(parameterMap);
client.executeAsync("Methode", params, callback);
还有我的输出
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>GetBalanceAndDate</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>subscriberNumberNAI</name>
<value>
<i4>2</i4>
</value>
</member>
<member>
<name>hostName</name>
<value>EXT</value>
</member>
<member>
<name>subscriberNumber</name>
<value>278980890</value>
</member>
<name>originTimeStamp</name>
<value>
<dateTime.iso8601>20150912T08:50:04</dateTime.iso8601>
</value>
</member>
<member>
<name>externalData1</name>
<value>EXEMPLE</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
答案 0 :(得分:0)
答案 1 :(得分:0)
Apache XML-RPC is sending strings as <value>SomeString</value>.
Whereas I would expect <value><string>SomeString</string></value>.
两种格式均有效。兼容XML-RPC的软件(就像Apache XML-RPC一样)必须能够理解两者。当然,您只能生产一个。不幸的是,那里有很多处理器,它们只能理解一个。
幸运的是,更改Apache XML-RPC生成的格式并不是很困难。首先,创建一个自定义类型工厂:
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);
}
}
然后,您必须安装该自定义类型的工厂。可以按照“自定义数据类型”一节中的说明进行操作:http://ws.apache.org/xmlrpc/advanced.html