Search code examples
scalasbtxml-rpc

XmlRpc client using Scala


I need to consume an xmlrpc service from Scala, and so far it looks like my only option is the Apache XML-RPC library.

I added this dependency to my Build.scala:

"org.apache.xmlrpc" % "xmlrpc" % "3.1.3"

and sbt reported no problem in downloading the library. However, I don't know how to go about actually accessing the library.

val xml = org.apache.xmlrpc.XmlRpcClient("http://foo") wouldn't compile

and

import org.apache.xmlrpc._

reported that object xmlrpc was not a member of package org.apache.

What would be the correct package to import?

(Or, is there a better library for XmlRpc from Scala?)


Solution

  • Try

    "org.apache.xmlrpc" % "xmlrpc-client" % "3.1.3"
    

    and so :

      class XmlRpc(val serverURL: String) {
    
        import org.apache.xmlrpc.client.XmlRpcClient
        import org.apache.xmlrpc.client.XmlRpcClientConfigImpl
        import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory
        import java.net.URL
        val config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(serverURL));
        config.setEncoding("ISO-8859-1");
        val client = new XmlRpcClient();
        client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
        client.setConfig(config);
    
        client.execute(...)
      }