Ertiam Nifur
Ertiam Nifur

Reputation: 1

java xmlrpc malformed output

As you can see below. for all value in String, the output is <value>{val}</value> instead of <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);

And there is my output

<?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>

Upvotes: 0

Views: 316

Answers (2)

xmoooz
xmoooz

Reputation: 481

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.

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": http://ws.apache.org/xmlrpc/advanced.html

Upvotes: 0

Andreas
Andreas

Reputation: 159175

According to XML-RPC Data types, a string can be either

<string>Hello world!</string>

or just

Hello world!

The <string> tag is optional.

Upvotes: 0

Related Questions